| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 6 #define CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 virtual void ReceiveTraceFinalContents( | 40 virtual void ReceiveTraceFinalContents( |
| 41 std::unique_ptr<const base::DictionaryValue> metadata) {} | 41 std::unique_ptr<const base::DictionaryValue> metadata) {} |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 friend class base::RefCountedThreadSafe<TraceDataEndpoint>; | 44 friend class base::RefCountedThreadSafe<TraceDataEndpoint>; |
| 45 virtual ~TraceDataEndpoint() {} | 45 virtual ~TraceDataEndpoint() {} |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class TracingControllerImpl | 48 class TracingControllerImpl |
| 49 : public TracingController, | 49 : public TracingController, |
| 50 public base::trace_event::MemoryDumpManagerDelegate, |
| 50 public base::trace_event::TracingAgent { | 51 public base::trace_event::TracingAgent { |
| 51 public: | 52 public: |
| 52 // Create an endpoint that may be supplied to any TraceDataSink to | 53 // Create an endpoint that may be supplied to any TraceDataSink to |
| 53 // dump the trace data to a callback. | 54 // dump the trace data to a callback. |
| 54 CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateCallbackEndpoint( | 55 CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateCallbackEndpoint( |
| 55 const base::Callback<void(std::unique_ptr<const base::DictionaryValue>, | 56 const base::Callback<void(std::unique_ptr<const base::DictionaryValue>, |
| 56 base::RefCountedString*)>& callback); | 57 base::RefCountedString*)>& callback); |
| 57 | 58 |
| 58 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink( | 59 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink( |
| 59 scoped_refptr<TraceDataEndpoint> endpoint); | 60 scoped_refptr<TraceDataEndpoint> endpoint); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 80 std::string GetTracingAgentName() override; | 81 std::string GetTracingAgentName() override; |
| 81 std::string GetTraceEventLabel() override; | 82 std::string GetTraceEventLabel() override; |
| 82 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config, | 83 void StartAgentTracing(const base::trace_event::TraceConfig& trace_config, |
| 83 const StartAgentTracingCallback& callback) override; | 84 const StartAgentTracingCallback& callback) override; |
| 84 void StopAgentTracing(const StopAgentTracingCallback& callback) override; | 85 void StopAgentTracing(const StopAgentTracingCallback& callback) override; |
| 85 bool SupportsExplicitClockSync() override; | 86 bool SupportsExplicitClockSync() override; |
| 86 void RecordClockSyncMarker( | 87 void RecordClockSyncMarker( |
| 87 const std::string& sync_id, | 88 const std::string& sync_id, |
| 88 const RecordClockSyncMarkerCallback& callback) override; | 89 const RecordClockSyncMarkerCallback& callback) override; |
| 89 | 90 |
| 91 // base::trace_event::MemoryDumpManagerDelegate implementation. |
| 92 void RequestGlobalMemoryDump( |
| 93 const base::trace_event::MemoryDumpRequestArgs& args, |
| 94 const base::trace_event::MemoryDumpCallback& callback) override; |
| 95 uint64_t GetTracingProcessId() const override; |
| 96 |
| 90 class TraceMessageFilterObserver { | 97 class TraceMessageFilterObserver { |
| 91 public: | 98 public: |
| 92 virtual void OnTraceMessageFilterAdded(TraceMessageFilter* filter) = 0; | 99 virtual void OnTraceMessageFilterAdded(TraceMessageFilter* filter) = 0; |
| 93 virtual void OnTraceMessageFilterRemoved(TraceMessageFilter* filter) = 0; | 100 virtual void OnTraceMessageFilterRemoved(TraceMessageFilter* filter) = 0; |
| 94 }; | 101 }; |
| 95 void AddTraceMessageFilterObserver(TraceMessageFilterObserver* observer); | 102 void AddTraceMessageFilterObserver(TraceMessageFilterObserver* observer); |
| 96 void RemoveTraceMessageFilterObserver(TraceMessageFilterObserver* observer); | 103 void RemoveTraceMessageFilterObserver(TraceMessageFilterObserver* observer); |
| 97 | 104 |
| 98 private: | 105 private: |
| 99 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; | 106 friend struct base::DefaultLazyInstanceTraits<TracingControllerImpl>; |
| 100 friend class TraceMessageFilter; | 107 friend class TraceMessageFilter; |
| 101 | 108 |
| 109 // The arguments and callback for an queued global memory dump request. |
| 110 struct QueuedMemoryDumpRequest { |
| 111 QueuedMemoryDumpRequest( |
| 112 const base::trace_event::MemoryDumpRequestArgs& args, |
| 113 const base::trace_event::MemoryDumpCallback& callback); |
| 114 ~QueuedMemoryDumpRequest(); |
| 115 const base::trace_event::MemoryDumpRequestArgs args; |
| 116 const base::trace_event::MemoryDumpCallback callback; |
| 117 }; |
| 118 |
| 102 TracingControllerImpl(); | 119 TracingControllerImpl(); |
| 103 ~TracingControllerImpl() override; | 120 ~TracingControllerImpl() override; |
| 104 | 121 |
| 105 bool can_start_tracing() const { | 122 bool can_start_tracing() const { |
| 106 return !is_tracing_; | 123 return !is_tracing_; |
| 107 } | 124 } |
| 108 | 125 |
| 109 bool can_stop_tracing() const { | 126 bool can_stop_tracing() const { |
| 110 return is_tracing_ && !trace_data_sink_.get(); | 127 return is_tracing_ && !trace_data_sink_.get(); |
| 111 } | 128 } |
| 112 | 129 |
| 113 bool can_start_monitoring() const { | 130 bool can_start_monitoring() const { |
| 114 return !is_monitoring_; | 131 return !is_monitoring_; |
| 115 } | 132 } |
| 116 | 133 |
| 117 bool can_stop_monitoring() const { | 134 bool can_stop_monitoring() const { |
| 118 return is_monitoring_ && !monitoring_data_sink_.get(); | 135 return is_monitoring_ && !monitoring_data_sink_.get(); |
| 119 } | 136 } |
| 120 | 137 |
| 121 bool can_get_trace_buffer_usage() const { | 138 bool can_get_trace_buffer_usage() const { |
| 122 return pending_trace_buffer_usage_callback_.is_null(); | 139 return pending_trace_buffer_usage_callback_.is_null(); |
| 123 } | 140 } |
| 124 | 141 |
| 142 void PerformNextQueuedGlobalMemoryDump(); |
| 143 |
| 125 // Methods for use by TraceMessageFilter. | 144 // Methods for use by TraceMessageFilter. |
| 126 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter); | 145 void AddTraceMessageFilter(TraceMessageFilter* trace_message_filter); |
| 127 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter); | 146 void RemoveTraceMessageFilter(TraceMessageFilter* trace_message_filter); |
| 128 | 147 |
| 129 void OnTraceDataCollected( | 148 void OnTraceDataCollected( |
| 130 const scoped_refptr<base::RefCountedString>& events_str_ptr); | 149 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
| 131 | 150 |
| 132 // Callback of TraceLog::Flush() for the local trace. | 151 // Callback of TraceLog::Flush() for the local trace. |
| 133 void OnLocalTraceDataCollected( | 152 void OnLocalTraceDataCollected( |
| 134 const scoped_refptr<base::RefCountedString>& events_str_ptr, | 153 const scoped_refptr<base::RefCountedString>& events_str_ptr, |
| 135 bool has_more_events); | 154 bool has_more_events); |
| 136 | 155 |
| 137 // Adds the tracing agent with the specified agent name to the list of | 156 // Adds the tracing agent with the specified agent name to the list of |
| 138 // additional tracing agents. | 157 // additional tracing agents. |
| 139 void AddTracingAgent(const std::string& agent_name); | 158 void AddTracingAgent(const std::string& agent_name); |
| 140 | 159 |
| 141 void OnStartAgentTracingAcked(const std::string& agent_name, bool success); | 160 void OnStartAgentTracingAcked(const std::string& agent_name, bool success); |
| 142 | 161 |
| 143 void OnStopTracingAcked( | 162 void OnStopTracingAcked( |
| 144 TraceMessageFilter* trace_message_filter, | 163 TraceMessageFilter* trace_message_filter, |
| 145 const std::vector<std::string>& known_category_groups); | 164 const std::vector<std::string>& known_category_groups); |
| 146 | 165 |
| 147 void OnEndAgentTracingAcked( | 166 void OnEndAgentTracingAcked( |
| 148 const std::string& agent_name, | 167 const std::string& agent_name, |
| 149 const std::string& events_label, | 168 const std::string& events_label, |
| 150 const scoped_refptr<base::RefCountedString>& events_str_ptr); | 169 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
| 151 | 170 |
| 152 void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter, | 171 void OnTraceLogStatusReply(TraceMessageFilter* trace_message_filter, |
| 153 const base::trace_event::TraceLogStatus& status); | 172 const base::trace_event::TraceLogStatus& status); |
| 173 void OnProcessMemoryDumpResponse(TraceMessageFilter* trace_message_filter, |
| 174 uint64_t dump_guid, |
| 175 bool success); |
| 176 |
| 177 // Callback of MemoryDumpManager::CreateProcessDump(). |
| 178 void OnBrowserProcessMemoryDumpDone(uint64_t dump_guid, bool success); |
| 179 |
| 180 void FinalizeGlobalMemoryDumpIfAllProcessesReplied(); |
| 154 | 181 |
| 155 void SetEnabledOnFileThread( | 182 void SetEnabledOnFileThread( |
| 156 const base::trace_event::TraceConfig& trace_config, | 183 const base::trace_event::TraceConfig& trace_config, |
| 157 int mode, | 184 int mode, |
| 158 const base::Closure& callback); | 185 const base::Closure& callback); |
| 159 void SetDisabledOnFileThread(const base::Closure& callback); | 186 void SetDisabledOnFileThread(const base::Closure& callback); |
| 160 void OnAllTracingAgentsStarted(); | 187 void OnAllTracingAgentsStarted(); |
| 161 void StopTracingAfterClockSync(); | 188 void StopTracingAfterClockSync(); |
| 162 void OnStopTracingDone(); | 189 void OnStopTracingDone(); |
| 163 | 190 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 184 // Pending acks for StopTracing. | 211 // Pending acks for StopTracing. |
| 185 int pending_stop_tracing_ack_count_; | 212 int pending_stop_tracing_ack_count_; |
| 186 TraceMessageFilterSet pending_stop_tracing_filters_; | 213 TraceMessageFilterSet pending_stop_tracing_filters_; |
| 187 | 214 |
| 188 // Pending acks for GetTraceLogStatus. | 215 // Pending acks for GetTraceLogStatus. |
| 189 int pending_trace_log_status_ack_count_; | 216 int pending_trace_log_status_ack_count_; |
| 190 TraceMessageFilterSet pending_trace_log_status_filters_; | 217 TraceMessageFilterSet pending_trace_log_status_filters_; |
| 191 float maximum_trace_buffer_usage_; | 218 float maximum_trace_buffer_usage_; |
| 192 size_t approximate_event_count_; | 219 size_t approximate_event_count_; |
| 193 | 220 |
| 221 // Pending acks for memory RequestGlobalDumpPoint. |
| 222 int pending_memory_dump_ack_count_; |
| 223 int failed_memory_dump_count_; |
| 224 TraceMessageFilterSet pending_memory_dump_filters_; |
| 225 std::list<QueuedMemoryDumpRequest> queued_memory_dump_requests_; |
| 226 |
| 194 std::vector<base::trace_event::TracingAgent*> additional_tracing_agents_; | 227 std::vector<base::trace_event::TracingAgent*> additional_tracing_agents_; |
| 195 int pending_clock_sync_ack_count_; | 228 int pending_clock_sync_ack_count_; |
| 196 base::OneShotTimer clock_sync_timer_; | 229 base::OneShotTimer clock_sync_timer_; |
| 197 | 230 |
| 198 bool is_tracing_; | 231 bool is_tracing_; |
| 199 bool is_monitoring_; | 232 bool is_monitoring_; |
| 200 | 233 |
| 201 GetCategoriesDoneCallback pending_get_categories_done_callback_; | 234 GetCategoriesDoneCallback pending_get_categories_done_callback_; |
| 202 GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_; | 235 GetTraceBufferUsageCallback pending_trace_buffer_usage_callback_; |
| 203 | 236 |
| 204 base::ObserverList<TraceMessageFilterObserver> | 237 base::ObserverList<TraceMessageFilterObserver> |
| 205 trace_message_filter_observers_; | 238 trace_message_filter_observers_; |
| 206 | 239 |
| 207 std::set<std::string> known_category_groups_; | 240 std::set<std::string> known_category_groups_; |
| 208 std::set<TracingUI*> tracing_uis_; | 241 std::set<TracingUI*> tracing_uis_; |
| 209 scoped_refptr<TraceDataSink> trace_data_sink_; | 242 scoped_refptr<TraceDataSink> trace_data_sink_; |
| 210 scoped_refptr<TraceDataSink> monitoring_data_sink_; | 243 scoped_refptr<TraceDataSink> monitoring_data_sink_; |
| 211 std::unique_ptr<base::DictionaryValue> metadata_; | 244 std::unique_ptr<base::DictionaryValue> metadata_; |
| 212 | 245 |
| 213 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); | 246 DISALLOW_COPY_AND_ASSIGN(TracingControllerImpl); |
| 214 }; | 247 }; |
| 215 | 248 |
| 216 } // namespace content | 249 } // namespace content |
| 217 | 250 |
| 218 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ | 251 #endif // CONTENT_BROWSER_TRACING_TRACING_CONTROLLER_IMPL_H_ |
| OLD | NEW |