Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: content/browser/tracing/etw_system_event_consumer_win.cc

Issue 1468173003: [Tracing Clock Sync] Add TracingAgent interface in Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 18 matching lines...) Expand all
29 29
30 } // namespace 30 } // namespace
31 31
32 EtwSystemEventConsumer::EtwSystemEventConsumer() 32 EtwSystemEventConsumer::EtwSystemEventConsumer()
33 : thread_("EtwConsumerThread") { 33 : thread_("EtwConsumerThread") {
34 } 34 }
35 35
36 EtwSystemEventConsumer::~EtwSystemEventConsumer() { 36 EtwSystemEventConsumer::~EtwSystemEventConsumer() {
37 } 37 }
38 38
39 bool EtwSystemEventConsumer::StartSystemTracing() { 39 std::string EtwSystemEventConsumer::GetTracingAgentName() {
40 return kETWTracingAgentName;
41 }
40 42
43 std::string EtwSystemEventConsumer::GetTraceEventLabel() {
44 return kSystemTraceLabel;
45 }
46
47 bool EtwSystemEventConsumer::StartAgentTracing(
48 const base::trace_event::TraceConfig& trace_config) {
41 // Activate kernel tracing. 49 // Activate kernel tracing.
42 if (!StartKernelSessionTracing()) 50 if (!StartKernelSessionTracing())
43 return false; 51 return false;
44 52
45 // Start the consumer thread and start consuming events. 53 // Start the consumer thread and start consuming events.
46 thread_.Start(); 54 thread_.Start();
47 thread_.message_loop()->PostTask( 55 thread_.message_loop()->PostTask(
48 FROM_HERE, 56 FROM_HERE,
49 base::Bind(&EtwSystemEventConsumer::TraceAndConsumeOnThread, 57 base::Bind(&EtwSystemEventConsumer::TraceAndConsumeOnThread,
50 base::Unretained(this))); 58 base::Unretained(this)));
51 59
52 return true; 60 return true;
53 } 61 }
54 62
55 void EtwSystemEventConsumer::StopSystemTracing(const OutputCallback& callback) { 63 void EtwSystemEventConsumer::StopAgentTracing(
64 const StopAgentTracingCallback& callback) {
56 // Deactivate kernel tracing. 65 // Deactivate kernel tracing.
57 if (!StopKernelSessionTracing()) { 66 if (!StopKernelSessionTracing()) {
58 LOG(FATAL) << "Could not stop system tracing."; 67 LOG(FATAL) << "Could not stop system tracing.";
59 } 68 }
60 69
61 // Stop consuming and flush events. 70 // Stop consuming and flush events.
62 OutputCallback on_stop_system_tracing_done_callback =
63 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone,
64 base::Unretained(this),
65 callback);
66 thread_.message_loop()->PostTask(FROM_HERE, 71 thread_.message_loop()->PostTask(FROM_HERE,
67 base::Bind(&EtwSystemEventConsumer::FlushOnThread, 72 base::Bind(&EtwSystemEventConsumer::FlushOnThread,
68 base::Unretained(this), on_stop_system_tracing_done_callback)); 73 base::Unretained(this),
74 callback));
69 } 75 }
70 76
71 void EtwSystemEventConsumer::OnStopSystemTracingDone( 77 void EtwSystemEventConsumer::OnStopSystemTracingDone(
72 const OutputCallback& callback, 78 const StopAgentTracingCallback& callback,
73 const scoped_refptr<base::RefCountedString>& result) { 79 const scoped_refptr<base::RefCountedString>& result) {
74 80
75 // Stop the consumer thread. 81 // Stop the consumer thread.
76 thread_.Stop(); 82 thread_.Stop();
77 83
78 // Pass the serialized events. 84 // Pass the serialized events.
79 callback.Run(result); 85 callback.Run(GetTracingAgentName(), GetTraceEventLabel(), result);
80 } 86 }
81 87
82 bool EtwSystemEventConsumer::StartKernelSessionTracing() { 88 bool EtwSystemEventConsumer::StartKernelSessionTracing() {
83 // Enabled flags (tracing facilities). 89 // Enabled flags (tracing facilities).
84 uint32 enabled_flags = EVENT_TRACE_FLAG_IMAGE_LOAD | 90 uint32 enabled_flags = EVENT_TRACE_FLAG_IMAGE_LOAD |
85 EVENT_TRACE_FLAG_PROCESS | 91 EVENT_TRACE_FLAG_PROCESS |
86 EVENT_TRACE_FLAG_THREAD | 92 EVENT_TRACE_FLAG_THREAD |
87 EVENT_TRACE_FLAG_CSWITCH; 93 EVENT_TRACE_FLAG_CSWITCH;
88 94
89 EVENT_TRACE_PROPERTIES& p = *properties_.get(); 95 EVENT_TRACE_PROPERTIES& p = *properties_.get();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Output a clock sync event. 208 // Output a clock sync event.
203 AddSyncEventToBuffer(); 209 AddSyncEventToBuffer();
204 210
205 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); 211 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME);
206 if (FAILED(hr)) 212 if (FAILED(hr))
207 return; 213 return;
208 Consume(); 214 Consume();
209 Close(); 215 Close();
210 } 216 }
211 217
212 void EtwSystemEventConsumer::FlushOnThread(const OutputCallback& callback) { 218 void EtwSystemEventConsumer::FlushOnThread(
219 const StopAgentTracingCallback& callback) {
213 // Add the header information to the stream. 220 // Add the header information to the stream.
214 scoped_ptr<base::DictionaryValue> header(new base::DictionaryValue()); 221 scoped_ptr<base::DictionaryValue> header(new base::DictionaryValue());
215 header->Set("name", new base::StringValue("ETW")); 222 header->Set("name", new base::StringValue("ETW"));
216 223
217 // Release and pass the events buffer. 224 // Release and pass the events buffer.
218 header->Set("content", events_.release()); 225 header->Set("content", events_.release());
219 226
220 // Serialize the results as a JSon string. 227 // Serialize the results as a JSon string.
221 std::string output; 228 std::string output;
222 JSONStringValueSerializer serializer(&output); 229 JSONStringValueSerializer serializer(&output);
223 serializer.Serialize(*header.get()); 230 serializer.Serialize(*header.get());
224 231
225 // Pass the result to the UI Thread. 232 // Pass the result to the UI Thread.
226 scoped_refptr<base::RefCountedString> result = 233 scoped_refptr<base::RefCountedString> result =
227 base::RefCountedString::TakeString(&output); 234 base::RefCountedString::TakeString(&output);
228 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 235 BrowserThread::PostTask(
229 base::Bind(callback, result)); 236 BrowserThread::UI, FROM_HERE,
237 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone,
238 base::Unretained(this),
239 callback,
240 result));
230 } 241 }
231 242
232 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698