Chromium Code Reviews| 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..14f7c4b49123fd5f42fe0fe220d8a648007fda89 100644 |
| --- a/content/browser/android/tracing_controller_android.cc |
| +++ b/content/browser/android/tracing_controller_android.cc |
| @@ -4,15 +4,74 @@ |
| #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) { |
| + const unsigned char* const category_group_enabled = |
| + TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(kCategoryGroup); |
| + |
| + 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()); |
| + |
| + 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) { |
| + // Overhead reporting is disabled, as the events are added later than they |
| + // occur. With overhead reporting, the overhead would have an |
| + // unrealistic and very high value. |
| + trace_log->AddTraceEventWithThreadIdAndTimestamp( |
| + phases[i].phase, category_group_enabled, trace_event.name.c_str(), |
|
dsinclair
2015/03/16 14:41:23
All of these are going to end up with the category
Benoit L
2015/03/19 16:50:47
I think that EarlyJava is fine. I have added a com
|
| + 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 +88,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, |