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

Unified Diff: base/debug/in_process_tracing.cc

Issue 67073002: DO NOT SUBMIT: In-process tracing for debugging tests Base URL: svn://svn.chromium.org/chrome/trunk/src
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
« no previous file with comments | « base/debug/in_process_tracing.h ('k') | base/debug/trace_event_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/in_process_tracing.cc
diff --git a/base/debug/in_process_tracing.cc b/base/debug/in_process_tracing.cc
new file mode 100644
index 0000000000000000000000000000000000000000..555a2b604100f6d5be3f944ab8767ea8e39d9f2c
--- /dev/null
+++ b/base/debug/in_process_tracing.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/debug/in_process_tracing.h"
+#include "base/debug/trace_event.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/singleton.h"
+
+namespace {
+
+class InProcessTraceController {
+ public:
+ static InProcessTraceController* GetInstance() {
+ return Singleton<InProcessTraceController>::get();
+ }
+
+ InProcessTraceController() {}
+ virtual ~InProcessTraceController() {}
+
+ bool BeginTracing(const std::string& category_patterns) {
+ base::debug::TraceLog::GetInstance()->SetEnabled(
+ base::debug::CategoryFilter(category_patterns),
+ base::debug::TraceLog::RECORD_UNTIL_FULL);
+ return true;
+ }
+
+ void OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& events_str,
+ bool has_more_events) {
+ trace_buffer_.AddFragment(events_str->data());
+ }
+
+ bool EndTracing(std::string* json_trace_output) {
+ using namespace base::debug;
+
+ base::debug::TraceLog::GetInstance()->SetDisabled();
+
+ TraceResultBuffer::SimpleOutput output;
+ trace_buffer_.SetOutputCallback(output.GetCallback());
+
+ trace_buffer_.Start();
+
+ base::debug::TraceLog::GetInstance()->Flush(
+ base::Bind(&InProcessTraceController::OnTraceDataCollected,
+ base::Unretained(this)));
+
+ trace_buffer_.Finish();
+ trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback());
+ *json_trace_output = output.json_output;
+ return true;
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<InProcessTraceController>;
+
+ // For collecting trace data asynchronously.
+ base::debug::TraceResultBuffer trace_buffer_;
+
+ DISALLOW_COPY_AND_ASSIGN(InProcessTraceController);
+};
+
+} // namespace
+
+namespace tracing {
+
+bool BeginTracing(const std::string& category_patterns) {
+ return InProcessTraceController::GetInstance()->BeginTracing(
+ category_patterns);
+}
+
+bool EndTracing(std::string* json_trace_output) {
+ return InProcessTraceController::GetInstance()->EndTracing(json_trace_output);
+}
+
+} // namespace tracing
« no previous file with comments | « base/debug/in_process_tracing.h ('k') | base/debug/trace_event_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698