| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.base; | 5 package org.chromium.base; |
| 6 | 6 |
| 7 import android.os.Looper; | 7 import android.os.Looper; |
| 8 import android.os.MessageQueue; | 8 import android.os.MessageQueue; |
| 9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
| 10 import android.util.Log; | 10 import android.util.Log; |
| 11 import android.util.Printer; | 11 import android.util.Printer; |
| 12 | 12 |
| 13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
| 14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
| 15 /** | 15 /** |
| 16 * Java mirror of Chrome trace event API. See base/trace_event/trace_event.h. Un
like the native | 16 * Java mirror of Chrome trace event API. See base/trace_event/trace_event.h. Un
like the native |
| 17 * version, Java does not have stack objects, so a TRACE_EVENT() which does both
TRACE_EVENT_BEGIN() | 17 * version, Java does not have stack objects, so a TRACE_EVENT() which does both
TRACE_EVENT_BEGIN() |
| 18 * and TRACE_EVENT_END() in ctor/dtor is not possible. | 18 * and TRACE_EVENT_END() in ctor/dtor is not possible. |
| 19 * It is OK to use tracing before the native library has loaded, but such traces
will | 19 * It is OK to use tracing before the native library has loaded, in a slightly r
estricted fashion. |
| 20 * be ignored. (Perhaps we could devise to buffer them up in future?). | 20 * @see EarlyTraceEvent for details. |
| 21 */ | 21 */ |
| 22 @JNINamespace("base::android") | 22 @JNINamespace("base::android") |
| 23 public class TraceEvent { | 23 public class TraceEvent { |
| 24 | 24 |
| 25 private static volatile boolean sEnabled = false; | 25 private static volatile boolean sEnabled = false; |
| 26 private static volatile boolean sATraceEnabled = false; // True when taking
an Android systrace. | 26 private static volatile boolean sATraceEnabled = false; // True when taking
an Android systrace. |
| 27 | 27 |
| 28 private static class BasicLooperMonitor implements Printer { | 28 private static class BasicLooperMonitor implements Printer { |
| 29 @Override | 29 @Override |
| 30 public void println(final String line) { | 30 public void println(final String line) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 */ | 172 */ |
| 173 public static void registerNativeEnabledObserver() { | 173 public static void registerNativeEnabledObserver() { |
| 174 nativeRegisterEnabledObserver(); | 174 nativeRegisterEnabledObserver(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * Notification from native that tracing is enabled/disabled. | 178 * Notification from native that tracing is enabled/disabled. |
| 179 */ | 179 */ |
| 180 @CalledByNative | 180 @CalledByNative |
| 181 public static void setEnabled(boolean enabled) { | 181 public static void setEnabled(boolean enabled) { |
| 182 if (enabled) EarlyTraceEvent.disable(); |
| 182 sEnabled = enabled; | 183 sEnabled = enabled; |
| 183 // Android M+ systrace logs this on its own. Only log it if not writing
to Android systrace. | 184 // Android M+ systrace logs this on its own. Only log it if not writing
to Android systrace. |
| 184 if (sATraceEnabled) return; | 185 if (sATraceEnabled) return; |
| 185 ThreadUtils.getUiThreadLooper().setMessageLogging( | 186 ThreadUtils.getUiThreadLooper().setMessageLogging( |
| 186 enabled ? LooperMonitorHolder.sInstance : null); | 187 enabled ? LooperMonitorHolder.sInstance : null); |
| 187 } | 188 } |
| 188 | 189 |
| 189 /** | 190 /** |
| 191 * May enable early tracing depending on the environment. |
| 192 * |
| 193 * Must be called after the command-line has been read. |
| 194 */ |
| 195 public static void maybeEnableEarlyTracing() { |
| 196 EarlyTraceEvent.maybeEnable(); |
| 197 } |
| 198 |
| 199 /** |
| 190 * Enables or disabled Android systrace path of Chrome tracing. If enabled,
all Chrome | 200 * Enables or disabled Android systrace path of Chrome tracing. If enabled,
all Chrome |
| 191 * traces will be also output to Android systrace. Because of the overhead o
f Android | 201 * traces will be also output to Android systrace. Because of the overhead o
f Android |
| 192 * systrace, this is for WebView only. | 202 * systrace, this is for WebView only. |
| 193 */ | 203 */ |
| 194 public static void setATraceEnabled(boolean enabled) { | 204 public static void setATraceEnabled(boolean enabled) { |
| 195 if (sATraceEnabled == enabled) return; | 205 if (sATraceEnabled == enabled) return; |
| 196 sATraceEnabled = enabled; | 206 sATraceEnabled = enabled; |
| 197 if (enabled) { | 207 if (enabled) { |
| 198 // Calls TraceEvent.setEnabled(true) via | 208 // Calls TraceEvent.setEnabled(true) via |
| 199 // TraceLog::EnabledStateObserver::OnTraceLogEnabled | 209 // TraceLog::EnabledStateObserver::OnTraceLogEnabled |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 */ | 257 */ |
| 248 public static void finishAsync(String name, long id) { | 258 public static void finishAsync(String name, long id) { |
| 249 if (sEnabled) nativeFinishAsync(name, id); | 259 if (sEnabled) nativeFinishAsync(name, id); |
| 250 } | 260 } |
| 251 | 261 |
| 252 /** | 262 /** |
| 253 * Triggers the 'begin' native trace event with no arguments. | 263 * Triggers the 'begin' native trace event with no arguments. |
| 254 * @param name The name of the event. | 264 * @param name The name of the event. |
| 255 */ | 265 */ |
| 256 public static void begin(String name) { | 266 public static void begin(String name) { |
| 257 if (sEnabled) nativeBegin(name, null); | 267 begin(name, null); |
| 258 } | 268 } |
| 259 | 269 |
| 260 /** | 270 /** |
| 261 * Triggers the 'begin' native trace event. | 271 * Triggers the 'begin' native trace event. |
| 262 * @param name The name of the event. | 272 * @param name The name of the event. |
| 263 * @param arg The arguments of the event. | 273 * @param arg The arguments of the event. |
| 264 */ | 274 */ |
| 265 public static void begin(String name, String arg) { | 275 public static void begin(String name, String arg) { |
| 276 EarlyTraceEvent.begin(name); |
| 266 if (sEnabled) nativeBegin(name, arg); | 277 if (sEnabled) nativeBegin(name, arg); |
| 267 } | 278 } |
| 268 | 279 |
| 269 /** | 280 /** |
| 270 * Triggers the 'end' native trace event with no arguments. | 281 * Triggers the 'end' native trace event with no arguments. |
| 271 * @param name The name of the event. | 282 * @param name The name of the event. |
| 272 */ | 283 */ |
| 273 public static void end(String name) { | 284 public static void end(String name) { |
| 274 if (sEnabled) nativeEnd(name, null); | 285 end(name, null); |
| 275 } | 286 } |
| 276 | 287 |
| 277 /** | 288 /** |
| 278 * Triggers the 'end' native trace event. | 289 * Triggers the 'end' native trace event. |
| 279 * @param name The name of the event. | 290 * @param name The name of the event. |
| 280 * @param arg The arguments of the event. | 291 * @param arg The arguments of the event. |
| 281 */ | 292 */ |
| 282 public static void end(String name, String arg) { | 293 public static void end(String name, String arg) { |
| 294 EarlyTraceEvent.end(name); |
| 283 if (sEnabled) nativeEnd(name, arg); | 295 if (sEnabled) nativeEnd(name, arg); |
| 284 } | 296 } |
| 285 | 297 |
| 286 private static native void nativeRegisterEnabledObserver(); | 298 private static native void nativeRegisterEnabledObserver(); |
| 287 private static native void nativeStartATrace(); | 299 private static native void nativeStartATrace(); |
| 288 private static native void nativeStopATrace(); | 300 private static native void nativeStopATrace(); |
| 289 private static native void nativeInstant(String name, String arg); | 301 private static native void nativeInstant(String name, String arg); |
| 290 private static native void nativeBegin(String name, String arg); | 302 private static native void nativeBegin(String name, String arg); |
| 291 private static native void nativeEnd(String name, String arg); | 303 private static native void nativeEnd(String name, String arg); |
| 292 private static native void nativeBeginToplevel(); | 304 private static native void nativeBeginToplevel(); |
| 293 private static native void nativeEndToplevel(); | 305 private static native void nativeEndToplevel(); |
| 294 private static native void nativeStartAsync(String name, long id); | 306 private static native void nativeStartAsync(String name, long id); |
| 295 private static native void nativeFinishAsync(String name, long id); | 307 private static native void nativeFinishAsync(String name, long id); |
| 296 } | 308 } |
| OLD | NEW |