Index: content/public/browser/background_tracing_manager.h |
diff --git a/content/public/browser/background_tracing_manager.h b/content/public/browser/background_tracing_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..76b05b58dc1f7f3215e325bf5562aad1a059f7b4 |
--- /dev/null |
+++ b/content/public/browser/background_tracing_manager.h |
@@ -0,0 +1,171 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ |
+#define CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ |
+ |
+#include "base/memory/ref_counted_memory.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/trace_event/trace_event_impl.h" |
+#include "base/values.h" |
+#include "content/common/content_export.h" |
+ |
+namespace content { |
+ |
+// BackgroundTracingConfig is passed to the BackgroundTracingManager to |
+// setup the trigger rules used to enable/disable background tracing. |
+class BackgroundTracingConfig |
+ : public base::RefCountedThreadSafe<BackgroundTracingConfig> { |
+ public: |
+ enum Mode { |
+ PREEMPTIVE_TRACING_MODE, |
+ REACTIVE_TRACING_MODE, |
+ }; |
+ enum CategoryPreset { |
+ BENCHMARK, |
+ BENCHMARK_DEEP, |
+ }; |
+ |
+ Mode mode() const; |
+ |
+ static BackgroundTracingConfig* FromDict(const base::DictionaryValue*); |
+ void IntoDict(base::DictionaryValue*); |
+ |
+ protected: |
+ friend class base::RefCountedThreadSafe<BackgroundTracingConfig>; |
+ |
+ BackgroundTracingConfig(Mode); |
+ virtual ~BackgroundTracingConfig(); |
+ |
+ Mode mode_; |
+}; |
+ |
+// BackgroundTracingPreemptiveConfig holds trigger rules for use during |
+// preemptive tracing. Tracing will be enabled immediately, and whenever |
+// a trigger occurs, the trace will be finalized. |
+class BackgroundTracingPreemptiveConfig : public BackgroundTracingConfig { |
+ public: |
+ BackgroundTracingPreemptiveConfig(); |
+ |
+ enum RuleType { |
+ MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED, |
+ MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE, |
+ MONITOR_AND_DUMP_WHEN_BROWSER_STARTED, |
+ }; |
+ struct HistogramTriggerInfo { |
+ std::string histogram_name_to_trigger_on; |
+ int histogram_bin_to_trigger_on; |
+ }; |
+ struct NamedTriggerInfo { |
+ std::string trigger_name; |
+ }; |
+ struct MonitoringRule { |
+ RuleType type; |
+ HistogramTriggerInfo histogram_trigger_info; |
+ NamedTriggerInfo named_trigger_info; |
+ }; |
+ |
+ void AddHistogramTriggerRule(const std::string& histogram_name, |
+ int histogram_bin); |
+ void AddNamedTriggerRule(const std::string& trigger_name); |
+ |
+ CategoryPreset category_preset() const; |
+ const std::vector<MonitoringRule>& configs() const; |
+ |
+ static BackgroundTracingPreemptiveConfig* FromDict( |
+ const base::DictionaryValue*); |
+ void AsDict(base::DictionaryValue*); |
+ |
+ protected: |
+ ~BackgroundTracingPreemptiveConfig() override; |
+ |
+ std::vector<MonitoringRule> configs_; |
+ CategoryPreset category_preset_; |
+}; |
+ |
+// BackgroundTracingReactiveConfig holds trigger rules for use during |
+// reactive tracing. Tracing will be not be enabled immediately, rather |
+// the BackgroundTracingManager will wait for a trigger to occur, and |
+// enable tracing at that point. Tracing will be finalized later, either |
+// after some time has elapsed or the trigger occurs again. |
+class BackgroundTracingReactiveConfig : public BackgroundTracingConfig { |
+ public: |
+ BackgroundTracingReactiveConfig(); |
+ |
+ enum RuleType { TRACE_ON_TRIGGER_UNTIL_10S_OR_NEXT_TRIGGER_OR_FULL }; |
+ struct TracingRule { |
+ RuleType type; |
+ std::string trigger_name; |
+ CategoryPreset category_preset; |
+ }; |
+ |
+ void AddTracingRule(RuleType rule_type, |
+ const char* trigger_name, |
+ CategoryPreset category_preset); |
+ |
+ static BackgroundTracingReactiveConfig* FromDict( |
+ const base::DictionaryValue*); |
+ void AsDict(base::DictionaryValue*); |
+ |
+ protected: |
+ ~BackgroundTracingReactiveConfig() override; |
+ |
+ std::vector<TracingRule> configs; |
+}; |
+ |
+// Interface for trace data consumer. An implementation of this interface |
+// is passed to SetActiveScenario() and receives the trace data. |
+// This may happen on any thread. |
+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
|
+ : public base::RefCountedThreadSafe<BackgroundTracingUploadSink> { |
+ public: |
+ virtual void Upload(const std::string&, base::Callback<void()>) = 0; |
+ virtual bool RequiresAnonymizedData() const = 0; |
+ |
+ protected: |
+ friend class base::RefCountedThreadSafe<BackgroundTracingUploadSink>; |
+ virtual ~BackgroundTracingUploadSink() {} |
+}; |
+ |
+// BackgroundTracingManager is used on the browser process to trigger the |
+// collection of trace data and upload the results. Only the browser UI thread |
+// is allowed to interact with the BackgroundTracingManager. All callbacks are |
+// called on the UI thread. |
+class BackgroundTracingManager { |
+ public: |
+ CONTENT_EXPORT static BackgroundTracingManager* GetInstance(); |
+ |
+ // Set the triggering rules for when to start recording. |
+ virtual bool SetActiveScenario( |
+ scoped_refptr<BackgroundTracingConfig>, |
+ scoped_refptr<BackgroundTracingUploadSink>) = 0; |
+ |
+ // Notifies the caller when the manager is idle (not recording or uploading), |
+ // so that a call to SetActiveScenario() is likely to succeed. |
+ typedef base::Callback<void()> IdleCallback; |
+ virtual void WhenIdle(IdleCallback idle_callback) = 0; |
+ |
+ typedef base::Callback<void(bool)> StartedFinalizingCallback; |
+ typedef int TriggerHandle; |
+ |
+ // Notifies that a manual trigger event has occurred, and we may need to |
+ // either begin recording or finalize the trace, depending on the config. |
+ // If the trigger specified isn't active in the config, this will do nothing. |
+ virtual void DidTriggerHappen(TriggerHandle, StartedFinalizingCallback) = 0; |
+ |
+ // Registers a manual trigger handle, and returns a TriggerHandle which can |
+ // be passed to DidTriggerHappen(). |
+ virtual TriggerHandle RegisterTriggerType(const char* trigger_name) = 0; |
+ |
+ // Returns a list of all registered triggers. |
+ virtual void GetTriggerNameList(std::vector<std::string>& trigger_names) = 0; |
+ |
+ protected: |
+ virtual ~BackgroundTracingManager() {} |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ |