Java打印 第一种
notification_visibility转为writeNoticationVisibility
编译时候会解析生成文件EventLogTags.java,然后代码再去调用以实现添加EventLog
可以在out目录下执行命令 find -name EventLogTags.java来找对应目录生成的EventLogTags.java
@/frameworks/base/services/core/java/com/android/server/EventLogTags.logtags
# replaces 27510 with a row per notification
7627531 notification_visibility (key|3),(visibile|1),(lifespan|1),(freshness|1),(exposure|1),(rank|1)
notification_visibility 解析出来是 writeNoticationVisibility
@/frameworks/base/services/core/java/com/android/server/notification/NotificationRecord.java
/**
* Set the visibility of the notification.
*/
public void setVisibility(boolean visible, int rank) {
final long now = System.currentTimeMillis();
mVisibleSinceMs = visible ? now : mVisibleSinceMs;
stats.onVisibilityChanged(visible);
MetricsLogger.action(getLogMaker(now)
.setCategory(MetricsEvent.NOTIFICATION_ITEM)
.setType(visible ? MetricsEvent.TYPE_OPEN : MetricsEvent.TYPE_CLOSE)
.addTaggedData(MetricsEvent.NOTIFICATION_SHADE_INDEX, rank));
if (visible) {
MetricsLogger.histogram(mContext, "note_freshness", getFreshnessMs(now));
}
EventLogTags.writeNotificationVisibility(getKey(), visible ? 1 : 0, //这里打印Log
getLifespanMs(now),
getFreshnessMs(now),
0, // exposure time
rank);
}
Java第二种
boot_progress_system_run直接大写BOOT_PROGRESS_SYSTEM_RUN
/frameworks/base/services/core/java/com/android/server/EventLogTags.logtags
# SystemServer.run() starts:
3010 boot_progress_system_run (time|2|3)
@/frameworks/base/services/java/com/android/server/SystemServer.java
// Here we go!
Slog.i(TAG, "Entered the Android system server!");
int uptimeMillis = (int) SystemClock.elapsedRealtime();
EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, uptimeMillis);
Native第三种
BINDER_SAMPLE 的值是 52004
//cat EventLogTags.java入下
android/out/soong/.intermediates/frameworks/base$ cat ./api-stubs-docs/android_common/gen/logtags/frameworks/base/core/java/android/content/EventLogTags.*
/* This file is auto-generated. DO NOT MODIFY.
* Source file: frameworks/base/core/java/android/content/EventLogTags.logtags
*/
package android.content;;
/**
* @hide
*/
public class EventLogTags {
private EventLogTags() { } // don't instantiate
/** 52002 content_query_sample (uri|3),(projection|3),(selection|3),(sortorder|3),(time|1|3),(blocking_package|3),(sample_percent|1|6) */
public static final int CONTENT_QUERY_SAMPLE = 52002;
/** 52003 content_update_sample (uri|3),(operation|3),(selection|3),(time|1|3),(blocking_package|3),(sample_percent|1|6) */
public static final int CONTENT_UPDATE_SAMPLE = 52003;
/** 52004 binder_sample (descriptor|3),(method_num|1|5),(time|1|3),(blocking_package|3),(sample_percent|1|6) */
public static final int BINDER_SAMPLE = 52004;
public static void writeContentQuerySample(String uri, String projection, String selection, String sortorder, int time, String blockingPackage, int samplePercent) {
android.util.EventLog.writeEvent(CONTENT_QUERY_SAMPLE, uri, projection, selection, sortorder, time, blockingPackage, samplePercent);
}
public static void writeContentUpdateSample(String uri, String operation, String selection, int time, String blockingPackage, int samplePercent) {
android.util.EventLog.writeEvent(CONTENT_UPDATE_SAMPLE, uri, operation, selection, time, blockingPackage, samplePercent);
}
public static void writeBinderSample(String descriptor, int methodNum, int time, String blockingPackage, int samplePercent) {
android.util.EventLog.writeEvent(BINDER_SAMPLE, descriptor, methodNum, time, blockingPackage, samplePercent);
}
}
Bidner_sample的打印位置 LOGTAG_BINDER_OPERATION 就是eventLog定义的 BINDER_SAMPLE
@frameworks/base/core/jni/android_util_Binder.cpp
#define LOGTAG_BINDER_OPERATION 52004
static void conditionally_log_binder_call(int64_t start_millis,
IBinder* target, jint code) {
int duration_ms = static_cast<int>(uptimeMillis() - start_millis);
int sample_percent;
...
if (!push_eventlog_string(&pos, end, process_name)) return;
if (!push_eventlog_int(&pos, end, sample_percent)) return;
*(pos++) = '\n'; // conventional with EVENT_TYPE_LIST apparently.
android_bWriteLog(LOGTAG_BINDER_OPERATION, buf, pos - buf);
}
android_bWriteLog最终调用write_to_log写eventID
@system/core/liblog/logger_write.c
LIBLOG_ABI_PUBLIC int __android_log_bwrite(int32_t tag, const void* payload,
size_t len) {
struct iovec vec[2];
vec[0].iov_base = &tag;
vec[0].iov_len = sizeof(tag);
vec[1].iov_base = (void*)payload;
vec[1].iov_len = len;
return write_to_log(LOG_ID_EVENTS, vec, 2);
}
``