| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/browser/tracing/etw_system_event_consumer_win.h" | 5 #include "content/browser/tracing/etw_system_event_consumer_win.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "base/trace_event/trace_event_impl.h" | 16 #include "base/trace_event/trace_event_impl.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const char kETWTracingAgentName[] = "etw"; | 23 const char kETWTracingAgentName[] = "etw"; |
| 23 const char kETWTraceLabel[] = "systemTraceEvents"; | 24 const char kETWTraceLabel[] = "systemTraceEvents"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 | 44 |
| 44 std::string EtwSystemEventConsumer::GetTracingAgentName() { | 45 std::string EtwSystemEventConsumer::GetTracingAgentName() { |
| 45 return kETWTracingAgentName; | 46 return kETWTracingAgentName; |
| 46 } | 47 } |
| 47 | 48 |
| 48 std::string EtwSystemEventConsumer::GetTraceEventLabel() { | 49 std::string EtwSystemEventConsumer::GetTraceEventLabel() { |
| 49 return kETWTraceLabel; | 50 return kETWTraceLabel; |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool EtwSystemEventConsumer::StartAgentTracing( | 53 void EtwSystemEventConsumer::StartAgentTracing( |
| 53 const base::trace_event::TraceConfig& trace_config) { | 54 const base::trace_event::TraceConfig& trace_config, |
| 55 const StartAgentTracingCallback& callback) { |
| 54 // Activate kernel tracing. | 56 // Activate kernel tracing. |
| 55 if (!StartKernelSessionTracing()) | 57 if (!StartKernelSessionTracing()) { |
| 56 return false; | 58 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 59 FROM_HERE, |
| 60 base::Bind(callback, GetTracingAgentName(), false /* success */)); |
| 61 return; |
| 62 } |
| 57 | 63 |
| 58 // Start the consumer thread and start consuming events. | 64 // Start the consumer thread and start consuming events. |
| 59 thread_.Start(); | 65 thread_.Start(); |
| 60 thread_.message_loop()->PostTask( | 66 thread_.message_loop()->PostTask( |
| 61 FROM_HERE, | 67 FROM_HERE, |
| 62 base::Bind(&EtwSystemEventConsumer::TraceAndConsumeOnThread, | 68 base::Bind(&EtwSystemEventConsumer::TraceAndConsumeOnThread, |
| 63 base::Unretained(this))); | 69 base::Unretained(this))); |
| 64 | 70 |
| 65 return true; | 71 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 72 FROM_HERE, |
| 73 base::Bind(callback, GetTracingAgentName(), true /* success */)); |
| 66 } | 74 } |
| 67 | 75 |
| 68 void EtwSystemEventConsumer::StopAgentTracing( | 76 void EtwSystemEventConsumer::StopAgentTracing( |
| 69 const StopAgentTracingCallback& callback) { | 77 const StopAgentTracingCallback& callback) { |
| 70 // Deactivate kernel tracing. | 78 // Deactivate kernel tracing. |
| 71 if (!StopKernelSessionTracing()) { | 79 if (!StopKernelSessionTracing()) { |
| 72 LOG(FATAL) << "Could not stop system tracing."; | 80 LOG(FATAL) << "Could not stop system tracing."; |
| 73 } | 81 } |
| 74 | 82 |
| 75 // Stop consuming and flush events. | 83 // Stop consuming and flush events. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 base::RefCountedString::TakeString(&output); | 246 base::RefCountedString::TakeString(&output); |
| 239 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
| 240 BrowserThread::UI, FROM_HERE, | 248 BrowserThread::UI, FROM_HERE, |
| 241 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone, | 249 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone, |
| 242 base::Unretained(this), | 250 base::Unretained(this), |
| 243 callback, | 251 callback, |
| 244 result)); | 252 result)); |
| 245 } | 253 } |
| 246 | 254 |
| 247 } // namespace content | 255 } // namespace content |
| OLD | NEW |