| 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_tracing_agent_win.h" | 5 #include "content/browser/tracing/etw_tracing_agent_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/single_thread_task_runner.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "base/trace_event/trace_event_impl.h" | 17 #include "base/trace_event/trace_event_impl.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Activate kernel tracing. | 57 // Activate kernel tracing. |
| 57 if (!StartKernelSessionTracing()) { | 58 if (!StartKernelSessionTracing()) { |
| 58 base::ThreadTaskRunnerHandle::Get()->PostTask( | 59 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 59 FROM_HERE, | 60 FROM_HERE, |
| 60 base::Bind(callback, GetTracingAgentName(), false /* success */)); | 61 base::Bind(callback, GetTracingAgentName(), false /* success */)); |
| 61 return; | 62 return; |
| 62 } | 63 } |
| 63 | 64 |
| 64 // Start the consumer thread and start consuming events. | 65 // Start the consumer thread and start consuming events. |
| 65 thread_.Start(); | 66 thread_.Start(); |
| 66 thread_.message_loop()->PostTask( | 67 thread_.task_runner()->PostTask( |
| 67 FROM_HERE, | 68 FROM_HERE, base::Bind(&EtwTracingAgent::TraceAndConsumeOnThread, |
| 68 base::Bind(&EtwTracingAgent::TraceAndConsumeOnThread, | 69 base::Unretained(this))); |
| 69 base::Unretained(this))); | |
| 70 | 70 |
| 71 base::ThreadTaskRunnerHandle::Get()->PostTask( | 71 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 72 FROM_HERE, | 72 FROM_HERE, |
| 73 base::Bind(callback, GetTracingAgentName(), true /* success */)); | 73 base::Bind(callback, GetTracingAgentName(), true /* success */)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void EtwTracingAgent::StopAgentTracing( | 76 void EtwTracingAgent::StopAgentTracing( |
| 77 const StopAgentTracingCallback& callback) { | 77 const StopAgentTracingCallback& callback) { |
| 78 // Deactivate kernel tracing. | 78 // Deactivate kernel tracing. |
| 79 if (!StopKernelSessionTracing()) { | 79 if (!StopKernelSessionTracing()) { |
| 80 LOG(FATAL) << "Could not stop system tracing."; | 80 LOG(FATAL) << "Could not stop system tracing."; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Stop consuming and flush events. | 83 // Stop consuming and flush events. |
| 84 thread_.message_loop()->PostTask(FROM_HERE, | 84 thread_.task_runner()->PostTask(FROM_HERE, |
| 85 base::Bind(&EtwTracingAgent::FlushOnThread, | 85 base::Bind(&EtwTracingAgent::FlushOnThread, |
| 86 base::Unretained(this), | 86 base::Unretained(this), callback)); |
| 87 callback)); | |
| 88 } | 87 } |
| 89 | 88 |
| 90 void EtwTracingAgent::OnStopSystemTracingDone( | 89 void EtwTracingAgent::OnStopSystemTracingDone( |
| 91 const StopAgentTracingCallback& callback, | 90 const StopAgentTracingCallback& callback, |
| 92 const scoped_refptr<base::RefCountedString>& result) { | 91 const scoped_refptr<base::RefCountedString>& result) { |
| 93 | 92 |
| 94 // Stop the consumer thread. | 93 // Stop the consumer thread. |
| 95 thread_.Stop(); | 94 thread_.Stop(); |
| 96 | 95 |
| 97 // Pass the serialized events. | 96 // Pass the serialized events. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 base::RefCountedString::TakeString(&output); | 245 base::RefCountedString::TakeString(&output); |
| 247 BrowserThread::PostTask( | 246 BrowserThread::PostTask( |
| 248 BrowserThread::UI, FROM_HERE, | 247 BrowserThread::UI, FROM_HERE, |
| 249 base::Bind(&EtwTracingAgent::OnStopSystemTracingDone, | 248 base::Bind(&EtwTracingAgent::OnStopSystemTracingDone, |
| 250 base::Unretained(this), | 249 base::Unretained(this), |
| 251 callback, | 250 callback, |
| 252 result)); | 251 result)); |
| 253 } | 252 } |
| 254 | 253 |
| 255 } // namespace content | 254 } // namespace content |
| OLD | NEW |