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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/debug/in_process_tracing.h ('k') | base/debug/trace_event_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/debug/in_process_tracing.h"
6 #include "base/debug/trace_event.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/singleton.h"
9
10 namespace {
11
12 class InProcessTraceController {
13 public:
14 static InProcessTraceController* GetInstance() {
15 return Singleton<InProcessTraceController>::get();
16 }
17
18 InProcessTraceController() {}
19 virtual ~InProcessTraceController() {}
20
21 bool BeginTracing(const std::string& category_patterns) {
22 base::debug::TraceLog::GetInstance()->SetEnabled(
23 base::debug::CategoryFilter(category_patterns),
24 base::debug::TraceLog::RECORD_UNTIL_FULL);
25 return true;
26 }
27
28 void OnTraceDataCollected(
29 const scoped_refptr<base::RefCountedString>& events_str,
30 bool has_more_events) {
31 trace_buffer_.AddFragment(events_str->data());
32 }
33
34 bool EndTracing(std::string* json_trace_output) {
35 using namespace base::debug;
36
37 base::debug::TraceLog::GetInstance()->SetDisabled();
38
39 TraceResultBuffer::SimpleOutput output;
40 trace_buffer_.SetOutputCallback(output.GetCallback());
41
42 trace_buffer_.Start();
43
44 base::debug::TraceLog::GetInstance()->Flush(
45 base::Bind(&InProcessTraceController::OnTraceDataCollected,
46 base::Unretained(this)));
47
48 trace_buffer_.Finish();
49 trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback());
50 *json_trace_output = output.json_output;
51 return true;
52 }
53
54 private:
55 friend struct DefaultSingletonTraits<InProcessTraceController>;
56
57 // For collecting trace data asynchronously.
58 base::debug::TraceResultBuffer trace_buffer_;
59
60 DISALLOW_COPY_AND_ASSIGN(InProcessTraceController);
61 };
62
63 } // namespace
64
65 namespace tracing {
66
67 bool BeginTracing(const std::string& category_patterns) {
68 return InProcessTraceController::GetInstance()->BeginTracing(
69 category_patterns);
70 }
71
72 bool EndTracing(std::string* json_trace_output) {
73 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output);
74 }
75
76 } // namespace tracing
OLDNEW
« 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