Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: base/android/java/src/org/chromium/base/TraceEvent.java

Issue 2145443002: Revert of Android: Add support for TraceEvent before the native library is loaded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, in a slightly r estricted fashion. 19 * It is OK to use tracing before the native library has loaded, but such traces will
20 * @see EarlyTraceEvent for details. 20 * be ignored. (Perhaps we could devise to buffer them up in future?).
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
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();
183 sEnabled = enabled; 182 sEnabled = enabled;
184 // Android M+ systrace logs this on its own. Only log it if not writing to Android systrace. 183 // Android M+ systrace logs this on its own. Only log it if not writing to Android systrace.
185 if (sATraceEnabled) return; 184 if (sATraceEnabled) return;
186 ThreadUtils.getUiThreadLooper().setMessageLogging( 185 ThreadUtils.getUiThreadLooper().setMessageLogging(
187 enabled ? LooperMonitorHolder.sInstance : null); 186 enabled ? LooperMonitorHolder.sInstance : null);
188 } 187 }
189 188
190 /** 189 /**
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 /**
200 * Enables or disabled Android systrace path of Chrome tracing. If enabled, all Chrome 190 * Enables or disabled Android systrace path of Chrome tracing. If enabled, all Chrome
201 * traces will be also output to Android systrace. Because of the overhead o f Android 191 * traces will be also output to Android systrace. Because of the overhead o f Android
202 * systrace, this is for WebView only. 192 * systrace, this is for WebView only.
203 */ 193 */
204 public static void setATraceEnabled(boolean enabled) { 194 public static void setATraceEnabled(boolean enabled) {
205 if (sATraceEnabled == enabled) return; 195 if (sATraceEnabled == enabled) return;
206 sATraceEnabled = enabled; 196 sATraceEnabled = enabled;
207 if (enabled) { 197 if (enabled) {
208 // Calls TraceEvent.setEnabled(true) via 198 // Calls TraceEvent.setEnabled(true) via
209 // TraceLog::EnabledStateObserver::OnTraceLogEnabled 199 // TraceLog::EnabledStateObserver::OnTraceLogEnabled
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 */ 247 */
258 public static void finishAsync(String name, long id) { 248 public static void finishAsync(String name, long id) {
259 if (sEnabled) nativeFinishAsync(name, id); 249 if (sEnabled) nativeFinishAsync(name, id);
260 } 250 }
261 251
262 /** 252 /**
263 * Triggers the 'begin' native trace event with no arguments. 253 * Triggers the 'begin' native trace event with no arguments.
264 * @param name The name of the event. 254 * @param name The name of the event.
265 */ 255 */
266 public static void begin(String name) { 256 public static void begin(String name) {
267 begin(name, null); 257 if (sEnabled) nativeBegin(name, null);
268 } 258 }
269 259
270 /** 260 /**
271 * Triggers the 'begin' native trace event. 261 * Triggers the 'begin' native trace event.
272 * @param name The name of the event. 262 * @param name The name of the event.
273 * @param arg The arguments of the event. 263 * @param arg The arguments of the event.
274 */ 264 */
275 public static void begin(String name, String arg) { 265 public static void begin(String name, String arg) {
276 EarlyTraceEvent.begin(name);
277 if (sEnabled) nativeBegin(name, arg); 266 if (sEnabled) nativeBegin(name, arg);
278 } 267 }
279 268
280 /** 269 /**
281 * Triggers the 'end' native trace event with no arguments. 270 * Triggers the 'end' native trace event with no arguments.
282 * @param name The name of the event. 271 * @param name The name of the event.
283 */ 272 */
284 public static void end(String name) { 273 public static void end(String name) {
285 end(name, null); 274 if (sEnabled) nativeEnd(name, null);
286 } 275 }
287 276
288 /** 277 /**
289 * Triggers the 'end' native trace event. 278 * Triggers the 'end' native trace event.
290 * @param name The name of the event. 279 * @param name The name of the event.
291 * @param arg The arguments of the event. 280 * @param arg The arguments of the event.
292 */ 281 */
293 public static void end(String name, String arg) { 282 public static void end(String name, String arg) {
294 EarlyTraceEvent.end(name);
295 if (sEnabled) nativeEnd(name, arg); 283 if (sEnabled) nativeEnd(name, arg);
296 } 284 }
297 285
298 private static native void nativeRegisterEnabledObserver(); 286 private static native void nativeRegisterEnabledObserver();
299 private static native void nativeStartATrace(); 287 private static native void nativeStartATrace();
300 private static native void nativeStopATrace(); 288 private static native void nativeStopATrace();
301 private static native void nativeInstant(String name, String arg); 289 private static native void nativeInstant(String name, String arg);
302 private static native void nativeBegin(String name, String arg); 290 private static native void nativeBegin(String name, String arg);
303 private static native void nativeEnd(String name, String arg); 291 private static native void nativeEnd(String name, String arg);
304 private static native void nativeBeginToplevel(); 292 private static native void nativeBeginToplevel();
305 private static native void nativeEndToplevel(); 293 private static native void nativeEndToplevel();
306 private static native void nativeStartAsync(String name, long id); 294 private static native void nativeStartAsync(String name, long id);
307 private static native void nativeFinishAsync(String name, long id); 295 private static native void nativeFinishAsync(String name, long id);
308 } 296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698