概要
在平時(shí)開(kāi)發(fā)和處理bug的過(guò)程中經(jīng)常會(huì)和EventLog打交到,通過(guò)EventLog來(lái)分析Activity故硅、Process蘑险、CPU、Window等相關(guān)信息决乎。
在開(kāi)發(fā)調(diào)試中可以通過(guò)如下命令查看EventLog信息:
adb logcat -b events
在分析bug的時(shí)候可以從log中打開(kāi)如下文件查看EventLog信息:
event.log
這兩種方式獲取到的信息基本上如:
01-06 18:54:07.783 886 1469 I am_uid_active: 1037
01-06 18:54:07.787 886 1469 I am_proc_bound: [0,1659,WebViewLoader-arm64-v8a]
01-06 18:54:07.790 886 1130 I am_proc_start: [0,1692,1001,com.qualcomm.qcrilmsgtunnel,service,com.qualcomm.qcrilmsgtunnel/.QcrilMsgTunnelService]
01-06 18:54:07.791 886 1128 I am_wtf : [0,886,system_server,-1,ActivityManager,Sending non-protected broadcast diagandroid.app.ApplicationState from system 886:system/1000 pkg android]
01-06 18:54:07.934 886 886 I wm_task_created: [1,0]
01-06 18:54:07.937 886 886 I wm_task_moved: [1,0,2147483647]
01-06 18:54:07.938 886 886 I am_create_task: [0,1]
01-06 18:54:07.938 886 886 I am_create_activity: [0,201820164,1,com.android.settings/.FallbackHome,android.intent.action.MAIN,NULL,NULL,276824320]
01-06 18:54:07.938 886 886 I wm_task_moved: [1,0,2147483647]
01-06 18:54:07.957 886 1366 I commit_sys_config_file: [settings-0-0,10]
從EventLog中我們可以獲取到不少有用的信息队询,例如上面 I am_create_task,創(chuàng)建task等,后面的括號(hào)中的內(nèi)容也有很高的價(jià)值构诚,下面我們會(huì)詳細(xì)講解對(duì)應(yīng)的字段
EventLog
EventLog中大概分為如下幾類(lèi)蚌斩,EventLog在編譯之后存放在system/etc/event-log-tags文件中,但是其語(yǔ)法定義在system/core/logcat/event.logtags文件中。
我們需要了解的主要為T(mén)agName后面的括號(hào)中的內(nèi)容,每一種Tag由于功能和模塊的不同范嘱,括號(hào)中的內(nèi)容不同送膳,但是都遵循以下規(guī)則:
(Name|type|unit)
Name:表示這個(gè)字段的意義
Type:表示這個(gè)字段的數(shù)據(jù)格式,取值為:
1: int
2: long
3: string
4: list
5: float
- 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)
例如:
30001 am_finish_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3),(Reason|3)
在上面的代碼中(User|1|5)表示這個(gè)字段的意義為User叠聋,數(shù)據(jù)類(lèi)型為1,1的數(shù)據(jù)類(lèi)型對(duì)應(yīng)type的定義為int,5表示數(shù)據(jù)unit,5的數(shù)據(jù)類(lèi)型對(duì)應(yīng)unit中的定義為Id
這些定義主要在系統(tǒng)解析相關(guān)字段的時(shí)候用于代碼生成的映射關(guān)系受裹。
ActivityManager相關(guān)
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)
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)
從相應(yīng)的Event的定義的TagName以及后面的參數(shù)的說(shuō)明碌补,我們可以拿到在我們分析問(wèn)題的過(guò)程中需要的信息
WindowManager相關(guān)
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)
Power相關(guān)
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)
Notification相關(guān)
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)
實(shí)戰(zhàn)
定義:
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]
含義:
啟動(dòng)一個(gè)進(jìn)程,UserId=0,PID=6533,UID=10131,ProcessName=com.jingdong.app.mall:WatchDogService,Type=service,Component=com.jingdong.app.mall/com.jingdong.common.watchdog.WatchDogService