event log 分析

一、EventLog介绍

1. 在平时开发和处理bug的过程中经常会和EventLog打交到,通过EventLog来分析Activity、Process、CPU、Window等相关信息。

查看Event所有的tags
adb shell cat /system/etc/event-log-tags

输出events日志信息
adb logcat -b events

该命令会输出带有时间点、进程号等信息的events log
adb logcat -v threadtime -t 4096 -b events

 

2. EventLog Tag在编译之后存放在system/etc/event-log-tags文件中,但是其语法定义在system/core/logcat/event.logtags文件中。我们需要了解的主要为TagName后面的括号中的内容,每一种Tag由于功能和模块的不同,括号中的内容不同,但是都遵循以下规则:

(Name|type|unit)

(1) Name:表示这个字段的意义

(2) Type:表示这个字段的数据格式,取值为:
    1: int
    2: long
    3: string
    4: list
    5: float

(3) unit: 取值为
    1: Number of objects
    2: Number of bytes
    3: Number of milliseconds
    4: Number of allocations
    5: Id
    6: Percent
    s: Number of seconds (monotonic time)

 

3.EventLog中大概分为如下几类

(1) ActivityManager相关:

30001 am_finish_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3),(Reason|3)

30002 am_task_to_front (User|1|5),(Task|1|5)

30003 am_new_intent (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3),(Action|3),(MIME Type|3),(URI|3),(Flags|1|5)

30004 am_create_task (User|1|5),(Task ID|1|5)

30005 am_create_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3),(Action|3),(MIME Type|3),(URI|3),(Flags|1|5)

30006 am_restart_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3)

30007 am_resume_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3)

30008 am_anr (User|1|5),(pid|1|5),(Package Name|3),(Flags|1|5),(reason|3) //ANR

30009 am_activity_launch_time (User|1|5),(Token|1|5),(Component Name|3),(time|2|3)

30010 am_proc_bound (User|1|5),(PID|1|5),(Process Name|3)

30011 am_proc_died (User|1|5),(PID|1|5),(Process Name|3),(OomAdj|1|5),(ProcState|1|5)

30012 am_failed_to_pause (User|1|5),(Token|1|5),(Wanting to pause|3),(Currently pausing|3)

30013 am_pause_activity (User|1|5),(Token|1|5),(Component Name|3),(User Leaving|3)

30014 am_proc_start (User|1|5),(PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3)

30015 am_proc_bad (User|1|5),(UID|1|5),(Process Name|3)

30016 am_proc_good (User|1|5),(UID|1|5),(Process Name|3)

30017 am_low_memory (Num Processes|1|1)

30018 am_destroy_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3),(Reason|3)

30019 am_relaunch_resume_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3)

30020 am_relaunch_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3)

30021 am_on_paused_called (User|1|5),(Component Name|3),(Reason|3)

30022 am_on_resume_called (User|1|5),(Component Name|3),(Reason|3)

30023 am_kill (User|1|5),(PID|1|5),(Process Name|3),(OomAdj|1|5),(Reason|3) //杀进程

30024 am_broadcast_discard_filter (User|1|5),(Broadcast|1|5),(Action|3),(Receiver Number|1|1),(BroadcastFilter|1|5)

30025 am_broadcast_discard_app (User|1|5),(Broadcast|1|5),(Action|3),(Receiver Number|1|1),(App|3)

30030 am_create_service (User|1|5),(Service Record|1|5),(Name|3),(UID|1|5),(PID|1|5)

30031 am_destroy_service (User|1|5),(Service Record|1|5),(PID|1|5)

30032 am_process_crashed_too_much (User|1|5),(Name|3),(PID|1|5)

30033 am_drop_process (PID|1|5)

30034 am_service_crashed_too_much (User|1|5),(Crash Count|1|1),(Component Name|3),(PID|1|5)

30035 am_schedule_service_restart (User|1|5),(Component Name|3),(Time|2|3)

30036 am_provider_lost_process (User|1|5),(Package Name|3),(UID|1|5),(Name|3)

30037 am_process_start_timeout (User|1|5),(PID|1|5),(UID|1|5),(Process Name|3)

30039 am_crash (User|1|5),(PID|1|5),(Process Name|3),(Flags|1|5),(Exception|3),(Message|3),(File|3),(Line|1|5)

30040 am_wtf (User|1|5),(PID|1|5),(Process Name|3),(Flags|1|5),(Tag|3),(Message|3)

30041 am_switch_user (id|1|5)

30042 am_activity_fully_drawn_time (User|1|5),(Token|1|5),(Component Name|3),(time|2|3)

30043 am_set_resumed_activity (User|1|5),(Component Name|3),(Reason|3)

30044 am_focused_stack (User|1|5),(Focused Stack Id|1|5),(Last Focused Stack Id|1|5),(Reason|3)

30045 am_pre_boot (User|1|5),(Package|3)

30046 am_meminfo (Cached|2|2),(Free|2|2),(Zram|2|2),(Kernel|2|2),(Native|2|2)

30047 am_pss (Pid|1|5),(UID|1|5),(Process Name|3),(Pss|2|2),(Uss|2|2),(SwapPss|2|2),(Rss|2|2),(StatType|1|5),(ProcState|1|5),(TimeToCollect|2|2) //进程

30048 am_stop_activity (User|1|5),(Token|1|5),(Component Name|3)

30049 am_on_stop_called (User|1|5),(Component Name|3),(Reason|3)

