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

Unified Diff: content/browser/android/tracing_controller_android.cc

Issue 874543003: Add support for TraceEvent before the native library is loaded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/android/tracing_controller_android.cc
diff --git a/content/browser/android/tracing_controller_android.cc b/content/browser/android/tracing_controller_android.cc
index bd11672f58a8c2aea294d6f08d72afbf64815b98..311f83fc4badecc9520dfe0c832b0caf0d7ff6a7 100644
--- a/content/browser/android/tracing_controller_android.cc
+++ b/content/browser/android/tracing_controller_android.cc
@@ -4,15 +4,66 @@
#include "content/browser/android/tracing_controller_android.h"
+#include <vector>
+
+#include "base/android/early_trace_event.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
+#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/tracing_controller.h"
#include "jni/TracingControllerAndroid_jni.h"
+using base::debug::TraceLog;
dsinclair 2015/02/09 21:11:20 I believe this has now changed to be base::trace_e
Benoit L 2015/02/10 15:31:35 Done.
+
namespace content {
+namespace {
+
+const char kCategoryGroup[] = "Java";
+
+// Adds the early Java trace events (i.e. before the native library was called)
+// to the TraceEvent log before the data gets written to disk.
+void OnDisableRecording(TraceLog* trace_log) {
+ const unsigned char* const category_group_enabled =
+ TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(kCategoryGroup);
+
+ TraceLog::GetInstance()->SetEnabled(
dsinclair 2015/02/09 21:11:20 Why force the log to be enabled, is there a check
Benoit L 2015/02/10 15:31:35 Yes, precisely, otherwise the AddTraceEventWithThr
+ base::debug::CategoryFilter(kCategoryGroup), TraceLog::RECORDING_MODE,
+ base::debug::TraceOptions());
+
+ std::vector<base::android::EarlyTraceEvent> trace_events;
+ base::android::GetAllEarlyTraceEvents(&trace_events);
+
+ for (std::vector<base::android::EarlyTraceEvent>::const_iterator it =
+ trace_events.begin();
+ it != trace_events.end(); ++it) {
+ const base::android::EarlyTraceEvent& trace_event = *it;
+ const struct {
+ const char phase;
+ const base::TimeTicks timestamp;
+ const base::TimeTicks thread_time;
+ } phases[] = {
+ { TRACE_EVENT_PHASE_BEGIN, trace_event.begin_timestamp,
+ trace_event.begin_thread_time },
+ { TRACE_EVENT_PHASE_END, trace_event.end_timestamp,
+ trace_event.end_thread_time },
+ };
+
+ for (size_t i = 0; i < sizeof(phases) / sizeof(phases[0]); ++i) {
+ trace_log->AddTraceEventWithThreadIdAndTimestamp(
+ phases[i].phase, category_group_enabled, trace_event.name.c_str(),
+ trace_event_internal::kNoEventId,
+ trace_event.thread_id, phases[i].timestamp, phases[i].thread_time,
+ 0, NULL, NULL, NULL, NULL, TRACE_EVENT_FLAG_COPY);
+ }
+ }
+
+ TraceLog::GetInstance()->SetDisabled();
+}
+
+} // namespace
static jlong Init(JNIEnv* env, jobject obj) {
TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj);
@@ -29,6 +80,11 @@ void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) {
delete this;
}
+void TracingControllerAndroid::SetupEarlyJavaTracing() {
+ TracingControllerImpl::GetInstance()->SetDisableRecordingCallback(
+ base::Bind(&OnDisableRecording));
+}
+
bool TracingControllerAndroid::StartTracing(JNIEnv* env,
jobject obj,
jstring jcategories,

Powered by Google App Engine
This is Rietveld 408576698