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

Side by Side Diff: content/public/browser/background_tracing_manager.h

Issue 1002103004: NOT FOR REVIEW - Slow Reports Reference Implementation Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: JSON serialization. Created 5 years, 7 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
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/browser/background_tracing_manager.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 2015 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 #ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_
6 #define CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_
7
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/trace_event/trace_event_impl.h"
12 #include "base/values.h"
13 #include "content/common/content_export.h"
14
15 namespace content {
16
17 // BackgroundTracingConfig is passed to the BackgroundTracingManager to
18 // setup the trigger rules used to enable/disable background tracing.
19 class BackgroundTracingConfig
20 : public base::RefCountedThreadSafe<BackgroundTracingConfig> {
21 public:
22 enum Mode {
23 PREEMPTIVE_TRACING_MODE,
24 REACTIVE_TRACING_MODE,
25 };
26 enum CategoryPreset {
27 BENCHMARK,
28 BENCHMARK_DEEP,
29 };
30
31 Mode mode() const;
32
33 static scoped_refptr<BackgroundTracingConfig> FromDict(
34 const base::DictionaryValue* dict);
35 void IntoDict(base::DictionaryValue* dict);
36
37 protected:
38 friend class base::RefCountedThreadSafe<BackgroundTracingConfig>;
39
40 BackgroundTracingConfig(Mode mode);
41 virtual ~BackgroundTracingConfig();
42
43 Mode mode_;
44 };
45
46 // BackgroundTracingPreemptiveConfig holds trigger rules for use during
47 // preemptive tracing. Tracing will be enabled immediately, and whenever
48 // a trigger occurs, the trace will be finalized.
49 class BackgroundTracingPreemptiveConfig : public BackgroundTracingConfig {
50 public:
51 BackgroundTracingPreemptiveConfig();
52
53 enum RuleType {
54 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED,
55 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE,
56 MONITOR_AND_DUMP_WHEN_BROWSER_STARTED,
57 };
58 struct HistogramTriggerInfo {
59 std::string histogram_name_to_trigger_on;
60 int histogram_bin_to_trigger_on;
61 };
62 struct NamedTriggerInfo {
63 std::string trigger_name;
64 };
65 struct MonitoringRule {
66 RuleType type;
67 HistogramTriggerInfo histogram_trigger_info;
68 NamedTriggerInfo named_trigger_info;
69 };
70
71 void AddHistogramTriggerRule(const std::string& histogram_name,
72 int histogram_bin);
73 void AddNamedTriggerRule(const std::string& trigger_name);
74
75 CategoryPreset category_preset() const;
76 const std::vector<MonitoringRule>& configs() const;
77
78 static scoped_refptr<BackgroundTracingPreemptiveConfig> FromDict(
79 const base::DictionaryValue* dict);
80 void AsDict(base::DictionaryValue* dict);
81
82 protected:
83 ~BackgroundTracingPreemptiveConfig() override;
84
85 std::vector<MonitoringRule> configs_;
86 CategoryPreset category_preset_;
87 };
88
89 // BackgroundTracingReactiveConfig holds trigger rules for use during
90 // reactive tracing. Tracing will be not be enabled immediately, rather
91 // the BackgroundTracingManager will wait for a trigger to occur, and
92 // enable tracing at that point. Tracing will be finalized later, either
93 // after some time has elapsed or the trigger occurs again.
94 class BackgroundTracingReactiveConfig : public BackgroundTracingConfig {
95 public:
96 BackgroundTracingReactiveConfig();
97
98 enum RuleType { TRACE_ON_TRIGGER_UNTIL_10S_OR_NEXT_TRIGGER_OR_FULL };
99 struct TracingRule {
100 RuleType type;
101 std::string trigger_name;
102 CategoryPreset category_preset;
103 };
104
105 void AddTracingRule(RuleType rule_type,
106 const char* trigger_name,
107 CategoryPreset category_preset);
108
109 static scoped_refptr<BackgroundTracingReactiveConfig> FromDict(
110 const base::DictionaryValue* dict);
111 void AsDict(base::DictionaryValue* dict);
112
113 protected:
114 ~BackgroundTracingReactiveConfig() override;
115
116 std::vector<TracingRule> configs;
117 };
118
119 // Interface for trace data consumer. An implementation of this interface
120 // is passed to SetActiveScenario() and receives the trace data.
121 // This may happen on any thread.
122 class BackgroundTracingUploadSink
123 : public base::RefCountedThreadSafe<BackgroundTracingUploadSink> {
124 public:
125 virtual void Upload(const std::string& contents,
126 base::Callback<void()> done_callback) = 0;
127 virtual bool RequiresAnonymizedData() const = 0;
128
129 protected:
130 friend class base::RefCountedThreadSafe<BackgroundTracingUploadSink>;
131 virtual ~BackgroundTracingUploadSink() {}
132 };
133
134 // BackgroundTracingManager is used on the browser process to trigger the
135 // collection of trace data and upload the results. Only the browser UI thread
136 // is allowed to interact with the BackgroundTracingManager. All callbacks are
137 // called on the UI thread.
138 class BackgroundTracingManager {
139 public:
140 CONTENT_EXPORT static BackgroundTracingManager* GetInstance();
141
142 // Set the triggering rules for when to start recording.
143 virtual bool SetActiveScenario(
144 scoped_refptr<BackgroundTracingConfig> config,
145 scoped_refptr<BackgroundTracingUploadSink> upload_sink) = 0;
146
147 // Notifies the caller when the manager is idle (not recording or uploading),
148 // so that a call to SetActiveScenario() is likely to succeed.
149 typedef base::Callback<void()> IdleCallback;
150 virtual void WhenIdle(IdleCallback idle_callback) = 0;
151
152 typedef base::Callback<void(bool)> StartedFinalizingCallback;
153 typedef int TriggerHandle;
154
155 // Notifies that a manual trigger event has occurred, and we may need to
156 // either begin recording or finalize the trace, depending on the config.
157 // If the trigger specified isn't active in the config, this will do nothing.
158 virtual void DidTriggerHappen(TriggerHandle,
159 StartedFinalizingCallback started_callback) = 0;
160
161 // Registers a manual trigger handle, and returns a TriggerHandle which can
162 // be passed to DidTriggerHappen().
163 virtual TriggerHandle RegisterTriggerType(const char* trigger_name) = 0;
164
165 // Returns a list of all registered triggers.
166 virtual void GetTriggerNameList(std::vector<std::string>& trigger_names) = 0;
167
168 protected:
169 virtual ~BackgroundTracingManager() {}
170 };
171
172 } // namespace content
173
174 #endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/browser/background_tracing_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698