diff options
author | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 19:48:19 +0000 |
---|---|---|
committer | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-03 19:48:19 +0000 |
commit | 6174a36970df96acaa6a4bc00bb46727ddb6e7a7 (patch) | |
tree | fd540c556137ed279c13ddabe8ac3f0ed0fb3697 /chrome/test/base | |
parent | 6a3ad06b4dc301ff395a13605e7ab7439d9680d4 (diff) | |
download | chromium_src-6174a36970df96acaa6a4bc00bb46727ddb6e7a7.zip chromium_src-6174a36970df96acaa6a4bc00bb46727ddb6e7a7.tar.gz chromium_src-6174a36970df96acaa6a4bc00bb46727ddb6e7a7.tar.bz2 |
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
Diffstat (limited to 'chrome/test/base')
-rw-r--r-- | chrome/test/base/tracing.cc | 80 |
1 files changed, 50 insertions, 30 deletions
diff --git a/chrome/test/base/tracing.cc b/chrome/test/base/tracing.cc index 7060b9b..5aa07e7 100644 --- a/chrome/test/base/tracing.cc +++ b/chrome/test/base/tracing.cc @@ -4,19 +4,21 @@ #include "chrome/test/base/tracing.h" -#include "base/debug/trace_event.h" +#include "base/file_util.h" +#include "base/files/file_path.h" #include "base/memory/singleton.h" #include "base/message_loop/message_loop.h" +#include "base/strings/string_util.h" +#include "base/timer/timer.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/trace_controller.h" -#include "content/public/browser/trace_subscriber.h" +#include "content/public/browser/tracing_controller.h" #include "content/public/test/test_utils.h" namespace { using content::BrowserThread; -class InProcessTraceController : public content::TraceSubscriber { +class InProcessTraceController { public: static InProcessTraceController* GetInstance() { return Singleton<InProcessTraceController>::get(); @@ -29,8 +31,10 @@ class InProcessTraceController : public content::TraceSubscriber { bool BeginTracing(const std::string& category_patterns) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - return content::TraceController::GetInstance()->BeginTracing( - this, category_patterns, base::debug::TraceLog::RECORD_UNTIL_FULL); + return content::TracingController::GetInstance()->EnableRecording( + category_patterns, content::TracingController::DEFAULT_OPTIONS, + content::TracingController::EnableRecordingDoneCallback()); + return true; } bool BeginTracingWithWatch(const std::string& category_patterns, @@ -40,9 +44,11 @@ class InProcessTraceController : public content::TraceSubscriber { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(num_occurrences > 0); watch_notification_count_ = num_occurrences; - return BeginTracing(category_patterns) && - content::TraceController::GetInstance()->SetWatchEvent( - this, category_name, event_name); + return content::TracingController::GetInstance()->SetWatchEvent( + category_name, event_name, + base::Bind(&InProcessTraceController::OnWatchEventMatched, + base::Unretained(this))) && + BeginTracing(category_patterns); } bool WaitForWatchEvent(base::TimeDelta timeout) { @@ -67,20 +73,16 @@ class InProcessTraceController : public content::TraceSubscriber { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); using namespace base::debug; - TraceResultBuffer::SimpleOutput output; - trace_buffer_.SetOutputCallback(output.GetCallback()); - - trace_buffer_.Start(); - if (!content::TraceController::GetInstance()->EndTracingAsync(this)) + if (!content::TracingController::GetInstance()->DisableRecording( + base::FilePath(), + base::Bind(&InProcessTraceController::OnTraceDataCollected, + base::Unretained(this), + base::Unretained(json_trace_output)))) return false; + // Wait for OnEndTracingComplete() to quit the message loop. - // OnTraceDataCollected may be called multiple times while blocking here. message_loop_runner_ = new content::MessageLoopRunner; message_loop_runner_->Run(); - trace_buffer_.Finish(); - trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback()); - - *json_trace_output = output.json_output; // Watch notifications can occur during this method's message loop run, but // not after, so clear them here. @@ -91,19 +93,40 @@ class InProcessTraceController : public content::TraceSubscriber { private: friend struct DefaultSingletonTraits<InProcessTraceController>; - // TraceSubscriber implementation - virtual void OnEndTracingComplete() OVERRIDE { + void OnEndTracingComplete() { message_loop_runner_->Quit(); } - // TraceSubscriber implementation - virtual void OnTraceDataCollected( - const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE { - trace_buffer_.AddFragment(trace_fragment->data()); + void OnTraceDataCollected(std::string* json_trace_output, + const base::FilePath& path) { + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, + base::Bind(&InProcessTraceController::ReadTraceData, + base::Unretained(this), + base::Unretained(json_trace_output), + path)); } - // TraceSubscriber implementation - virtual void OnEventWatchNotification() OVERRIDE { + void ReadTraceData(std::string* json_trace_output, + const base::FilePath& path) { + json_trace_output->clear(); + bool ok = base::ReadFileToString(path, json_trace_output); + DCHECK(ok); + base::DeleteFile(path, false); + + // The callers expect an array of trace events. + const char* preamble = "{\"traceEvents\": "; + const char* trailout = "}"; + DCHECK(StartsWithASCII(*json_trace_output, preamble, true)); + DCHECK(EndsWith(*json_trace_output, trailout, true)); + json_trace_output->erase(0, strlen(preamble)); + json_trace_output->erase(json_trace_output->end() - 1); + + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::Bind(&InProcessTraceController::OnEndTracingComplete, + base::Unretained(this))); + } + + void OnWatchEventMatched() { if (watch_notification_count_ == 0) return; if (--watch_notification_count_ == 0) { @@ -118,9 +141,6 @@ class InProcessTraceController : public content::TraceSubscriber { message_loop_runner_->Quit(); } - // For collecting trace data asynchronously. - base::debug::TraceResultBuffer trace_buffer_; - scoped_refptr<content::MessageLoopRunner> message_loop_runner_; base::OneShotTimer<InProcessTraceController> timer_; |