tracing_controller.h revision f2477e01787aa58f445919b809d89e252beef54f
1// Copyright 2013 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_TRACING_CONTROLLER_H_ 6#define CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ 7 8#include <set> 9 10#include "base/debug/trace_event.h" 11#include "content/common/content_export.h" 12 13namespace base { 14class FilePath; 15}; 16 17namespace content { 18 19class TracingController; 20 21// TracingController is used on the browser processes to enable/disable 22// trace status and collect trace data. Only the browser UI thread is allowed 23// to interact with the TracingController object. All callbacks are called on 24// the UI thread. 25class TracingController { 26 public: 27 enum Options { 28 ENABLE_SYSTRACE = 1 << 0, 29 ENABLE_SAMPLING = 1 << 1, 30 RECORD_CONTINUOUSLY = 1 << 2, // For EnableRecording() only. 31 }; 32 33 CONTENT_EXPORT static TracingController* GetInstance(); 34 35 // Get a set of category groups. The category groups can change as 36 // new code paths are reached. 37 // 38 // Once all child processes have acked to the GetCategories request, 39 // GetCategoriesDoneCallback is called back with a set of category 40 // groups. 41 typedef base::Callback<void(const std::set<std::string>&)> 42 GetCategoriesDoneCallback; 43 virtual void GetCategories( 44 const GetCategoriesDoneCallback& callback) = 0; 45 46 // Start recording on all processes. 47 // 48 // Recording begins immediately locally, and asynchronously on child processes 49 // as soon as they receive the EnableRecording request. 50 // 51 // Once all child processes have acked to the EnableRecording request, 52 // EnableRecordingDoneCallback will be called back. 53 // 54 // |filter| is a filter to control what category groups should be traced. 55 // A filter can have an optional '-' prefix to exclude category groups 56 // that contain a matching category. Having both included and excluded 57 // category patterns in the same list would not be supported. 58 // 59 // Examples: "test_MyTest*", 60 // "test_MyTest*,test_OtherStuff", 61 // "-excluded_category1,-excluded_category2" 62 // 63 // |options| controls what kind of tracing is enabled. 64 typedef base::Callback<void()> EnableRecordingDoneCallback; 65 virtual bool EnableRecording( 66 const base::debug::CategoryFilter& filter, 67 TracingController::Options options, 68 const EnableRecordingDoneCallback& callback) = 0; 69 70 // Stop recording on all processes. 71 // 72 // Child processes typically are caching trace data and only rarely flush 73 // and send trace data back to the browser process. That is because it may be 74 // an expensive operation to send the trace data over IPC, and we would like 75 // to avoid much runtime overhead of tracing. So, to end tracing, we must 76 // asynchronously ask all child processes to flush any pending trace data. 77 // 78 // Once all child processes have acked to the DisableRecording request, 79 // TracingFileResultCallback will be called back with a file that contains 80 // the traced data. 81 // 82 // Trace data will be written into |result_file_path| if it is not empty, or 83 // into a temporary file. The actual file path will be passed to |callback| if 84 // it's not null. 85 // 86 // If |result_file_path| is empty and |callback| is null, trace data won't be 87 // written to any file. 88 typedef base::Callback<void(const base::FilePath&)> TracingFileResultCallback; 89 virtual bool DisableRecording(const base::FilePath& result_file_path, 90 const TracingFileResultCallback& callback) = 0; 91 92 // Start monitoring on all processes. 93 // 94 // Monitoring begins immediately locally, and asynchronously on child 95 // processes as soon as they receive the EnableMonitoring request. 96 // 97 // Once all child processes have acked to the EnableMonitoring request, 98 // EnableMonitoringDoneCallback will be called back. 99 // 100 // |filter| is a filter to control what category groups should be traced. 101 // 102 // |options| controls what kind of tracing is enabled. 103 typedef base::Callback<void()> EnableMonitoringDoneCallback; 104 virtual bool EnableMonitoring(const base::debug::CategoryFilter& filter, 105 TracingController::Options options, 106 const EnableMonitoringDoneCallback& callback) = 0; 107 108 // Stop monitoring on all processes. 109 // 110 // Once all child processes have acked to the DisableMonitoring request, 111 // DisableMonitoringDoneCallback is called back. 112 typedef base::Callback<void()> DisableMonitoringDoneCallback; 113 virtual bool DisableMonitoring( 114 const DisableMonitoringDoneCallback& callback) = 0; 115 116 // Get the current monitoring configuration. 117 virtual void GetMonitoringStatus(bool* out_enabled, 118 base::debug::CategoryFilter* out_filter, 119 TracingController::Options* out_options) = 0; 120 121 // Get the current monitoring traced data. 122 // 123 // Child processes typically are caching trace data and only rarely flush 124 // and send trace data back to the browser process. That is because it may be 125 // an expensive operation to send the trace data over IPC, and we would like 126 // to avoid much runtime overhead of tracing. So, to end tracing, we must 127 // asynchronously ask all child processes to flush any pending trace data. 128 // 129 // Once all child processes have acked to the CaptureMonitoringSnapshot 130 // request, TracingFileResultCallback will be called back with a file that 131 // contains the traced data. 132 // 133 // Trace data will be written into |result_file_path| if it is not empty, or 134 // into a temporary file. The actual file path will be passed to |callback|. 135 // 136 // If |result_file_path| is empty and |callback| is null, trace data won't be 137 // written to any file. 138 virtual void CaptureMonitoringSnapshot( 139 const base::FilePath& result_file_path, 140 const TracingFileResultCallback& callback) = 0; 141 142 // Get the maximum across processes of trace buffer percent full state. 143 // When the TraceBufferPercentFull value is determined, the callback is 144 // called. 145 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; 146 virtual bool GetTraceBufferPercentFull( 147 const GetTraceBufferPercentFullCallback& callback) = 0; 148 149 protected: 150 virtual ~TracingController() {} 151}; 152 153} // namespace content 154 155#endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ 156