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

Side by Side Diff: content/browser/trace_controller_impl.h

Issue 9694028: Add a Content API around TracingController. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix linux Created 8 years, 9 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_TRACE_CONTROLLER_H_ 5 #ifndef CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_
6 #define CONTENT_BROWSER_TRACE_CONTROLLER_H_ 6 #define CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/memory/ref_counted_memory.h"
14 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
15 #include "content/common/content_export.h" 14 #include "content/public/browser/trace_controller.h"
16 15
17 class CommandLine; 16 class CommandLine;
18 class TraceMessageFilter; 17 class TraceMessageFilter;
19 18
20 // Objects interested in receiving trace data derive from TraceSubscriber. 19 namespace content {
21 // See also: trace_message_filter.h 20
22 // See also: child_trace_message_filter.h 21 class TraceControllerImpl : public TraceController {
23 class CONTENT_EXPORT TraceSubscriber {
24 public: 22 public:
25 // Called once after TraceController::EndTracingAsync. 23 static TraceControllerImpl* GetInstance();
26 virtual void OnEndTracingComplete() = 0;
27 // Called 0 or more times between TraceController::BeginTracing and
28 // OnEndTracingComplete. Use base::debug::TraceResultBuffer to convert one or
29 // more trace fragments to JSON.
30 virtual void OnTraceDataCollected(
31 const scoped_refptr<base::RefCountedString>& trace_fragment) = 0;
32 // Called once after TraceController::GetKnownCategoriesAsync.
33 virtual void OnKnownCategoriesCollected(
34 const std::set<std::string>& known_categories);
35 virtual void OnTraceBufferPercentFullReply(float percent_full);
36
37 protected:
38 virtual ~TraceSubscriber();
39 };
40
41 // TraceController is used on the browser processes to enable/disable
42 // trace status and collect trace data. Only the browser UI thread is allowed
43 // to interact with the TraceController object. All calls on the TraceSubscriber
44 // happen on the UI thread.
45 class CONTENT_EXPORT TraceController {
46 public:
47 static TraceController* GetInstance();
48 24
49 // Called on the main thread of the browser process to initialize 25 // Called on the main thread of the browser process to initialize
50 // startup tracing. 26 // startup tracing.
51 void InitStartupTracing(const CommandLine& command_line); 27 void InitStartupTracing(const CommandLine& command_line);
52 28
53 // Get set of known categories. This can change as new code paths are reached. 29 // Get set of known categories. This can change as new code paths are reached.
54 // If true is returned, subscriber->OnKnownCategoriesCollected will be called 30 // If true is returned, subscriber->OnKnownCategoriesCollected will be called
55 // when once the categories are retrieved from child processes. 31 // when once the categories are retrieved from child processes.
56 bool GetKnownCategoriesAsync(TraceSubscriber* subscriber); 32 bool GetKnownCategoriesAsync(TraceSubscriber* subscriber);
57 33
58 // Called by browser process to start tracing events on all processes.
59 //
60 // Currently only one subscriber is allowed at a time.
61 // Tracing begins immediately locally, and asynchronously on child processes
62 // as soon as they receive the BeginTracing request.
63 // By default, all categories are traced except those matching "test_*".
64 //
65 // If BeginTracing was already called previously,
66 // or if an EndTracingAsync is pending,
67 // or if another subscriber is tracing,
68 // BeginTracing will return false meaning it failed.
69 bool BeginTracing(TraceSubscriber* subscriber);
70
71 // Same as above, but specifies which categories to trace. 34 // Same as above, but specifies which categories to trace.
72 // If both included_categories and excluded_categories are empty, 35 // If both included_categories and excluded_categories are empty,
73 // all categories are traced. 36 // all categories are traced.
74 // Else if included_categories is non-empty, only those are traced. 37 // Else if included_categories is non-empty, only those are traced.
75 // Else if excluded_categories is non-empty, everything but those are traced. 38 // Else if excluded_categories is non-empty, everything but those are traced.
76 bool BeginTracing(TraceSubscriber* subscriber, 39 bool BeginTracing(TraceSubscriber* subscriber,
77 const std::vector<std::string>& included_categories, 40 const std::vector<std::string>& included_categories,
78 const std::vector<std::string>& excluded_categories); 41 const std::vector<std::string>& excluded_categories);
79 42
80 // |categories| is a comma-delimited list of category wildcards. 43 // TraceController implementation:
81 // A category can have an optional '-' prefix to make it an excluded category. 44 virtual bool BeginTracing(TraceSubscriber* subscriber) OVERRIDE;
82 // All the same rules apply above, so for example, having both included and 45 virtual bool BeginTracing(TraceSubscriber* subscriber,
83 // excluded categories in the same list would not be supported. 46 const std::string& categories) OVERRIDE;
84 // 47 virtual bool EndTracingAsync(TraceSubscriber* subscriber) OVERRIDE;
85 // Example: BeginTracing("test_MyTest*"); 48 virtual bool GetTraceBufferPercentFullAsync(
86 // Example: BeginTracing("test_MyTest*,test_OtherStuff"); 49 TraceSubscriber* subscriber) OVERRIDE;
87 // Example: BeginTracing("-excluded_category1,-excluded_category2"); 50 virtual void CancelSubscriber(TraceSubscriber* subscriber) OVERRIDE;
88 bool BeginTracing(TraceSubscriber* subscriber, const std::string& categories);
89
90 // Called by browser process to stop tracing events on all processes.
91 //
92 // Child processes typically are caching trace data and only rarely flush
93 // and send trace data back to the browser process. That is because it may be
94 // an expensive operation to send the trace data over IPC, and we would like
95 // to avoid much runtime overhead of tracing. So, to end tracing, we must
96 // asynchronously ask all child processes to flush any pending trace data.
97 //
98 // Once all child processes have acked the EndTracing request,
99 // TraceSubscriber will be called with OnEndTracingComplete.
100 //
101 // If a previous call to EndTracingAsync is already pending,
102 // or if another subscriber is tracing,
103 // EndTracingAsync will return false meaning it failed.
104 bool EndTracingAsync(TraceSubscriber* subscriber);
105
106 // Get the maximum across processes of trace buffer percent full state.
107 // When the TraceBufferPercentFull value is determined,
108 // subscriber->OnTraceBufferPercentFullReply is called.
109 // When any child process reaches 100% full, the TraceController will end
110 // tracing, and call TraceSubscriber::OnEndTracingComplete.
111 // GetTraceBufferPercentFullAsync fails in the following conditions:
112 // trace is ending or disabled;
113 // a previous call to GetTraceBufferPercentFullAsync is pending; or
114 // the caller is not the current subscriber.
115 bool GetTraceBufferPercentFullAsync(TraceSubscriber* subscriber);
116
117 // Cancel the subscriber so that it will not be called when EndTracingAsync is
118 // acked by all child processes. This will also call EndTracingAsync
119 // internally if necessary.
120 // Safe to call even if caller is not the current subscriber.
121 void CancelSubscriber(TraceSubscriber* subscriber);
122 51
123 private: 52 private:
124 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap; 53 typedef std::set<scoped_refptr<TraceMessageFilter> > FilterMap;
125 54
126 friend struct DefaultSingletonTraits<TraceController>; 55 friend struct DefaultSingletonTraits<TraceControllerImpl>;
127 friend class TraceMessageFilter; 56 friend class ::TraceMessageFilter;
128 57
129 TraceController(); 58 TraceControllerImpl();
130 ~TraceController(); 59 virtual ~TraceControllerImpl();
131 60
132 bool is_tracing_enabled() const { 61 bool is_tracing_enabled() const {
133 return can_end_tracing(); 62 return can_end_tracing();
134 } 63 }
135 64
136 bool can_end_tracing() const { 65 bool can_end_tracing() const {
137 return is_tracing_ && pending_end_ack_count_ == 0; 66 return is_tracing_ && pending_end_ack_count_ == 0;
138 } 67 }
139 68
140 // Can get Buffer Percent Full 69 // Can get Buffer Percent Full
(...skipping 25 matching lines...) Expand all
166 int pending_end_ack_count_; 95 int pending_end_ack_count_;
167 // Pending acks for GetTraceBufferPercentFullAsync: 96 // Pending acks for GetTraceBufferPercentFullAsync:
168 int pending_bpf_ack_count_; 97 int pending_bpf_ack_count_;
169 float maximum_bpf_; 98 float maximum_bpf_;
170 bool is_tracing_; 99 bool is_tracing_;
171 bool is_get_categories_; 100 bool is_get_categories_;
172 std::set<std::string> known_categories_; 101 std::set<std::string> known_categories_;
173 std::vector<std::string> included_categories_; 102 std::vector<std::string> included_categories_;
174 std::vector<std::string> excluded_categories_; 103 std::vector<std::string> excluded_categories_;
175 104
176 DISALLOW_COPY_AND_ASSIGN(TraceController); 105 DISALLOW_COPY_AND_ASSIGN(TraceControllerImpl);
177 }; 106 };
178 107
179 #endif // CONTENT_BROWSER_TRACE_CONTROLLER_H_ 108 } // namespace content
180 109
110 #endif // CONTENT_BROWSER_TRACE_CONTROLLER_IMPL_H_
111
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698