Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: trunk/src/chrome/test/base/tracing.cc

Issue 89753004: Revert 237280 "Remove TraceController" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: trunk/src/chrome/test/base/tracing.cc
===================================================================
--- trunk/src/chrome/test/base/tracing.cc (revision 237451)
+++ trunk/src/chrome/test/base/tracing.cc (working copy)
@@ -4,21 +4,19 @@
#include "chrome/test/base/tracing.h"
-#include "base/file_util.h"
-#include "base/files/file_path.h"
+#include "base/debug/trace_event.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/tracing_controller.h"
+#include "content/public/browser/trace_controller.h"
+#include "content/public/browser/trace_subscriber.h"
#include "content/public/test/test_utils.h"
namespace {
using content::BrowserThread;
-class InProcessTraceController {
+class InProcessTraceController : public content::TraceSubscriber {
public:
static InProcessTraceController* GetInstance() {
return Singleton<InProcessTraceController>::get();
@@ -31,10 +29,8 @@
bool BeginTracing(const std::string& category_patterns) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return content::TracingController::GetInstance()->EnableRecording(
- category_patterns, content::TracingController::DEFAULT_OPTIONS,
- content::TracingController::EnableRecordingDoneCallback());
- return true;
+ return content::TraceController::GetInstance()->BeginTracing(
+ this, category_patterns, base::debug::TraceLog::RECORD_UNTIL_FULL);
}
bool BeginTracingWithWatch(const std::string& category_patterns,
@@ -44,11 +40,9 @@
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(num_occurrences > 0);
watch_notification_count_ = num_occurrences;
- return content::TracingController::GetInstance()->SetWatchEvent(
- category_name, event_name,
- base::Bind(&InProcessTraceController::OnWatchEventMatched,
- base::Unretained(this))) &&
- BeginTracing(category_patterns);
+ return BeginTracing(category_patterns) &&
+ content::TraceController::GetInstance()->SetWatchEvent(
+ this, category_name, event_name);
}
bool WaitForWatchEvent(base::TimeDelta timeout) {
@@ -73,17 +67,21 @@
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
using namespace base::debug;
- if (!content::TracingController::GetInstance()->DisableRecording(
- base::FilePath(),
- base::Bind(&InProcessTraceController::OnTraceDataCollected,
- base::Unretained(this),
- base::Unretained(json_trace_output))))
- return false;
+ TraceResultBuffer::SimpleOutput output;
+ trace_buffer_.SetOutputCallback(output.GetCallback());
+ trace_buffer_.Start();
+ if (!content::TraceController::GetInstance()->EndTracingAsync(this))
+ 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.
watch_notification_count_ = 0;
@@ -93,40 +91,19 @@
private:
friend struct DefaultSingletonTraits<InProcessTraceController>;
- void OnEndTracingComplete() {
+ // TraceSubscriber implementation
+ virtual void OnEndTracingComplete() OVERRIDE {
message_loop_runner_->Quit();
}
- 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 OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE {
+ trace_buffer_.AddFragment(trace_fragment->data());
}
- 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() {
+ // TraceSubscriber implementation
+ virtual void OnEventWatchNotification() OVERRIDE {
if (watch_notification_count_ == 0)
return;
if (--watch_notification_count_ == 0) {
@@ -141,6 +118,9 @@
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_;
« no previous file with comments | « trunk/src/chrome/test/automation/automation_proxy.cc ('k') | trunk/src/components/tracing/child_trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698