30050 am_mem_factor (Current|1|5),(Previous|1|5)

30051 am_user_state_changed (id|1|5),(state|1|5)

30052 am_uid_running (UID|1|5)

30053 am_uid_stopped (UID|1|5)

30054 am_uid_active (UID|1|5)

30055 am_uid_idle (UID|1|5)

30056 am_stop_idle_service (UID|1|5),(Component Name|3)

30057 am_on_create_called (User|1|5),(Component Name|3),(Reason|3)

30058 am_on_restart_called (User|1|5),(Component Name|3),(Reason|3)

30059 am_on_start_called (User|1|5),(Component Name|3),(Reason|3)

30060 am_on_destroy_called (User|1|5),(Component Name|3),(Reason|3)

30061 am_remove_task (Task ID|1|5), (Stack ID|1|5)

30062 am_on_activity_result_called (User|1|5),(Component Name|3),(Reason|3)

从相应的Event的定义的TagName以及后面的参数的说明,我们可以拿到在我们分析问题的过程中需要的信息。

 

(2) WindowManager相关:

31000 wm_no_surface_memory (Window|3),(PID|1|5),(Operation|3)

31001 wm_task_created (TaskId|1|5),(StackId|1|5)

31002 wm_task_moved (TaskId|1|5),(ToTop|1),(Index|1)

31003 wm_task_removed (TaskId|1|5),(Reason|3)

31004 wm_stack_created (StackId|1|5)

31005 wm_home_stack_moved (ToTop|1)

31006 wm_stack_removed (StackId|1|5)

31007 wm_boot_animation_done (time|2|3)

 

(3) Power相关:

2722 battery_level (level|1|6),(voltage|1|1),(temperature|1|1)

2723 battery_status (status|1|5),(health|1|5),(present|1|5),(plugged|1|5),(technology|3)  可以从这里看出什么时刻插入了充电器

2724 power_sleep_requested (wakeLocksCleared|1|1)

2725 power_screen_broadcast_send (wakelockCount|1|1)

2726 power_screen_broadcast_done (on|1|5),(broadcastDuration|2|3),(wakelockCount|1|1)

2727 power_screen_broadcast_stop (which|1|5),(wakelockCount|1|1)

2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1),(latency|1|3)

2729 power_partial_wake_state (releasedorAcquired|1|5),(tag|3)

2730 battery_discharge (duration|2|3),(minLevel|1|6),(maxLevel|1|6)

2731 power_soft_sleep_requested (savedwaketimems|2)

 

(3) Notification相关:

27500 notification_panel_revealed (items|1)

27501 notification_panel_hidden

27510 notification_visibility_changed (newlyVisibleKeys|3),(noLongerVisibleKeys|3)

27511 notification_expansion (key|3),(user_action|1),(expanded|1),(lifespan|1),(freshness|1),(exposure|1)

27520 notification_clicked (key|3),(lifespan|1),(freshness|1),(exposure|1),(rank|1),(count|1)

27521 notification_action_clicked (key|3),(action_index|1),(lifespan|1),(freshness|1),(exposure|1),(rank|1),(count|1)

27530 notification_canceled (key|3),(reason|1),(lifespan|1),(freshness|1),(exposure|1),(rank|1),(count|1),(listener|3)

27531 notification_visibility (key|3),(visibile|1),(lifespan|1),(freshness|1),(exposure|1),(rank|1)

27532 notification_alert (key|3),(buzz|1),(beep|1),(blink|1)

27533 notification_autogrouped (key|3)

 

二、补充

1. event log 在framework层常常使用,通过类似EventLog.writeEvent()写log,这种log被保存在/system/etc/event-log-tags,如果要看这种log,通过类似# logcat -b events -v threadtime 这种方式打印出来,输出的格式类似于下面:

02-18 12:29:22.625   451   467 I am_create_task: [0,116]
02-18 12:29:22.625   451   467 I am_create_activity: [0,114895309,116,com.xd.ro.roapk/com.xindong.RODevelop.UnitySavePicActivity,android.intent.action.MAIN,NULL,NULL,270532608]
02-18 12:29:22.626   451   467 I wm_task_created: [116,1]

它的格式就是: timestamp PID TID log-level log-tag tag-values

每个log-tag都能在framework下的源代码中找到,如上面的am_create_task,它的tag是在frameworks/base/services/core/java/com/android/server/am/EventLogTags.logtags定义的。某种程度上说,要检查event log,必须去找这些EventLogTags.logtags,才能清楚知道是啥意思。

EventLogTags.logtags 在frameworks下的多个目录下都有,不只是1个文件,编译到手机中就汇成一个文件了。

 

三、EventLog实战

1. am_proc_start的

定义:
30014 am_proc_start (User|1|5),(PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3)

EventLog:
I am_proc_start: [0,6533,10131,com.jingdong.app.mall:WatchDogService,service,com.jingdong.app.mall/com.jingdong.common.watchdog.WatchDogService]

含义:
启动一个进程,UserId=0,PID=6533,UID=10131,ProcessName=com.jingdong.app.mall:WatchDogService,Type=service,Component=com.jingdong.app.mall/com.jingdong.common.watchdog.WatchDogService

 

 

参考:Android开发中EventLog分析: https://www.jianshu.com/p/dc9e75bcf539

 

posted on 2020-03-23 00:23  Hello-World3  阅读(4786)  评论(0编辑  收藏  举报

导航