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

Side by Side 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: Rebase. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/browser/android/tracing_controller_android.h" 5 #include "content/browser/android/tracing_controller_android.h"
6 6
7 #include <vector>
8
9 #include "base/android/early_trace_event.h"
7 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
9 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
10 #include "base/logging.h" 13 #include "base/logging.h"
11 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "content/browser/tracing/tracing_controller_impl.h"
12 #include "content/public/browser/tracing_controller.h" 16 #include "content/public/browser/tracing_controller.h"
13 #include "jni/TracingControllerAndroid_jni.h" 17 #include "jni/TracingControllerAndroid_jni.h"
14 18
19 using base::trace_event::TraceLog;
20
15 namespace content { 21 namespace content {
22 namespace {
23
24 const char kCategoryGroup[] = "EarlyJava";
25
26 // Adds the early Java trace events (i.e. before the native library was called)
27 // to the TraceEvent log before the data gets written to disk.
28 void OnDisableRecording(TraceLog* trace_log) {
29 const unsigned char* const category_group_enabled =
30 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(kCategoryGroup);
31
32 std::vector<base::android::EarlyTraceEvent> trace_events;
33 base::android::GetAllEarlyTraceEvents(&trace_events);
34
35 // Enables the tracing recording only for the specific "EarlyJava" category
36 // just for the duration of the dump. Otherwise, the events are dropped in the
37 // AddTraceEventWithThreadIdAndTimestamp call chain. Note that since this
38 // category is not used elsewhere, there is no race condition here.
39 TraceLog::GetInstance()->SetEnabled(
40 base::trace_event::CategoryFilter(kCategoryGroup),
41 TraceLog::RECORDING_MODE, base::trace_event::TraceOptions());
42
43 for (std::vector<base::android::EarlyTraceEvent>::const_iterator it =
44 trace_events.begin();
45 it != trace_events.end(); ++it) {
46 const base::android::EarlyTraceEvent& trace_event = *it;
47 const struct {
48 const char phase;
49 const base::TimeTicks timestamp;
50 const base::TimeTicks thread_time;
51 } phases[] = {
52 {TRACE_EVENT_PHASE_BEGIN, trace_event.begin_timestamp,
53 trace_event.begin_thread_time},
54 {TRACE_EVENT_PHASE_END, trace_event.end_timestamp,
55 trace_event.end_thread_time},
56 };
57
58 for (size_t i = 0; i < sizeof(phases) / sizeof(phases[0]); ++i) {
59 // Overhead reporting is disabled, as the events are added later than they
60 // occur. With overhead reporting, the overhead would have an
61 // unrealistic and very high value.
62 trace_log->AddTraceEventWithThreadIdAndTimestamp(
63 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
64 trace_event_internal::kNoEventId,
65 trace_event.thread_id, phases[i].timestamp, phases[i].thread_time,
66 0, NULL, NULL, NULL, NULL,
67 TRACE_EVENT_FLAG_COPY | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP);
68 }
69 }
70
71 TraceLog::GetInstance()->SetDisabled();
72 }
73
74 } // namespace
16 75
17 static jlong Init(JNIEnv* env, jobject obj) { 76 static jlong Init(JNIEnv* env, jobject obj) {
18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); 77 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj);
19 return reinterpret_cast<intptr_t>(profiler); 78 return reinterpret_cast<intptr_t>(profiler);
20 } 79 }
21 80
22 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) 81 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj)
23 : weak_java_object_(env, obj), 82 : weak_java_object_(env, obj),
24 weak_factory_(this) {} 83 weak_factory_(this) {}
25 84
26 TracingControllerAndroid::~TracingControllerAndroid() {} 85 TracingControllerAndroid::~TracingControllerAndroid() {}
27 86
28 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) { 87 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) {
29 delete this; 88 delete this;
30 } 89 }
31 90
91 void TracingControllerAndroid::SetupEarlyJavaTracing() {
92 TracingControllerImpl::GetInstance()->SetDisableRecordingCallback(
93 base::Bind(&OnDisableRecording));
94 }
95
32 bool TracingControllerAndroid::StartTracing(JNIEnv* env, 96 bool TracingControllerAndroid::StartTracing(JNIEnv* env,
33 jobject obj, 97 jobject obj,
34 jstring jcategories, 98 jstring jcategories,
35 jstring jtraceoptions) { 99 jstring jtraceoptions) {
36 std::string categories = 100 std::string categories =
37 base::android::ConvertJavaStringToUTF8(env, jcategories); 101 base::android::ConvertJavaStringToUTF8(env, jcategories);
38 base::trace_event::TraceOptions trace_options; 102 base::trace_event::TraceOptions trace_options;
39 trace_options.SetFromString( 103 trace_options.SetFromString(
40 base::android::ConvertJavaStringToUTF8(env, jtraceoptions)); 104 base::android::ConvertJavaStringToUTF8(env, jtraceoptions));
41 105
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 env, 173 env,
110 base::trace_event::CategoryFilter::kDefaultCategoryFilterString) 174 base::trace_event::CategoryFilter::kDefaultCategoryFilterString)
111 .Release(); 175 .Release();
112 } 176 }
113 177
114 bool RegisterTracingControllerAndroid(JNIEnv* env) { 178 bool RegisterTracingControllerAndroid(JNIEnv* env) {
115 return RegisterNativesImpl(env); 179 return RegisterNativesImpl(env);
116 } 180 }
117 181
118 } // namespace content 182 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698