Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.content.common; | 5 package org.chromium.content.common; |
| 6 | 6 |
| 7 import android.os.Build; | 7 import android.os.Build; |
| 8 import android.os.Looper; | 8 import android.os.Looper; |
| 9 import android.util.Log; | 9 import android.util.Log; |
| 10 import android.util.Printer; | 10 import android.util.Printer; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 public void println(String line) { | 30 public void println(String line) { |
| 31 if (line.startsWith(">>>>>")) { | 31 if (line.startsWith(">>>>>")) { |
| 32 TraceEvent.begin(NAME, line); | 32 TraceEvent.begin(NAME, line); |
| 33 } else { | 33 } else { |
| 34 assert line.startsWith("<<<<<"); | 34 assert line.startsWith("<<<<<"); |
| 35 TraceEvent.end(NAME); | 35 TraceEvent.end(NAME); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 static { | |
| 41 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
| 42 try { | |
| 43 Class<?> systemPropertiesClass = Class.forName("android.os.Syste mProperties"); | |
| 44 Method addChangeCallbackMethod = systemPropertiesClass.getDeclar edMethod( | |
| 45 "addChangeCallback", Runnable.class); | |
| 46 addChangeCallbackMethod.invoke(null, new Runnable() { | |
| 47 @Override | |
| 48 public void run() { | |
| 49 setEnabledToMatchNative(); | |
| 50 } | |
| 51 }); | |
| 52 } catch (ClassNotFoundException e) { | |
| 53 Log.e("TraceEvent", "init", e); | |
| 54 } catch (NoSuchMethodException e) { | |
| 55 Log.e("TraceEvent", "init", e); | |
| 56 } catch (IllegalArgumentException e) { | |
| 57 Log.e("TraceEvent", "init", e); | |
| 58 } catch (IllegalAccessException e) { | |
| 59 Log.e("TraceEvent", "init", e); | |
| 60 } catch (InvocationTargetException e) { | |
| 61 Log.e("TraceEvent", "init", e); | |
| 62 } | |
| 63 } | |
| 64 } | |
| 65 | |
| 40 /** | 66 /** |
| 41 * Calling this will cause enabled() to be updated to match that set on the native side. | 67 * Calling this will cause enabled() to be updated to match that set on the native side. |
| 42 * The native library must be loaded before calling this method. | 68 * The native library must be loaded before calling this method. |
| 43 */ | 69 */ |
| 44 public static void setEnabledToMatchNative() { | 70 public static void setEnabledToMatchNative() { |
| 45 boolean enabled = nativeTraceEnabled(); | 71 boolean enabled = nativeTraceEnabled(); |
| 46 | 72 |
| 47 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | 73 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| 48 try { | 74 try { |
| 49 Class<?> traceClass = Class.forName("android.os.Trace"); | 75 Class<?> traceClass = Class.forName("android.os.Trace"); |
| 50 Method m = traceClass.getDeclaredMethod("isTagEnabled", Long.TYP E); | 76 long traceTagView = traceClass.getField("TRACE_TAG_VIEW").getLon g(null); |
| 51 Field f = traceClass.getField("TRACE_TAG_VIEW"); | 77 String propertyTraceTagEnableFlags = (String)traceClass.getField ( |
|
Jay Civelli
2013/02/13 18:24:02
Nit: missing space after (String)
Xianzhu
2013/02/13 21:50:17
Done.
| |
| 52 boolean atraceEnabled = (Boolean) m.invoke(traceClass, f.getLong (null)); | 78 "PROPERTY_TRACE_TAG_ENABLEFLAGS").get(null); |
| 53 if (atraceEnabled) nativeInitATrace(); | 79 |
| 54 enabled = enabled || atraceEnabled; | 80 Class<?> systemPropertiesClass = Class.forName("android.os.Syste mProperties"); |
| 81 Method systemPropertiesGetIntMethod = systemPropertiesClass.getD eclaredMethod( | |
| 82 "getInt", String.class, Integer.TYPE); | |
| 83 int enabledTags = (Integer) systemPropertiesGetIntMethod.invoke( | |
|
Jay Civelli
2013/02/13 18:24:02
Nit: should it be named enableFlags?
Xianzhu
2013/02/13 21:50:17
Done.
| |
| 84 null, propertyTraceTagEnableFlags, 0); | |
| 85 Log.d("TraceEvent", "New enabled tags: " + enabledTags); | |
| 86 if ((enabledTags & traceTagView) != 0) { | |
| 87 nativeStartATrace(); | |
| 88 enabled = true; | |
| 89 } else { | |
| 90 nativeStopATrace(); | |
| 91 } | |
| 55 } catch (ClassNotFoundException e) { | 92 } catch (ClassNotFoundException e) { |
| 56 Log.e("TraceEvent", "setEnabledToMatchNative", e); | 93 Log.e("TraceEvent", "setEnabledToMatchNative", e); |
| 57 } catch (NoSuchMethodException e) { | 94 } catch (NoSuchMethodException e) { |
| 58 Log.e("TraceEvent", "setEnabledToMatchNative", e); | 95 Log.e("TraceEvent", "setEnabledToMatchNative", e); |
| 59 } catch (NoSuchFieldException e) { | 96 } catch (NoSuchFieldException e) { |
| 60 Log.e("TraceEvent", "setEnabledToMatchNative", e); | 97 Log.e("TraceEvent", "setEnabledToMatchNative", e); |
| 61 } catch (IllegalArgumentException e) { | 98 } catch (IllegalArgumentException e) { |
| 62 Log.e("TraceEvent", "setEnabledToMatchNative", e); | 99 Log.e("TraceEvent", "setEnabledToMatchNative", e); |
| 63 } catch (IllegalAccessException e) { | 100 } catch (IllegalAccessException e) { |
| 64 Log.e("TraceEvent", "setEnabledToMatchNative", e); | 101 Log.e("TraceEvent", "setEnabledToMatchNative", e); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 // int index = 0; | 266 // int index = 0; |
| 230 // while (!stack[index].getClassName().equals(TraceEvent.class.getName( ))) ++index; | 267 // while (!stack[index].getClassName().equals(TraceEvent.class.getName( ))) ++index; |
| 231 // while (stack[index].getClassName().equals(TraceEvent.class.getName() )) ++index; | 268 // while (stack[index].getClassName().equals(TraceEvent.class.getName() )) ++index; |
| 232 // System.logW("TraceEvent caller is at stack index " + index); | 269 // System.logW("TraceEvent caller is at stack index " + index); |
| 233 | 270 |
| 234 // '4' Was derived using the above commented out code snippet. | 271 // '4' Was derived using the above commented out code snippet. |
| 235 return stack[4].getClassName() + "." + stack[4].getMethodName(); | 272 return stack[4].getClassName() + "." + stack[4].getMethodName(); |
| 236 } | 273 } |
| 237 | 274 |
| 238 private static native boolean nativeTraceEnabled(); | 275 private static native boolean nativeTraceEnabled(); |
| 239 private static native void nativeInitATrace(); | 276 private static native void nativeStartATrace(); |
| 277 private static native void nativeStopATrace(); | |
| 240 private static native void nativeInstant(String name, String arg); | 278 private static native void nativeInstant(String name, String arg); |
| 241 private static native void nativeBegin(String name, String arg); | 279 private static native void nativeBegin(String name, String arg); |
| 242 private static native void nativeEnd(String name, String arg); | 280 private static native void nativeEnd(String name, String arg); |
| 243 private static native void nativeStartAsync(String name, long id, String arg ); | 281 private static native void nativeStartAsync(String name, long id, String arg ); |
| 244 private static native void nativeFinishAsync(String name, long id, String ar g); | 282 private static native void nativeFinishAsync(String name, long id, String ar g); |
| 245 } | 283 } |
| OLD | NEW |