Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 BackgroundTracingConfig* FromDict(const base::DictionaryValue*); | |
| 34 void IntoDict(base::DictionaryValue*); | |
| 35 | |
| 36 protected: | |
| 37 friend class base::RefCountedThreadSafe<BackgroundTracingConfig>; | |
| 38 | |
| 39 BackgroundTracingConfig(Mode); | |
| 40 virtual ~BackgroundTracingConfig(); | |
| 41 | |
| 42 Mode mode_; | |
| 43 }; | |
| 44 | |
| 45 // BackgroundTracingPreemptiveConfig holds trigger rules for use during | |
| 46 // preemptive tracing. Tracing will be enabled immediately, and whenever | |
| 47 // a trigger occurs, the trace will be finalized. | |
| 48 class BackgroundTracingPreemptiveConfig : public BackgroundTracingConfig { | |
| 49 public: | |
| 50 BackgroundTracingPreemptiveConfig(); | |
| 51 | |
| 52 enum RuleType { | |
| 53 MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED, | |
| 54 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE, | |
| 55 MONITOR_AND_DUMP_WHEN_BROWSER_STARTED, | |
| 56 }; | |
| 57 struct HistogramTriggerInfo { | |
| 58 std::string histogram_name_to_trigger_on; | |
| 59 int histogram_bin_to_trigger_on; | |
| 60 }; | |
| 61 struct NamedTriggerInfo { | |
| 62 std::string trigger_name; | |
| 63 }; | |
| 64 struct MonitoringRule { | |
| 65 RuleType type; | |
| 66 HistogramTriggerInfo histogram_trigger_info; | |
| 67 NamedTriggerInfo named_trigger_info; | |
| 68 }; | |
| 69 | |
| 70 void AddHistogramTriggerRule(const std::string& histogram_name, | |
| 71 int histogram_bin); | |
| 72 void AddNamedTriggerRule(const std::string& trigger_name); | |
| 73 | |
| 74 CategoryPreset category_preset() const; | |
| 75 const std::vector<MonitoringRule>& configs() const; | |
| 76 | |
| 77 static BackgroundTracingPreemptiveConfig* FromDict( | |
| 78 const base::DictionaryValue*); | |
| 79 void AsDict(base::DictionaryValue*); | |
| 80 | |
| 81 protected: | |
| 82 ~BackgroundTracingPreemptiveConfig() override; | |
| 83 | |
| 84 std::vector<MonitoringRule> configs_; | |
| 85 CategoryPreset category_preset_; | |
| 86 }; | |
| 87 | |
| 88 // BackgroundTracingReactiveConfig holds trigger rules for use during | |
| 89 // reactive tracing. Tracing will be not be enabled immediately, rather | |
| 90 // the BackgroundTracingManager will wait for a trigger to occur, and | |
| 91 // enable tracing at that point. Tracing will be finalized later, either | |
| 92 // after some time has elapsed or the trigger occurs again. | |
| 93 class BackgroundTracingReactiveConfig : public BackgroundTracingConfig { | |
| 94 public: | |
| 95 BackgroundTracingReactiveConfig(); | |
| 96 | |
| 97 enum RuleType { TRACE_ON_TRIGGER_UNTIL_10S_OR_NEXT_TRIGGER_OR_FULL }; | |
| 98 struct TracingRule { | |
| 99 RuleType type; | |
| 100 std::string trigger_name; | |
| 101 CategoryPreset category_preset; | |
| 102 }; | |
| 103 | |
| 104 void AddTracingRule(RuleType rule_type, | |
| 105 const char* trigger_name, | |
| 106 CategoryPreset category_preset); | |
| 107 | |
| 108 static BackgroundTracingReactiveConfig* FromDict( | |
| 109 const base::DictionaryValue*); | |
| 110 void AsDict(base::DictionaryValue*); | |
| 111 | |
| 112 protected: | |
| 113 ~BackgroundTracingReactiveConfig() override; | |
| 114 | |
| 115 std::vector<TracingRule> configs; | |
| 116 }; | |
| 117 | |
| 118 // Interface for trace data consumer. An implementation of this interface | |
| 119 // is passed to SetActiveScenario() and receives the trace data. | |
| 120 // This may happen on any thread. | |
| 121 class BackgroundTracingUploadSink | |
|
nduca
2015/05/11 18:23:27
should we do one file for the configs and one for
shatch
2015/05/11 19:41:50
Ah yeah checking https://www.chromium.org/develope
| |
| 122 : public base::RefCountedThreadSafe<BackgroundTracingUploadSink> { | |
| 123 public: | |
| 124 virtual void Upload(const std::string&, base::Callback<void()>) = 0; | |
| 125 virtual bool RequiresAnonymizedData() const = 0; | |
| 126 | |
| 127 protected: | |
| 128 friend class base::RefCountedThreadSafe<BackgroundTracingUploadSink>; | |
| 129 virtual ~BackgroundTracingUploadSink() {} | |
| 130 }; | |
| 131 | |
| 132 // BackgroundTracingManager is used on the browser process to trigger the | |
| 133 // collection of trace data and upload the results. Only the browser UI thread | |
| 134 // is allowed to interact with the BackgroundTracingManager. All callbacks are | |
| 135 // called on the UI thread. | |
| 136 class BackgroundTracingManager { | |
| 137 public: | |
| 138 CONTENT_EXPORT static BackgroundTracingManager* GetInstance(); | |
| 139 | |
| 140 // Set the triggering rules for when to start recording. | |
| 141 virtual bool SetActiveScenario( | |
| 142 scoped_refptr<BackgroundTracingConfig>, | |
| 143 scoped_refptr<BackgroundTracingUploadSink>) = 0; | |
| 144 | |
| 145 // Notifies the caller when the manager is idle (not recording or uploading), | |
| 146 // so that a call to SetActiveScenario() is likely to succeed. | |
| 147 typedef base::Callback<void()> IdleCallback; | |
| 148 virtual void WhenIdle(IdleCallback idle_callback) = 0; | |
| 149 | |
| 150 typedef base::Callback<void(bool)> StartedFinalizingCallback; | |
| 151 typedef int TriggerHandle; | |
| 152 | |
| 153 // Notifies that a manual trigger event has occurred, and we may need to | |
| 154 // either begin recording or finalize the trace, depending on the config. | |
| 155 // If the trigger specified isn't active in the config, this will do nothing. | |
| 156 virtual void DidTriggerHappen(TriggerHandle, StartedFinalizingCallback) = 0; | |
| 157 | |
| 158 // Registers a manual trigger handle, and returns a TriggerHandle which can | |
| 159 // be passed to DidTriggerHappen(). | |
| 160 virtual TriggerHandle RegisterTriggerType(const char* trigger_name) = 0; | |
| 161 | |
| 162 // Returns a list of all registered triggers. | |
| 163 virtual void GetTriggerNameList(std::vector<std::string>& trigger_names) = 0; | |
| 164 | |
| 165 protected: | |
| 166 virtual ~BackgroundTracingManager() {} | |
| 167 }; | |
| 168 | |
| 169 } // namespace content | |
| 170 | |
| 171 #endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | |
| OLD | NEW |