diff options
| author | John Reck <jreck@google.com> | 2018-07-16 10:42:35 -0700 |
|---|---|---|
| committer | Michael Wright <michaelwr@google.com> | 2018-07-17 14:35:01 +0000 |
| commit | d5a9dc06be523d3414a8a3103304357228e53072 (patch) | |
| tree | ac8de24ec11f6f23517f6907e2fd01325c831f40 /core/java/android | |
| parent | 71fa53f8a548993d30d91343caee0e6269e8c0c5 (diff) | |
Expose async & counter publicly
Also add some go-faster to the JNI
Before:
android.os.TracePerfTest:INSTRUMENTATION_STATUS: enabled_mean=13
INSTRUMENTATION_STATUS: enabled_median=13
INSTRUMENTATION_STATUS: enabled_min=13
INSTRUMENTATION_STATUS: enabled_standardDeviation=0
INSTRUMENTATION_STATUS_CODE: -1
.INSTRUMENTATION_STATUS: beginEndSection_mean=3849
INSTRUMENTATION_STATUS: beginEndSection_median=3850
INSTRUMENTATION_STATUS: beginEndSection_min=3829
INSTRUMENTATION_STATUS: beginEndSection_standardDeviation=14
INSTRUMENTATION_STATUS_CODE: -1
.INSTRUMENTATION_STATUS: counter_mean=1836
INSTRUMENTATION_STATUS: counter_median=1837
INSTRUMENTATION_STATUS: counter_min=1832
INSTRUMENTATION_STATUS: counter_standardDeviation=2
INSTRUMENTATION_STATUS_CODE: -1
.INSTRUMENTATION_STATUS: asyncBeginEnd_mean=4992
INSTRUMENTATION_STATUS: asyncBeginEnd_median=4988
INSTRUMENTATION_STATUS: asyncBeginEnd_min=4964
INSTRUMENTATION_STATUS: asyncBeginEnd_standardDeviation=21
INSTRUMENTATION_STATUS_CODE: -1
After:
android.os.TracePerfTest:INSTRUMENTATION_STATUS: enabled_mean=13
INSTRUMENTATION_STATUS: enabled_median=13
INSTRUMENTATION_STATUS: enabled_min=13
INSTRUMENTATION_STATUS: enabled_standardDeviation=0
INSTRUMENTATION_STATUS_CODE: -1
.INSTRUMENTATION_STATUS: beginEndSection_mean=2974
INSTRUMENTATION_STATUS: beginEndSection_median=2971
INSTRUMENTATION_STATUS: beginEndSection_min=2958
INSTRUMENTATION_STATUS: beginEndSection_standardDeviation=15
INSTRUMENTATION_STATUS_CODE: -1
.INSTRUMENTATION_STATUS: counter_mean=1737
INSTRUMENTATION_STATUS: counter_median=1739
INSTRUMENTATION_STATUS: counter_min=1732
INSTRUMENTATION_STATUS: counter_standardDeviation=3
INSTRUMENTATION_STATUS_CODE: -1
.INSTRUMENTATION_STATUS: asyncBeginEnd_mean=3677
INSTRUMENTATION_STATUS: asyncBeginEnd_median=3679
INSTRUMENTATION_STATUS: asyncBeginEnd_min=3663
INSTRUMENTATION_STATUS: asyncBeginEnd_standardDeviation=11
INSTRUMENTATION_STATUS_CODE: -1
Test: builds, benchmarks, verified tracing still works
Bug: 111503982
Change-Id: I71cb026d034bf9b9f97427d10d5ff9ce3d103561
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/Trace.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/java/android/os/Trace.java b/core/java/android/os/Trace.java index 583f060f2e0c..a967b3da339e 100644 --- a/core/java/android/os/Trace.java +++ b/core/java/android/os/Trace.java @@ -288,6 +288,19 @@ public final class Trace { } /** + * 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 + * recommended to use this to prevent creating any temporary objects that would then be + * passed to those methods to reduce runtime cost when tracing isn't enabled. + * + * @return true if tracing is currently enabled, false otherwise + */ + public static boolean isEnabled() { + return isTagEnabled(TRACE_TAG_APP); + } + + /** * Writes a trace message to indicate that a given section of code has begun. This call must * be followed by a corresponding call to {@link #endSection()} on the same thread. * @@ -319,4 +332,42 @@ public final class Trace { nativeTraceEnd(TRACE_TAG_APP); } } + + /** + * Writes a trace message to indicate that a given section of code has + * begun. Must be followed by a call to {@link #endAsyncSection(String, int)} with the same + * methodName and cookie. Unlike {@link #beginSection(String)} and {@link #endSection()}, + * asynchronous events do not need to be nested. The name and cookie used to + * begin an event must be used to end it. + * + * @param methodName The method name to appear in the trace. + * @param cookie Unique identifier for distinguishing simultaneous events + */ + public static void beginAsyncSection(String methodName, int cookie) { + asyncTraceBegin(TRACE_TAG_APP, methodName, cookie); + } + + /** + * Writes a trace message to indicate that the current method has ended. + * Must be called exactly once for each call to {@link #beginAsyncSection(String, int)} + * using the same name and cookie. + * + * @param methodName The method name to appear in the trace. + * @param cookie Unique identifier for distinguishing simultaneous events + */ + public static void endAsyncSection(String methodName, int cookie) { + asyncTraceEnd(TRACE_TAG_APP, methodName, cookie); + } + + /** + * Writes trace message to indicate the value of a given counter. + * + * @param counterName The counter name to appear in the trace. + * @param counterValue The counter value. + */ + public static void setCounter(String counterName, int counterValue) { + if (isTagEnabled(TRACE_TAG_APP)) { + nativeTraceCounter(TRACE_TAG_APP, counterName, counterValue); + } + } } |
