| 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 6953a0de5f85015cb0334cb5d0287a3ba9031130..610981dcf2f9110f73f96f8aa12038a917bd7e50 100644
|
| --- a/content/browser/android/tracing_controller_android.cc
|
| +++ b/content/browser/android/tracing_controller_android.cc
|
| @@ -4,15 +4,71 @@
|
|
|
| #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::trace_event::TraceLog;
|
| +
|
| namespace content {
|
| +namespace {
|
| +
|
| +const char kCategoryGroup[] = "EarlyJava";
|
| +
|
| +// 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) {
|
| + std::vector<base::android::EarlyTraceEvent> trace_events;
|
| + base::android::GetAllEarlyTraceEvents(&trace_events);
|
| +
|
| + // Enables the tracing recording only for the specific "EarlyJava" category
|
| + // just for the duration of the dump. Otherwise, the events are dropped in the
|
| + // AddTraceEventWithThreadIdAndTimestamp call chain. Note that since this
|
| + // category is not used elsewhere, there is no race condition here.
|
| + TraceLog::GetInstance()->SetEnabled(
|
| + base::trace_event::CategoryFilter(kCategoryGroup),
|
| + TraceLog::RECORDING_MODE, base::trace_event::TraceOptions());
|
| +
|
| + const unsigned char* const category_group_enabled =
|
| + TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(kCategoryGroup);
|
| +
|
| + 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 | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP);
|
| + }
|
| + }
|
| +
|
| + TraceLog::GetInstance()->SetDisabled();
|
| +}
|
| +
|
| +} // namespace
|
|
|
| static jlong Init(JNIEnv* env, jobject obj) {
|
| TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj);
|
| @@ -29,6 +85,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,
|
|
|