summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-15 17:24:43 +0000
committerwangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-15 17:24:43 +0000
commit13afd5bb00c081a0a78ebdef0fee92d0a28b8a22 (patch)
tree9be8fa974a8cb96101fa964d665d9fa6401544d4
parent1e95b98814152b853988948ffd2203b67e198a8d (diff)
downloadchromium_src-13afd5bb00c081a0a78ebdef0fee92d0a28b8a22.zip
chromium_src-13afd5bb00c081a0a78ebdef0fee92d0a28b8a22.tar.gz
chromium_src-13afd5bb00c081a0a78ebdef0fee92d0a28b8a22.tar.bz2
Support JellyBean MR2 style of systrace
JB MR2 systrace.py combined the steps of trace tags settings and trace collection into one step, so we need to react to the change of trace tags settings to enable/disable atrace in chrome. The change also benefit pre-JB-MR2 systems that we don't need to restart chrome after changing the trace tags settings in Developer options. However, we still need "adb shell stop; adb shell start" if we set the trace tags using pre-JB-MR2 systrace.py. BUG=173954 Review URL: https://chromiumcodereview.appspot.com/12221047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182739 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/debug/trace_event_android.cc23
-rw-r--r--base/debug/trace_event_impl.h3
-rw-r--r--content/common/android/trace_event_binding.cc8
-rw-r--r--content/public/android/java/src/org/chromium/content/common/TraceEvent.java50
4 files changed, 69 insertions, 15 deletions
diff --git a/base/debug/trace_event_android.cc b/base/debug/trace_event_android.cc
index 29e684a..2901a34 100644
--- a/base/debug/trace_event_android.cc
+++ b/base/debug/trace_event_android.cc
@@ -20,12 +20,21 @@ const char* kATraceMarkerFile = "/sys/kernel/debug/tracing/trace_marker";
namespace base {
namespace debug {
-// static
-void TraceLog::InitATrace() {
- DCHECK(g_atrace_fd == -1);
- g_atrace_fd = open(kATraceMarkerFile, O_WRONLY | O_APPEND);
- if (g_atrace_fd == -1)
- LOG(WARNING) << "Couldn't open " << kATraceMarkerFile;
+void TraceLog::StartATrace() {
+ AutoLock lock(lock_);
+ if (g_atrace_fd == -1) {
+ g_atrace_fd = open(kATraceMarkerFile, O_WRONLY);
+ if (g_atrace_fd == -1)
+ LOG(WARNING) << "Couldn't open " << kATraceMarkerFile;
+ }
+}
+
+void TraceLog::StopATrace() {
+ AutoLock lock(lock_);
+ if (g_atrace_fd != -1) {
+ close(g_atrace_fd);
+ g_atrace_fd = -1;
+ }
}
void TraceLog::SendToATrace(char phase,
@@ -91,6 +100,8 @@ void TraceLog::SendToATrace(char phase,
void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_enabled) {
if (g_atrace_fd != -1)
*category_enabled |= ATRACE_ENABLED;
+ else
+ *category_enabled &= ~ATRACE_ENABLED;
}
} // namespace debug
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h
index 58a44da..7e306e2 100644
--- a/base/debug/trace_event_impl.h
+++ b/base/debug/trace_event_impl.h
@@ -209,7 +209,8 @@ class BASE_EXPORT TraceLog {
bool IsEnabled() { return !!enable_count_; }
#if defined(OS_ANDROID)
- static void InitATrace();
+ void StartATrace();
+ void StopATrace();
#endif
// Enabled state listeners give a callback when tracing is enabled or
diff --git a/content/common/android/trace_event_binding.cc b/content/common/android/trace_event_binding.cc
index 6dd3847..04607ed 100644
--- a/content/common/android/trace_event_binding.cc
+++ b/content/common/android/trace_event_binding.cc
@@ -76,8 +76,12 @@ static jboolean TraceEnabled(JNIEnv* env, jclass clazz) {
return base::debug::TraceLog::GetInstance()->IsEnabled();
}
-static void InitATrace(JNIEnv* env, jclass clazz) {
- base::debug::TraceLog::InitATrace();
+static void StartATrace(JNIEnv* env, jclass clazz) {
+ base::debug::TraceLog::GetInstance()->StartATrace();
+}
+
+static void StopATrace(JNIEnv* env, jclass clazz) {
+ base::debug::TraceLog::GetInstance()->StopATrace();
}
static void Instant(JNIEnv* env, jclass clazz,
diff --git a/content/public/android/java/src/org/chromium/content/common/TraceEvent.java b/content/public/android/java/src/org/chromium/content/common/TraceEvent.java
index 67c5413..ffd2528 100644
--- a/content/public/android/java/src/org/chromium/content/common/TraceEvent.java
+++ b/content/public/android/java/src/org/chromium/content/common/TraceEvent.java
@@ -37,6 +37,32 @@ public class TraceEvent {
}
}
+ static {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ try {
+ Class<?> systemPropertiesClass = Class.forName("android.os.SystemProperties");
+ Method addChangeCallbackMethod = systemPropertiesClass.getDeclaredMethod(
+ "addChangeCallback", Runnable.class);
+ addChangeCallbackMethod.invoke(null, new Runnable() {
+ @Override
+ public void run() {
+ setEnabledToMatchNative();
+ }
+ });
+ } catch (ClassNotFoundException e) {
+ Log.e("TraceEvent", "init", e);
+ } catch (NoSuchMethodException e) {
+ Log.e("TraceEvent", "init", e);
+ } catch (IllegalArgumentException e) {
+ Log.e("TraceEvent", "init", e);
+ } catch (IllegalAccessException e) {
+ Log.e("TraceEvent", "init", e);
+ } catch (InvocationTargetException e) {
+ Log.e("TraceEvent", "init", e);
+ }
+ }
+ }
+
/**
* Calling this will cause enabled() to be updated to match that set on the native side.
* The native library must be loaded before calling this method.
@@ -47,11 +73,22 @@ public class TraceEvent {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
try {
Class<?> traceClass = Class.forName("android.os.Trace");
- Method m = traceClass.getDeclaredMethod("isTagEnabled", Long.TYPE);
- Field f = traceClass.getField("TRACE_TAG_VIEW");
- boolean atraceEnabled = (Boolean) m.invoke(traceClass, f.getLong(null));
- if (atraceEnabled) nativeInitATrace();
- enabled = enabled || atraceEnabled;
+ long traceTagView = traceClass.getField("TRACE_TAG_VIEW").getLong(null);
+ String propertyTraceTagEnableFlags = (String) traceClass.getField(
+ "PROPERTY_TRACE_TAG_ENABLEFLAGS").get(null);
+
+ Class<?> systemPropertiesClass = Class.forName("android.os.SystemProperties");
+ Method systemPropertiesGetLongMethod = systemPropertiesClass.getDeclaredMethod(
+ "getLong", String.class, Long.TYPE);
+ long enabledFlags = (Long) systemPropertiesGetLongMethod.invoke(
+ null, propertyTraceTagEnableFlags, 0);
+ Log.d("TraceEvent", "New enabled flags: " + enabledFlags);
+ if ((enabledFlags & traceTagView) != 0) {
+ nativeStartATrace();
+ enabled = true;
+ } else {
+ nativeStopATrace();
+ }
} catch (ClassNotFoundException e) {
Log.e("TraceEvent", "setEnabledToMatchNative", e);
} catch (NoSuchMethodException e) {
@@ -236,7 +273,8 @@ public class TraceEvent {
}
private static native boolean nativeTraceEnabled();
- private static native void nativeInitATrace();
+ private static native void nativeStartATrace();
+ private static native void nativeStopATrace();
private static native void nativeInstant(String name, String arg);
private static native void nativeBegin(String name, String arg);
private static native void nativeEnd(String name, String arg);