| 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 "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/public/browser/tracing_controller.h" | 12 #include "content/public/browser/tracing_controller.h" |
| 13 #include "jni/TracingControllerAndroid_jni.h" | 13 #include "jni/TracingControllerAndroid_jni.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 17 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); | 18 TracingControllerAndroid* profiler = new TracingControllerAndroid(env, obj); |
| 19 return reinterpret_cast<intptr_t>(profiler); | 19 return reinterpret_cast<intptr_t>(profiler); |
| 20 } | 20 } |
| 21 | 21 |
| 22 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) | 22 TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj) |
| 23 : weak_java_object_(env, obj), | 23 : weak_java_object_(env, obj), |
| 24 weak_factory_(this) {} | 24 weak_factory_(this) {} |
| 25 | 25 |
| 26 TracingControllerAndroid::~TracingControllerAndroid() {} | 26 TracingControllerAndroid::~TracingControllerAndroid() {} |
| 27 | 27 |
| 28 void TracingControllerAndroid::Destroy(JNIEnv* env, jobject obj) { | 28 void TracingControllerAndroid::Destroy(JNIEnv* env, |
| 29 const JavaParamRef<jobject>& obj) { |
| 29 delete this; | 30 delete this; |
| 30 } | 31 } |
| 31 | 32 |
| 32 bool TracingControllerAndroid::StartTracing(JNIEnv* env, | 33 bool TracingControllerAndroid::StartTracing( |
| 33 jobject obj, | 34 JNIEnv* env, |
| 34 jstring jcategories, | 35 const JavaParamRef<jobject>& obj, |
| 35 jstring jtraceoptions) { | 36 const JavaParamRef<jstring>& jcategories, |
| 37 const JavaParamRef<jstring>& jtraceoptions) { |
| 36 std::string categories = | 38 std::string categories = |
| 37 base::android::ConvertJavaStringToUTF8(env, jcategories); | 39 base::android::ConvertJavaStringToUTF8(env, jcategories); |
| 38 std::string options = | 40 std::string options = |
| 39 base::android::ConvertJavaStringToUTF8(env, jtraceoptions); | 41 base::android::ConvertJavaStringToUTF8(env, jtraceoptions); |
| 40 | 42 |
| 41 // This log is required by adb_profile_chrome.py. | 43 // This log is required by adb_profile_chrome.py. |
| 42 LOG(WARNING) << "Logging performance trace to file"; | 44 LOG(WARNING) << "Logging performance trace to file"; |
| 43 | 45 |
| 44 return TracingController::GetInstance()->StartTracing( | 46 return TracingController::GetInstance()->StartTracing( |
| 45 base::trace_event::TraceConfig(categories, options), | 47 base::trace_event::TraceConfig(categories, options), |
| 46 TracingController::StartTracingDoneCallback()); | 48 TracingController::StartTracingDoneCallback()); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void TracingControllerAndroid::StopTracing(JNIEnv* env, | 51 void TracingControllerAndroid::StopTracing( |
| 50 jobject obj, | 52 JNIEnv* env, |
| 51 jstring jfilepath) { | 53 const JavaParamRef<jobject>& obj, |
| 54 const JavaParamRef<jstring>& jfilepath) { |
| 52 base::FilePath file_path( | 55 base::FilePath file_path( |
| 53 base::android::ConvertJavaStringToUTF8(env, jfilepath)); | 56 base::android::ConvertJavaStringToUTF8(env, jfilepath)); |
| 54 if (!TracingController::GetInstance()->StopTracing( | 57 if (!TracingController::GetInstance()->StopTracing( |
| 55 TracingController::CreateFileSink( | 58 TracingController::CreateFileSink( |
| 56 file_path, | 59 file_path, |
| 57 base::Bind(&TracingControllerAndroid::OnTracingStopped, | 60 base::Bind(&TracingControllerAndroid::OnTracingStopped, |
| 58 weak_factory_.GetWeakPtr())))) { | 61 weak_factory_.GetWeakPtr())))) { |
| 59 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; | 62 LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; |
| 60 OnTracingStopped(); | 63 OnTracingStopped(); |
| 61 } | 64 } |
| 62 } | 65 } |
| 63 | 66 |
| 64 void TracingControllerAndroid::GenerateTracingFilePath( | 67 void TracingControllerAndroid::GenerateTracingFilePath( |
| 65 base::FilePath* file_path) { | 68 base::FilePath* file_path) { |
| 66 JNIEnv* env = base::android::AttachCurrentThread(); | 69 JNIEnv* env = base::android::AttachCurrentThread(); |
| 67 ScopedJavaLocalRef<jstring> jfilename = | 70 ScopedJavaLocalRef<jstring> jfilename = |
| 68 Java_TracingControllerAndroid_generateTracingFilePath(env); | 71 Java_TracingControllerAndroid_generateTracingFilePath(env); |
| 69 *file_path = base::FilePath( | 72 *file_path = base::FilePath( |
| 70 base::android::ConvertJavaStringToUTF8(env, jfilename.obj())); | 73 base::android::ConvertJavaStringToUTF8(env, jfilename.obj())); |
| 71 } | 74 } |
| 72 | 75 |
| 73 void TracingControllerAndroid::OnTracingStopped() { | 76 void TracingControllerAndroid::OnTracingStopped() { |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | 77 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); | 78 base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env); |
| 76 if (obj.obj()) | 79 if (obj.obj()) |
| 77 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); | 80 Java_TracingControllerAndroid_onTracingStopped(env, obj.obj()); |
| 78 } | 81 } |
| 79 | 82 |
| 80 bool TracingControllerAndroid::GetKnownCategoryGroupsAsync(JNIEnv* env, | 83 bool TracingControllerAndroid::GetKnownCategoryGroupsAsync( |
| 81 jobject obj) { | 84 JNIEnv* env, |
| 85 const JavaParamRef<jobject>& obj) { |
| 82 if (!TracingController::GetInstance()->GetCategories( | 86 if (!TracingController::GetInstance()->GetCategories( |
| 83 base::Bind(&TracingControllerAndroid::OnKnownCategoriesReceived, | 87 base::Bind(&TracingControllerAndroid::OnKnownCategoriesReceived, |
| 84 weak_factory_.GetWeakPtr()))) { | 88 weak_factory_.GetWeakPtr()))) { |
| 85 return false; | 89 return false; |
| 86 } | 90 } |
| 87 return true; | 91 return true; |
| 88 } | 92 } |
| 89 | 93 |
| 90 void TracingControllerAndroid::OnKnownCategoriesReceived( | 94 void TracingControllerAndroid::OnKnownCategoriesReceived( |
| 91 const std::set<std::string>& categories_received) { | 95 const std::set<std::string>& categories_received) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 base::trace_event::TraceConfig trace_config; | 112 base::trace_event::TraceConfig trace_config; |
| 109 return base::android::ConvertUTF8ToJavaString( | 113 return base::android::ConvertUTF8ToJavaString( |
| 110 env, trace_config.ToCategoryFilterString()); | 114 env, trace_config.ToCategoryFilterString()); |
| 111 } | 115 } |
| 112 | 116 |
| 113 bool RegisterTracingControllerAndroid(JNIEnv* env) { | 117 bool RegisterTracingControllerAndroid(JNIEnv* env) { |
| 114 return RegisterNativesImpl(env); | 118 return RegisterNativesImpl(env); |
| 115 } | 119 } |
| 116 | 120 |
| 117 } // namespace content | 121 } // namespace content |
| OLD | NEW |