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
3 // found in the LICENSE file.
5 #include "content/browser/android/tracing_controller_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/debug/trace_event.h"
10 #include "base/logging.h"
11 #include "content/public/browser/tracing_controller.h"
12 #include "jni/TracingControllerAndroid_jni.h"
16 static jlong
Init(JNIEnv
* env
, jobject obj
) {
17 TracingControllerAndroid
* profiler
= new TracingControllerAndroid(env
, obj
);
18 return reinterpret_cast<intptr_t>(profiler
);
21 TracingControllerAndroid::TracingControllerAndroid(JNIEnv
* env
, jobject obj
)
22 : weak_java_object_(env
, obj
),
23 weak_factory_(this) {}
25 TracingControllerAndroid::~TracingControllerAndroid() {}
27 void TracingControllerAndroid::Destroy(JNIEnv
* env
, jobject obj
) {
31 bool TracingControllerAndroid::StartTracing(JNIEnv
* env
,
35 jboolean record_continuously
) {
36 file_path_
= base::FilePath(
37 base::android::ConvertJavaStringToUTF8(env
, jfilename
));
38 std::string categories
=
39 base::android::ConvertJavaStringToUTF8(env
, jcategories
);
41 // This log is required by adb_profile_chrome.py.
42 LOG(WARNING
) << "Logging performance trace to file: " << file_path_
.value();
44 return TracingController::GetInstance()->EnableRecording(
46 record_continuously
? TracingController::RECORD_CONTINUOUSLY
47 : TracingController::DEFAULT_OPTIONS
,
48 TracingController::EnableRecordingDoneCallback());
51 void TracingControllerAndroid::StopTracing(JNIEnv
* env
, jobject obj
) {
52 if (!TracingController::GetInstance()->DisableRecording(
54 base::Bind(&TracingControllerAndroid::OnTracingStopped
,
55 weak_factory_
.GetWeakPtr()))) {
56 LOG(ERROR
) << "EndTracingAsync failed, forcing an immediate stop";
57 OnTracingStopped(file_path_
);
61 void TracingControllerAndroid::OnTracingStopped(
62 const base::FilePath
& file_path
) {
63 JNIEnv
* env
= base::android::AttachCurrentThread();
64 base::android::ScopedJavaLocalRef
<jobject
> obj
= weak_java_object_
.get(env
);
66 Java_TracingControllerAndroid_onTracingStopped(env
, obj
.obj());
69 static jstring
GetDefaultCategories(JNIEnv
* env
, jobject obj
) {
70 return base::android::ConvertUTF8ToJavaString(env
,
71 base::debug::CategoryFilter::kDefaultCategoryFilterString
).Release();
74 bool RegisterTracingControllerAndroid(JNIEnv
* env
) {
75 return RegisterNativesImpl(env
);
78 } // namespace content