Log wrapper for multi-metrics in tron.
Test: Added new LogBuilderTest; runtest --path frameworks/base/core/tests/coretests/src/com/android/internal/logging/LogBuilderTest.java new file: core/java/com/android/internal/logging/LogWrapper.java Change-Id: I8c64a07b95ab9a70f39663d4ec54f9ec1bf49063
This commit is contained in:
@@ -5,5 +5,6 @@ option java_package com.android.internal.logging;
|
||||
# interaction logs
|
||||
524287 sysui_view_visibility (category|1|5),(visible|1|6)
|
||||
524288 sysui_action (category|1|5),(pkg|3)
|
||||
524292 sysui_multi_action (content|4)
|
||||
524290 sysui_count (name|3),(increment|1)
|
||||
524291 sysui_histogram (name|3),(bucket|1)
|
||||
|
||||
67
core/java/com/android/internal/logging/LogBuilder.java
Normal file
67
core/java/com/android/internal/logging/LogBuilder.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.android.internal.logging;
|
||||
|
||||
import android.util.EventLog;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Helper class to assemble more complex logs.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
|
||||
public class LogBuilder {
|
||||
|
||||
private SparseArray<Object> entries = new SparseArray();
|
||||
|
||||
public LogBuilder() {}
|
||||
|
||||
|
||||
public LogBuilder setView(View view) {
|
||||
entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_VIEW, view.getId());
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogBuilder setCategory(int category) {
|
||||
entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_CATEGORY, category);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogBuilder setType(int type) {
|
||||
entries.put(MetricsEvent.RESERVED_FOR_LOGBUILDER_TYPE, type);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tag From your MetricsEvent enum.
|
||||
* @param value One of Integer, Long, Float, String
|
||||
* @return
|
||||
*/
|
||||
public LogBuilder addTaggedData(int tag, Object value) {
|
||||
if (!(value instanceof Integer ||
|
||||
value instanceof String ||
|
||||
value instanceof Long ||
|
||||
value instanceof Float)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Value must be loggable type - int, long, float, String");
|
||||
}
|
||||
entries.put(tag, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble logs into structure suitable for EventLog.
|
||||
*/
|
||||
public Object[] serialize() {
|
||||
Object[] out = new Object[entries.size() * 2];
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
out[i * 2] = entries.keyAt(i);
|
||||
out[i * 2 + 1] = entries.valueAt(i);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@ package com.android.internal.logging;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.EventLog;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
|
||||
|
||||
/**
|
||||
* Log all the things.
|
||||
*
|
||||
@@ -71,6 +73,14 @@ public class MetricsLogger {
|
||||
action(context, category, Boolean.toString(value));
|
||||
}
|
||||
|
||||
public static void action(LogBuilder content) {
|
||||
//EventLog.writeEvent(524292, content.serialize());
|
||||
// Below would be the *right* way to do this, using the generated
|
||||
// EventLogTags method, but that doesn't work.
|
||||
EventLogTags.writeSysuiMultiAction(content.serialize());
|
||||
}
|
||||
|
||||
|
||||
public static void action(Context context, int category, String pkg) {
|
||||
if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) {
|
||||
throw new IllegalArgumentException("Must define metric category");
|
||||
|
||||
Reference in New Issue
Block a user