diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-12-15 19:31:26 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-12-15 19:31:26 +0000 |
| commit | 1ebda598ca89d2d2e6e53ae1e602c848870c36fd (patch) | |
| tree | 4cb77068919509f45ac531d894e9ab3a02a19134 | |
| parent | ebbe3194466d9d9c87c9ebea65a673a7e12677c9 (diff) | |
| parent | 891c20d0261d38b863c24f57b4d1d2546e81f66b (diff) | |
Merge "Log UI events to traces" am: a9666fccb9 am: 6e713ddc1e am: 8b81ff8dbc am: 891c20d026
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1920746
Change-Id: I5ed8fc8d20463550a043443b2e03e73b3d103a52
| -rw-r--r-- | core/java/android/os/Trace.java | 40 | ||||
| -rw-r--r-- | core/jni/android_os_Trace.cpp | 22 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt | 6 |
3 files changed, 66 insertions, 2 deletions
diff --git a/core/java/android/os/Trace.java b/core/java/android/os/Trace.java index ddb6533547bb..d974e0c0713a 100644 --- a/core/java/android/os/Trace.java +++ b/core/java/android/os/Trace.java @@ -131,6 +131,10 @@ public final class Trace { private static native void nativeAsyncTraceBegin(long tag, String name, int cookie); @FastNative private static native void nativeAsyncTraceEnd(long tag, String name, int cookie); + @FastNative + private static native void nativeInstant(long tag, String name); + @FastNative + private static native void nativeInstantForTrack(long tag, String trackName, String name); private Trace() { } @@ -258,6 +262,42 @@ public final class Trace { } /** + * Writes a trace message to indicate that a given section of code was invoked. + * + * @param traceTag The trace tag. + * @param methodName The method name to appear in the trace. + * @hide + */ + public static void instant(long traceTag, String methodName) { + if (methodName == null) { + throw new IllegalArgumentException("methodName cannot be null"); + } + if (isTagEnabled(traceTag)) { + nativeInstant(traceTag, methodName); + } + } + + /** + * Writes a trace message to indicate that a given section of code was invoked. + * + * @param traceTag The trace tag. + * @param trackName The track where the event should appear in the trace. + * @param methodName The method name to appear in the trace. + * @hide + */ + public static void instantForTrack(long traceTag, String trackName, String methodName) { + if (trackName == null) { + throw new IllegalArgumentException("trackName cannot be null"); + } + if (methodName == null) { + throw new IllegalArgumentException("methodName cannot be null"); + } + if (isTagEnabled(traceTag)) { + nativeInstantForTrack(traceTag, trackName, methodName); + } + } + + /** * Checks whether or not tracing is currently enabled. This is useful to avoid intermediate * string creation for trace sections that require formatting. It is not necessary * to guard all Trace method calls as they internally already check this. However it is diff --git a/core/jni/android_os_Trace.cpp b/core/jni/android_os_Trace.cpp index f67007cda209..85fd5d99e473 100644 --- a/core/jni/android_os_Trace.cpp +++ b/core/jni/android_os_Trace.cpp @@ -90,6 +90,22 @@ static void android_os_Trace_nativeSetTracingEnabled(JNIEnv*, jclass, jboolean e atrace_set_tracing_enabled(enabled); } +static void android_os_Trace_nativeInstant(JNIEnv* env, jclass, + jlong tag, jstring nameStr) { + withString(env, nameStr, [tag](char* str) { + atrace_instant(tag, str); + }); +} + +static void android_os_Trace_nativeInstantForTrack(JNIEnv* env, jclass, + jlong tag, jstring trackStr, jstring nameStr) { + withString(env, trackStr, [env, tag, nameStr](char* track) { + withString(env, nameStr, [tag, track](char* name) { + atrace_instant_for_track(tag, track, name); + }); + }); +} + static const JNINativeMethod gTraceMethods[] = { /* name, signature, funcPtr */ { "nativeSetAppTracingAllowed", @@ -116,6 +132,12 @@ static const JNINativeMethod gTraceMethods[] = { { "nativeAsyncTraceEnd", "(JLjava/lang/String;I)V", (void*)android_os_Trace_nativeAsyncTraceEnd }, + { "nativeInstant", + "(JLjava/lang/String;)V", + (void*)android_os_Trace_nativeInstant }, + { "nativeInstantForTrack", + "(JLjava/lang/String;Ljava/lang/String;)V", + (void*)android_os_Trace_nativeInstantForTrack }, // ----------- @CriticalNative ---------------- { "nativeGetEnabledTags", diff --git a/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt b/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt index 9e0038112dd3..492fdc699935 100644 --- a/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt +++ b/packages/SystemUI/src/com/android/systemui/log/LogBuffer.kt @@ -16,6 +16,7 @@ package com.android.systemui.log +import android.os.Trace import android.util.Log import com.android.systemui.log.dagger.LogModule import java.io.PrintWriter @@ -176,7 +177,7 @@ class LogBuffer( buffer.add(message as LogMessageImpl) if (logcatEchoTracker.isBufferLoggable(name, message.level) || logcatEchoTracker.isTagLoggable(message.tag, message.level)) { - echoToLogcat(message) + echo(message) } } @@ -226,7 +227,7 @@ class LogBuffer( pw.println(message.printer(message)) } - private fun echoToLogcat(message: LogMessage) { + private fun echo(message: LogMessage) { val strMessage = message.printer(message) when (message.level) { LogLevel.VERBOSE -> Log.v(message.tag, strMessage) @@ -236,6 +237,7 @@ class LogBuffer( LogLevel.ERROR -> Log.e(message.tag, strMessage) LogLevel.WTF -> Log.wtf(message.tag, strMessage) } + Trace.instantForTrack(Trace.TRACE_TAG_APP, "UI Events", strMessage) } } |
