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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_TRACE_CONTROLLER_H_
6 #define CONTENT_PUBLIC_BROWSER_TRACE_CONTROLLER_H_
8 #include "base/debug/trace_event.h"
9 #include "content/common/content_export.h"
13 class TraceSubscriber;
15 // Note: TraceController is going to be deprecated and replaced with
18 // TraceController is used on the browser processes to enable/disable
19 // trace status and collect trace data. Only the browser UI thread is allowed
20 // to interact with the TraceController object. All calls on the TraceSubscriber
21 // happen on the UI thread.
22 class TraceController {
24 CONTENT_EXPORT static TraceController* GetInstance();
26 // Called by browser process to start tracing events on all processes.
28 // Currently only one subscriber is allowed at a time.
29 // Tracing begins immediately locally, and asynchronously on child processes
30 // as soon as they receive the BeginTracing request.
32 // If BeginTracing was already called previously,
33 // or if an EndTracingAsync is pending,
34 // or if another subscriber is tracing,
35 // BeginTracing will return false meaning it failed.
37 // |category_patterns| is a comma-delimited list of category wildcards.
38 // A category pattern can have an optional '-' prefix to exclude category
39 // groups that contain a matching category.
40 // All the same rules apply above, so for example, having both included and
41 // excluded category patterns in the same list would not be supported.
43 // |mode| is the tracing mode being used.
45 // Example: BeginTracing("test_MyTest*");
46 // Example: BeginTracing("test_MyTest*,test_OtherStuff");
47 // Example: BeginTracing("-excluded_category1,-excluded_category2");
48 virtual bool BeginTracing(TraceSubscriber* subscriber,
49 const std::string& category_patterns,
50 base::debug::TraceLog::Options options) = 0;
52 // Called by browser process to stop tracing events on all processes.
54 // Child processes typically are caching trace data and only rarely flush
55 // and send trace data back to the browser process. That is because it may be
56 // an expensive operation to send the trace data over IPC, and we would like
57 // to avoid much runtime overhead of tracing. So, to end tracing, we must
58 // asynchronously ask all child processes to flush any pending trace data.
60 // Once all child processes have acked the EndTracing request,
61 // TraceSubscriber will be called with OnEndTracingComplete.
63 // If a previous call to EndTracingAsync is already pending,
64 // or if another subscriber is tracing,
65 // EndTracingAsync will return false meaning it failed.
66 virtual bool EndTracingAsync(TraceSubscriber* subscriber) = 0;
68 // Get the maximum across processes of trace buffer percent full state.
69 // When the TraceBufferPercentFull value is determined,
70 // subscriber->OnTraceBufferPercentFullReply is called.
71 // When any child process reaches 100% full, the TraceController will end
72 // tracing, and call TraceSubscriber::OnEndTracingComplete.
73 // GetTraceBufferPercentFullAsync fails in the following conditions:
74 // trace is ending or disabled;
75 // a previous call to GetTraceBufferPercentFullAsync is pending; or
76 // the caller is not the current subscriber.
77 virtual bool GetTraceBufferPercentFullAsync(TraceSubscriber* subscriber) = 0;
79 // |subscriber->OnEventWatchNotification()| will be called every time the
80 // given event occurs on any process.
81 virtual bool SetWatchEvent(TraceSubscriber* subscriber,
82 const std::string& category_name,
83 const std::string& event_name) = 0;
85 // Cancel the watch event. If tracing is enabled, this may race with the
86 // watch event notification firing.
87 virtual bool CancelWatchEvent(TraceSubscriber* subscriber) = 0;
89 // Cancel the subscriber so that it will not be called when EndTracingAsync is
90 // acked by all child processes. This will also call EndTracingAsync
91 // internally if necessary.
92 // Safe to call even if caller is not the current subscriber.
93 virtual void CancelSubscriber(TraceSubscriber* subscriber) = 0;
95 // Get set of known category groups. This can change as new code paths are
96 // reached. If true is returned, subscriber->OnKnownCategoriesCollected will
97 // be called once the categories are retrieved from child processes.
98 virtual bool GetKnownCategoryGroupsAsync(TraceSubscriber* subscriber) = 0;
101 virtual ~TraceController() {}
104 } // namespace content
106 #endif // CONTENT_PUBLIC_BROWSER_TRACE_CONTROLLER_H_