Index: base/android/java/src/org/chromium/base/TraceEvent.java |
diff --git a/base/android/java/src/org/chromium/base/TraceEvent.java b/base/android/java/src/org/chromium/base/TraceEvent.java |
index 3d3b11a04196cf40fe1179c3104eacd22c3285b7..9d315f315c190a22e071da34c8b6db756a44c4c2 100644 |
--- a/base/android/java/src/org/chromium/base/TraceEvent.java |
+++ b/base/android/java/src/org/chromium/base/TraceEvent.java |
@@ -9,16 +9,15 @@ import android.os.MessageQueue; |
import android.os.SystemClock; |
import android.util.Log; |
import android.util.Printer; |
+ |
/** |
* Java mirror of Chrome trace event API. See base/trace_event/trace_event.h. Unlike the native |
* version, Java does not have stack objects, so a TRACE_EVENT() which does both TRACE_EVENT_BEGIN() |
* and TRACE_EVENT_END() in ctor/dtor is not possible. |
- * It is OK to use tracing before the native library has loaded, but such traces will |
- * be ignored. (Perhaps we could devise to buffer them up in future?). |
+ * Note that this class can also be used before the native library is loaded for early tracing. |
*/ |
@JNINamespace("base::android") |
public class TraceEvent { |
- |
private static volatile boolean sEnabled = false; |
private static class BasicLooperMonitor implements Printer { |
@@ -175,12 +174,26 @@ public class TraceEvent { |
*/ |
@CalledByNative |
public static void setEnabled(boolean enabled) { |
+ if (!enabled) EarlyTraceEvent.disable(); |
+ |
sEnabled = enabled; |
ThreadUtils.getUiThreadLooper().setMessageLogging( |
enabled ? LooperMonitorHolder.sInstance : null); |
} |
/** |
+ * Can be called early during the application initialization so that TraceEvent can be used |
+ * before the native library is loaded. |
+ */ |
+ public static void enableEarlyTracing() { |
+ EarlyTraceEvent.enable(); |
+ } |
+ |
+ private static void disableEarlyTracing() { |
+ EarlyTraceEvent.disable(); |
+ } |
+ |
+ /** |
* Enables or disabled Android systrace path of Chrome tracing. If enabled, all Chrome |
* traces will be also output to Android systrace. Because of the overhead of Android |
* systrace, this is for WebView only. |
@@ -200,7 +213,7 @@ public class TraceEvent { |
* is enabled. |
*/ |
public static boolean enabled() { |
- return sEnabled; |
+ return sEnabled || EarlyTraceEvent.isEnabled(); |
} |
/** |
@@ -243,7 +256,7 @@ public class TraceEvent { |
* @param name The name of the event. |
*/ |
public static void begin(String name) { |
- if (sEnabled) nativeBegin(name, null); |
+ if (enabled()) begin(name, null); |
} |
/** |
@@ -252,7 +265,12 @@ public class TraceEvent { |
* @param arg The arguments of the event. |
*/ |
public static void begin(String name, String arg) { |
- if (sEnabled) nativeBegin(name, arg); |
+ if (sEnabled) { |
+ nativeBegin(name, arg); |
+ return; |
+ } |
+ |
+ EarlyTraceEvent.begin(name, arg); |
} |
/** |
@@ -260,7 +278,7 @@ public class TraceEvent { |
* @param name The name of the event. |
*/ |
public static void end(String name) { |
- if (sEnabled) nativeEnd(name, null); |
+ if (enabled()) end(name, null); |
} |
/** |
@@ -269,6 +287,10 @@ public class TraceEvent { |
* @param arg The arguments of the event. |
*/ |
public static void end(String name, String arg) { |
+ if (!enabled()) return; |
+ |
+ if (EarlyTraceEvent.end(name, arg)) return; |
+ |
if (sEnabled) nativeEnd(name, arg); |
} |