From 6174a36970df96acaa6a4bc00bb46727ddb6e7a7 Mon Sep 17 00:00:00 2001 From: "wangxianzhu@chromium.org" Date: Tue, 3 Dec 2013 19:48:19 +0000 Subject: Reapply "Remove TraceController" This reverts https://codereview.chromium.org/101543004/ which was created when suspected the reason of failure of telemetry tests, but turned out not the real reason. Reapply. Reapply the following change: > Revert "Revert 237280 "Remove TraceController"" > > This reverts commit 6aa58b8599840160df945afa89e7482d14d1c4d4. > > Fixed double-close issue when ending recording. > > > Revert 237280 "Remove TraceController" > > > > Seems to have broken trace-based telemetry benchmarks on android. > > > > BUG=323749 > > > > > Remove TraceController > > > > > > TraceController is obsoleted by TracingController. > > > Changed all remaining clients to use TracingController. > > > > > > BUG=none > > > > > > Review URL: https://codereview.chromium.org/67683003 > > > > TBR=wangxianzhu@chromium.org > > > > Review URL: https://codereview.chromium.org/89753004 > > > > git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237452 0039d316-1c4b-4281-b951-d872f2087c98 > > TBR=wangxianzhu@chromium.org > > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=238234 TBR= Review URL: https://codereview.chromium.org/102003003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238442 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/android/tracing_controller_android.cc | 67 +++++++--------------- .../browser/android/tracing_controller_android.h | 10 ++-- 2 files changed, 26 insertions(+), 51 deletions(-) (limited to 'content/browser/android') diff --git a/content/browser/android/tracing_controller_android.cc b/content/browser/android/tracing_controller_android.cc index 42d147e..75ac6d7 100644 --- a/content/browser/android/tracing_controller_android.cc +++ b/content/browser/android/tracing_controller_android.cc @@ -6,12 +6,9 @@ #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/browser/tracing/trace_subscriber_stdio.h" -#include "content/public/browser/trace_controller.h" +#include "content/public/browser/tracing_controller.h" #include "jni/TracingControllerAndroid_jni.h" namespace content { @@ -21,29 +18,9 @@ static jlong Init(JNIEnv* env, jobject obj) { return reinterpret_cast(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_java_object_(env, obj), + weak_factory_(this) {} TracingControllerAndroid::~TracingControllerAndroid() {} @@ -56,39 +33,37 @@ bool TracingControllerAndroid::StartTracing(JNIEnv* env, jstring jfilename, jstring jcategories, jboolean record_continuously) { - if (subscriber_.get()) { - return false; - } - std::string filename = base::android::ConvertJavaStringToUTF8(env, jfilename); + file_path_ = base::FilePath( + base::android::ConvertJavaStringToUTF8(env, jfilename)); std::string categories = base::android::ConvertJavaStringToUTF8(env, jcategories); - subscriber_.reset(new Subscriber(this, base::FilePath(filename))); - return TraceController::GetInstance()->BeginTracing( - subscriber_.get(), + + // This log is required by adb_profile_chrome.py. + LOG(WARNING) << "Logging performance trace to file: " << file_path_.value(); + + return TracingController::GetInstance()->EnableRecording( categories, - record_continuously ? base::debug::TraceLog::RECORD_CONTINUOUSLY - : base::debug::TraceLog::RECORD_UNTIL_FULL); + record_continuously ? TracingController::RECORD_CONTINUOUSLY + : TracingController::DEFAULT_OPTIONS, + TracingController::EnableRecordingDoneCallback()); } void TracingControllerAndroid::StopTracing(JNIEnv* env, jobject obj) { - if (!subscriber_.get()) { - return; - } - TraceController* controller = TraceController::GetInstance(); - if (!controller->EndTracingAsync(subscriber_.get())) { + if (!TracingController::GetInstance()->DisableRecording( + file_path_, + base::Bind(&TracingControllerAndroid::OnTracingStopped, + weak_factory_.GetWeakPtr()))) { LOG(ERROR) << "EndTracingAsync failed, forcing an immediate stop"; - controller->CancelSubscriber(subscriber_.get()); - OnTracingStopped(); + OnTracingStopped(file_path_); } } -void TracingControllerAndroid::OnTracingStopped() { +void TracingControllerAndroid::OnTracingStopped( + const base::FilePath& file_path) { JNIEnv* env = base::android::AttachCurrentThread(); base::android::ScopedJavaLocalRef 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) { diff --git a/content/browser/android/tracing_controller_android.h b/content/browser/android/tracing_controller_android.h index 0cd310e..4d70e7b 100644 --- a/content/browser/android/tracing_controller_android.h +++ b/content/browser/android/tracing_controller_android.h @@ -6,7 +6,8 @@ #define CONTENT_BROWSER_ANDROID_TRACING_CONTROLLER_ANDROID_H_ #include "base/android/jni_helper.h" -#include "base/memory/scoped_ptr.h" +#include "base/files/file_path.h" +#include "base/memory/weak_ptr.h" namespace content { @@ -25,12 +26,11 @@ class TracingControllerAndroid { private: ~TracingControllerAndroid(); - void OnTracingStopped(); + void OnTracingStopped(const base::FilePath& file_path); JavaObjectWeakGlobalRef weak_java_object_; - - class Subscriber; - scoped_ptr subscriber_; + base::FilePath file_path_; + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(TracingControllerAndroid); }; -- cgit v1.1