OLD | NEW |
---|---|
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::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.
| |
20 | |
15 namespace content { | 21 namespace content { |
22 namespace { | |
23 | |
24 const char kCategoryGroup[] = "Java"; | |
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 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
| |
33 base::debug::CategoryFilter(kCategoryGroup), TraceLog::RECORDING_MODE, | |
34 base::debug::TraceOptions()); | |
35 | |
36 std::vector<base::android::EarlyTraceEvent> trace_events; | |
37 base::android::GetAllEarlyTraceEvents(&trace_events); | |
38 | |
39 for (std::vector<base::android::EarlyTraceEvent>::const_iterator it = | |
40 trace_events.begin(); | |
41 it != trace_events.end(); ++it) { | |
42 const base::android::EarlyTraceEvent& trace_event = *it; | |
43 const struct { | |
44 const char phase; | |
45 const base::TimeTicks timestamp; | |
46 const base::TimeTicks thread_time; | |
47 } phases[] = { | |
48 { TRACE_EVENT_PHASE_BEGIN, trace_event.begin_timestamp, | |
49 trace_event.begin_thread_time }, | |
50 { TRACE_EVENT_PHASE_END, trace_event.end_timestamp, | |
51 trace_event.end_thread_time }, | |
52 }; | |
53 | |
54 for (size_t i = 0; i < sizeof(phases) / sizeof(phases[0]); ++i) { | |
55 trace_log->AddTraceEventWithThreadIdAndTimestamp( | |
56 phases[i].phase, category_group_enabled, trace_event.name.c_str(), | |
57 trace_event_internal::kNoEventId, | |
58 trace_event.thread_id, phases[i].timestamp, phases[i].thread_time, | |
59 0, NULL, NULL, NULL, NULL, TRACE_EVENT_FLAG_COPY); | |
60 } | |
61 } | |
62 | |
63 TraceLog::GetInstance()->SetDisabled(); | |
64 } | |
65 | |
66 } // namespace | |
16 | 67 |
17 static jlong Init(JNIEnv* env, jobject obj) { | 68 static jlong Init(JNIEnv* env, jobject obj) { |
18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); | 69 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); |
19 return reinterpret_cast<intptr_t>(profiler); | 70 return reinterpret_cast<intptr_t>(profiler); |
20 } | 71 } |
21 | 72 |
22 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) | 73 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) |
23 : weak_java_object_(env, obj), | 74 : weak_java_object_(env, obj), |
24 weak_factory_(this) {} | 75 weak_factory_(this) {} |
25 | 76 |
26 TracingControllerAndroid::~TracingControllerAndroid() {} | 77 TracingControllerAndroid::~TracingControllerAndroid() {} |
27 | 78 |
28 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) { | 79 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) { |
29 delete this; | 80 delete this; |
30 } | 81 } |
31 | 82 |
83 void TracingControllerAndroid::SetupEarlyJavaTracing() { | |
84 TracingControllerImpl::GetInstance()->SetDisableRecordingCallback( | |
85 base::Bind(&OnDisableRecording)); | |
86 } | |
87 | |
32 bool TracingControllerAndroid::StartTracing(JNIEnv* env, | 88 bool TracingControllerAndroid::StartTracing(JNIEnv* env, |
33 jobject obj, | 89 jobject obj, |
34 jstring jcategories, | 90 jstring jcategories, |
35 jstring jtraceoptions) { | 91 jstring jtraceoptions) { |
36 std::string categories = | 92 std::string categories = |
37 base::android::ConvertJavaStringToUTF8(env, jcategories); | 93 base::android::ConvertJavaStringToUTF8(env, jcategories); |
38 base::debug::TraceOptions trace_options; | 94 base::debug::TraceOptions trace_options; |
39 trace_options.SetFromString( | 95 trace_options.SetFromString( |
40 base::android::ConvertJavaStringToUTF8(env, jtraceoptions)); | 96 base::android::ConvertJavaStringToUTF8(env, jtraceoptions)); |
41 | 97 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { | 163 static jstring GetDefaultCategories(JNIEnv* env, jobject obj) { |
108 return base::android::ConvertUTF8ToJavaString(env, | 164 return base::android::ConvertUTF8ToJavaString(env, |
109 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); | 165 base::debug::CategoryFilter::kDefaultCategoryFilterString).Release(); |
110 } | 166 } |
111 | 167 |
112 bool RegisterTracingControllerAndroid(JNIEnv* env) { | 168 bool RegisterTracingControllerAndroid(JNIEnv* env) { |
113 return RegisterNativesImpl(env); | 169 return RegisterNativesImpl(env); |
114 } | 170 } |
115 | 171 |
116 } // namespace content | 172 } // namespace content |
OLD | NEW |