| Index: trunk/src/content/browser/android/tracing_controller_android.cc
|
| ===================================================================
|
| --- trunk/src/content/browser/android/tracing_controller_android.cc (revision 237451)
|
| +++ trunk/src/content/browser/android/tracing_controller_android.cc (working copy)
|
| @@ -6,9 +6,12 @@
|
|
|
| #include "base/android/jni_android.h"
|
| #include "base/android/jni_string.h"
|
| +#include "base/command_line.h"
|
| #include "base/debug/trace_event.h"
|
| +#include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| -#include "content/public/browser/tracing_controller.h"
|
| +#include "content/browser/tracing/trace_subscriber_stdio.h"
|
| +#include "content/public/browser/trace_controller.h"
|
| #include "jni/TracingControllerAndroid_jni.h"
|
|
|
| namespace content {
|
| @@ -18,9 +21,29 @@
|
| return reinterpret_cast<intptr_t>(profiler);
|
| }
|
|
|
| +class TracingControllerAndroid::Subscriber
|
| + : public content::TraceSubscriberStdio {
|
| + public:
|
| + Subscriber(TracingControllerAndroid* profiler, const base::FilePath& path)
|
| + : TraceSubscriberStdio(path, FILE_TYPE_ARRAY, false),
|
| + profiler_(profiler) {}
|
| +
|
| + void set_profiler(TracingControllerAndroid* profiler) {
|
| + CHECK(!profiler_);
|
| + profiler_ = profiler;
|
| + }
|
| +
|
| + virtual void OnEndTracingComplete() OVERRIDE {
|
| + TraceSubscriberStdio::OnEndTracingComplete();
|
| + profiler_->OnTracingStopped();
|
| + }
|
| +
|
| + private:
|
| + TracingControllerAndroid* profiler_;
|
| +};
|
| +
|
| TracingControllerAndroid::TracingControllerAndroid(JNIEnv* env, jobject obj)
|
| - : weak_java_object_(env, obj),
|
| - weak_factory_(this) {}
|
| + : weak_java_object_(env, obj) {}
|
|
|
| TracingControllerAndroid::~TracingControllerAndroid() {}
|
|
|
| @@ -33,37 +56,39 @@
|
| jstring jfilename,
|
| jstring jcategories,
|
| jboolean record_continuously) {
|
| - file_path_ = base::FilePath(
|
| - base::android::ConvertJavaStringToUTF8(env, jfilename));
|
| + if (subscriber_.get()) {
|
| + return false;
|
| + }
|
| + std::string filename = base::android::ConvertJavaStringToUTF8(env, jfilename);
|
| std::string categories =
|
| base::android::ConvertJavaStringToUTF8(env, jcategories);
|
| -
|
| - // This log is required by adb_profile_chrome.py.
|
| - LOG(WARNING) << "Logging performance trace to file: " << file_path_.value();
|
| -
|
| - return TracingController::GetInstance()->EnableRecording(
|
| + subscriber_.reset(new Subscriber(this, base::FilePath(filename)));
|
| + return TraceController::GetInstance()->BeginTracing(
|
| + subscriber_.get(),
|
| categories,
|
| - record_continuously ? TracingController::RECORD_CONTINUOUSLY
|
| - : TracingController::DEFAULT_OPTIONS,
|
| - TracingController::EnableRecordingDoneCallback());
|
| + record_continuously ? base::debug::TraceLog::RECORD_CONTINUOUSLY
|
| + : base::debug::TraceLog::RECORD_UNTIL_FULL);
|
| }
|
|
|
| void TracingControllerAndroid::StopTracing(JNIEnv* env, jobject obj) {
|
| - if (!TracingController::GetInstance()->DisableRecording(
|
| - file_path_,
|
| - base::Bind(&TracingControllerAndroid::OnTracingStopped,
|
| - weak_factory_.GetWeakPtr()))) {
|
| + if (!subscriber_.get()) {
|
| + return;
|
| + }
|
| + TraceController* controller = TraceController::GetInstance();
|
| + if (!controller->EndTracingAsync(subscriber_.get())) {
|
| LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop";
|
| - OnTracingStopped(file_path_);
|
| + controller->CancelSubscriber(subscriber_.get());
|
| + OnTracingStopped();
|
| }
|
| }
|
|
|
| -void TracingControllerAndroid::OnTracingStopped(
|
| - const base::FilePath& file_path) {
|
| +void TracingControllerAndroid::OnTracingStopped() {
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
| base::android::ScopedJavaLocalRef<jobject> obj = weak_java_object_.get(env);
|
| - if (obj.obj())
|
| + if (obj.obj()) {
|
| Java_TracingControllerAndroid_onTracingStopped(env, obj.obj());
|
| + }
|
| + subscriber_.reset();
|
| }
|
|
|
| static jstring GetDefaultCategories(JNIEnv* env, jobject obj) {
|
|
|