[Android] EventLogTags.logtags简单使用

转载来源:https://blog.csdn.net/yfbdxz/article/details/114702144

  1. 用EventLog.writeEvent打的日志(或EventLogTags.java方法打的日志),可以用logcat -b events查看
    frameworks/base/core/java/android/util/EventLog.java
        //tag:The event type tag code. value:value to log 
        public static native int writeEvent(int tag, var value);
        public static native void readEvents(int[] tags, Collection<Event> output);
        //从system/etc/event-log-tags读后同时放到了sTagCodes,sTagNames两个map中
        private static final String TAGS_FILE = "/system/etc/event-log-tags"; 
        private static HashMap<String, Integer> sTagCodes = null; 
        private static HashMap<Integer, String> sTagNames = null;

  1. EventLogTags.logtags 很多模块有该文件, writeEvent()参数tag value也是在其中被声明的
    packages/providers/BlacklistProvider/src/com/android/providers/black/EventLogTags.logtags
    packages/providers/CalendarProvider/src/com/android/providers/calendar/EventLogTags.logtags
    packages/providers/ContactsProvider/src/com/android/providers/contacts/EventLogTags.logtags
    packages/services/Telephony/src/com/android/phone/EventLogTags.logtags
    packages/apps/Settings/src/com/android/settings/EventLogTags.logtags
    packages/apps/QuickSearchBox/src/com/android/quicksearchbox/EventLogTags.logtags
    frameworks/base/services/core/java/com/android/server/EventLogTags.logtags
    frameworks/base/services/core/java/com/android/server/am/EventLogTags.logtags
    frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags
  1. EventLogTags.logtags在Android.mk中配置
    logcat中LOCAL_SRC_FILES:= logcat.cpp event.logtags
    systemui中LOCAL_SRC_FILES := src/com/android/systemui/EventLogTags.logtags
  1. EventLogTags.logtags文件格式说明
   每一行大致三部分组成: Tag numbers + Tag names + (<名字>|数据类型[|数据单位]),(<名字>|数据类型[|数据单位])
   logcat打印内容就是第二部分+第三部分
   详见:android/system/core/logcat/event.logtags

  1. EventLogTags.logtags编译时被翻译成了java
    frameworks/base/core/java/com/android/internal/logging/EventLogTags.logtags
    
        option java_package com.android.internal.logging;
        524287 sysui_view_visibility (category|1|5),(visible|1|6)
        524288 sysui_action (category|1|5),(pkg|3)
        524290 sysui_count (name|3),(increment|1)
        524291 sysui_histogram (name|3),(bucket|1)
    
    out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/.../logging/EventLogTags.java
    
        public class EventLogTags {
          private EventLogTags() { }  // don't instantiate
        
          /** 524287 sysui_view_visibility (category|1|5),(visible|1|6) */
          public static final int SYSUI_VIEW_VISIBILITY = 524287;
        
          /** 524288 sysui_action (category|1|5),(pkg|3) */
          public static final int SYSUI_ACTION = 524288;
        
          /** 524290 sysui_count (name|3),(increment|1) */
          public static final int SYSUI_COUNT = 524290;
        
          /** 524291 sysui_histogram (name|3),(bucket|1) */
          public static final int SYSUI_HISTOGRAM = 524291;
        
          public static void writeSysuiViewVisibility(int category, int visible) {
            android.util.EventLog.writeEvent(SYSUI_VIEW_VISIBILITY, category, visible);
          }
        
          public static void writeSysuiAction(int category, String pkg) {
            android.util.EventLog.writeEvent(SYSUI_ACTION, category, pkg);
          }
        
          public static void writeSysuiCount(String name, int increment) {
            android.util.EventLog.writeEvent(SYSUI_COUNT, name, increment);
          }
        
          public static void writeSysuiHistogram(String name, int bucket) {
            android.util.EventLog.writeEvent(SYSUI_HISTOGRAM, name, bucket);
          }
        }
  1. EventLogTags.logtags相关脚本
    android/build/tools 目录下有三个event_log相关的脚本  
        event_log_tags.py //读取跟解析event_log_tags文件
        java-event-log-tags.py //把EventLogTags.logtags文件翻成java
        merge-event-log-tags.py //把多个EventLogTags.logtags合并成一个,并检查number冲突
    
    merge-event-log-tags.py使用及/system/etc/event-log-tags文件创建时间点  
        详见:android/build/core/Makefile -- .PHONY: event-log-tags
    
    遗留:event-log-tags被使用细节?其他两个py被使用时间点?
posted @ 2024-01-11 15:25  亦幻  阅读(305)  评论(0编辑  收藏  举报