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

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: Created 5 years, 1 month 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 bool EtwSystemEventConsumer::StartAgentTracing(
44 const base::trace_event::TraceConfig& trace_config) {
41 // Activate kernel tracing. 45 // Activate kernel tracing.
42 if (!StartKernelSessionTracing()) 46 if (!StartKernelSessionTracing())
43 return false; 47 return false;
44 48
45 // Start the consumer thread and start consuming events. 49 // Start the consumer thread and start consuming events.
46 thread_.Start(); 50 thread_.Start();
47 thread_.message_loop()->PostTask( 51 thread_.message_loop()->PostTask(
48 FROM_HERE, 52 FROM_HERE,
49 base::Bind(&EtwSystemEventConsumer::TraceAndConsumeOnThread, 53 base::Bind(&EtwSystemEventConsumer::TraceAndConsumeOnThread,
50 base::Unretained(this))); 54 base::Unretained(this)));
51 55
52 return true; 56 return true;
53 } 57 }
54 58
55 void EtwSystemEventConsumer::StopSystemTracing(const OutputCallback& callback) { 59 void EtwSystemEventConsumer::StopAgentTracing(
60 const StopAgentTracingCallback& callback) {
56 // Deactivate kernel tracing. 61 // Deactivate kernel tracing.
57 if (!StopKernelSessionTracing()) { 62 if (!StopKernelSessionTracing()) {
58 LOG(FATAL) << "Could not stop system tracing."; 63 LOG(FATAL) << "Could not stop system tracing.";
59 } 64 }
60 65
61 // Stop consuming and flush events. 66 // Stop consuming and flush events.
62 OutputCallback on_stop_system_tracing_done_callback = 67 StopAgentTracingCallback on_stop_system_tracing_done_callback =
63 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone, 68 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone,
64 base::Unretained(this), 69 base::Unretained(this),
65 callback); 70 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), on_stop_system_tracing_done_callback));
69 } 74 }
70 75
71 void EtwSystemEventConsumer::OnStopSystemTracingDone( 76 void EtwSystemEventConsumer::OnStopSystemTracingDone(
72 const OutputCallback& callback, 77 const StopAgentTracingCallback& callback,
73 const scoped_refptr<base::RefCountedString>& result) { 78 const scoped_refptr<base::RefCountedString>& result) {
74 79
75 // Stop the consumer thread. 80 // Stop the consumer thread.
76 thread_.Stop(); 81 thread_.Stop();
77 82
78 // Pass the serialized events. 83 // Pass the serialized events.
79 callback.Run(result); 84 callback.Run(result);
80 } 85 }
81 86
87 bool EtwSystemEventConsumer::SupportsExplicitClockSync() {
88 return false;
89 }
90
91 void EtwSystemEventConsumer::RecordClockSyncMarker(
92 scoped_ptr<base::DictionaryValue> marker) {
93 DCHECK(SupportsExplicitClockSync());
94 }
95
96 void EtwSystemEventConsumer::IssueClockSyncMarker() {
97 DCHECK(SupportsExplicitClockSync());
98 }
99
82 bool EtwSystemEventConsumer::StartKernelSessionTracing() { 100 bool EtwSystemEventConsumer::StartKernelSessionTracing() {
83 // Enabled flags (tracing facilities). 101 // Enabled flags (tracing facilities).
84 uint32 enabled_flags = EVENT_TRACE_FLAG_IMAGE_LOAD | 102 uint32 enabled_flags = EVENT_TRACE_FLAG_IMAGE_LOAD |
85 EVENT_TRACE_FLAG_PROCESS | 103 EVENT_TRACE_FLAG_PROCESS |
86 EVENT_TRACE_FLAG_THREAD | 104 EVENT_TRACE_FLAG_THREAD |
87 EVENT_TRACE_FLAG_CSWITCH; 105 EVENT_TRACE_FLAG_CSWITCH;
88 106
89 EVENT_TRACE_PROPERTIES& p = *properties_.get(); 107 EVENT_TRACE_PROPERTIES& p = *properties_.get();
90 p.LogFileMode = EVENT_TRACE_REAL_TIME_MODE; 108 p.LogFileMode = EVENT_TRACE_REAL_TIME_MODE;
91 p.FlushTimer = kEtwBufferFlushTimeoutInSeconds; 109 p.FlushTimer = kEtwBufferFlushTimeoutInSeconds;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Output a clock sync event. 220 // Output a clock sync event.
203 AddSyncEventToBuffer(); 221 AddSyncEventToBuffer();
204 222
205 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); 223 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME);
206 if (FAILED(hr)) 224 if (FAILED(hr))
207 return; 225 return;
208 Consume(); 226 Consume();
209 Close(); 227 Close();
210 } 228 }
211 229
212 void EtwSystemEventConsumer::FlushOnThread(const OutputCallback& callback) { 230 void EtwSystemEventConsumer::FlushOnThread(
231 const StopAgentTracingCallback& callback) {
213 // Add the header information to the stream. 232 // Add the header information to the stream.
214 scoped_ptr<base::DictionaryValue> header(new base::DictionaryValue()); 233 scoped_ptr<base::DictionaryValue> header(new base::DictionaryValue());
215 header->Set("name", new base::StringValue("ETW")); 234 header->Set("name", new base::StringValue("ETW"));
216 235
217 // Release and pass the events buffer. 236 // Release and pass the events buffer.
218 header->Set("content", events_.release()); 237 header->Set("content", events_.release());
219 238
220 // Serialize the results as a JSon string. 239 // Serialize the results as a JSon string.
221 std::string output; 240 std::string output;
222 JSONStringValueSerializer serializer(&output); 241 JSONStringValueSerializer serializer(&output);
223 serializer.Serialize(*header.get()); 242 serializer.Serialize(*header.get());
224 243
225 // Pass the result to the UI Thread. 244 // Pass the result to the UI Thread.
226 scoped_refptr<base::RefCountedString> result = 245 scoped_refptr<base::RefCountedString> result =
227 base::RefCountedString::TakeString(&output); 246 base::RefCountedString::TakeString(&output);
228 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 247 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
229 base::Bind(callback, result)); 248 base::Bind(callback, result));
230 } 249 }
231 250
232 } // namespace content 251 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698