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 <utility> | |
10 | |
9 #include "base/base64.h" | 11 #include "base/base64.h" |
10 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
11 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
12 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
17 #include "base/trace_event/trace_event_impl.h" | 19 #include "base/trace_event/trace_event_impl.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
jdoerrie
2017/04/13 13:49:49
#include "base/values.h"
vabr (Chromium)
2017/04/13 16:06:48
Done.
| |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 const char kETWTracingAgentName[] = "etw"; | 26 const char kETWTracingAgentName[] = "etw"; |
25 const char kETWTraceLabel[] = "systemTraceEvents"; | 27 const char kETWTraceLabel[] = "systemTraceEvents"; |
26 | 28 |
27 const int kEtwBufferSizeInKBytes = 16; | 29 const int kEtwBufferSizeInKBytes = 16; |
28 const int kEtwBufferFlushTimeoutInSeconds = 1; | 30 const int kEtwBufferFlushTimeoutInSeconds = 1; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 // Add fields to the event. | 169 // Add fields to the event. |
168 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 170 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
169 value->Set("guid", new base::Value("ClockSync")); | 171 value->Set("guid", new base::Value("ClockSync")); |
170 value->Set("walltime", | 172 value->Set("walltime", |
171 new base::Value(base::StringPrintf( | 173 new base::Value(base::StringPrintf( |
172 "%08X%08X", walltime_in_us.HighPart, walltime_in_us.LowPart))); | 174 "%08X%08X", walltime_in_us.HighPart, walltime_in_us.LowPart))); |
173 value->Set("tick", new base::Value(base::StringPrintf( | 175 value->Set("tick", new base::Value(base::StringPrintf( |
174 "%08X%08X", now_in_us.HighPart, now_in_us.LowPart))); | 176 "%08X%08X", now_in_us.HighPart, now_in_us.LowPart))); |
175 | 177 |
176 // Append it to the events buffer. | 178 // Append it to the events buffer. |
177 events_->Append(value.release()); | 179 events_->Append(std::move(value)); |
178 } | 180 } |
179 | 181 |
180 void EtwTracingAgent::AppendEventToBuffer(EVENT_TRACE* event) { | 182 void EtwTracingAgent::AppendEventToBuffer(EVENT_TRACE* event) { |
181 using base::Value; | 183 using base::Value; |
182 | 184 |
183 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 185 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
184 | 186 |
185 // Add header fields to the event. | 187 // Add header fields to the event. |
186 LARGE_INTEGER ts_us; | 188 LARGE_INTEGER ts_us; |
187 ts_us.QuadPart = event->Header.TimeStamp.QuadPart / 10; | 189 ts_us.QuadPart = event->Header.TimeStamp.QuadPart / 10; |
188 value->Set("ts", new base::Value(base::StringPrintf( | 190 value->Set("ts", new base::Value(base::StringPrintf( |
189 "%08X%08X", ts_us.HighPart, ts_us.LowPart))); | 191 "%08X%08X", ts_us.HighPart, ts_us.LowPart))); |
190 | 192 |
191 value->Set("guid", new base::Value(GuidToString(event->Header.Guid))); | 193 value->Set("guid", new base::Value(GuidToString(event->Header.Guid))); |
192 | 194 |
193 value->Set("op", new Value(event->Header.Class.Type)); | 195 value->Set("op", new Value(event->Header.Class.Type)); |
194 value->Set("ver", new Value(event->Header.Class.Version)); | 196 value->Set("ver", new Value(event->Header.Class.Version)); |
195 value->Set("pid", new Value(static_cast<int>(event->Header.ProcessId))); | 197 value->Set("pid", new Value(static_cast<int>(event->Header.ProcessId))); |
196 value->Set("tid", new Value(static_cast<int>(event->Header.ThreadId))); | 198 value->Set("tid", new Value(static_cast<int>(event->Header.ThreadId))); |
197 value->Set("cpu", new Value(event->BufferContext.ProcessorNumber)); | 199 value->Set("cpu", new Value(event->BufferContext.ProcessorNumber)); |
198 | 200 |
199 // Base64 encode the payload bytes. | 201 // Base64 encode the payload bytes. |
200 base::StringPiece buffer(static_cast<const char*>(event->MofData), | 202 base::StringPiece buffer(static_cast<const char*>(event->MofData), |
201 event->MofLength); | 203 event->MofLength); |
202 std::string payload; | 204 std::string payload; |
203 base::Base64Encode(buffer, &payload); | 205 base::Base64Encode(buffer, &payload); |
204 value->Set("payload", new base::Value(payload)); | 206 value->Set("payload", new base::Value(payload)); |
205 | 207 |
206 // Append it to the events buffer. | 208 // Append it to the events buffer. |
207 events_->Append(value.release()); | 209 events_->Append(std::move(value)); |
208 } | 210 } |
209 | 211 |
210 void EtwTracingAgent::TraceAndConsumeOnThread() { | 212 void EtwTracingAgent::TraceAndConsumeOnThread() { |
211 // Create the events buffer. | 213 // Create the events buffer. |
212 events_.reset(new base::ListValue()); | 214 events_.reset(new base::ListValue()); |
213 | 215 |
214 // Output a clock sync event. | 216 // Output a clock sync event. |
215 AddSyncEventToBuffer(); | 217 AddSyncEventToBuffer(); |
216 | 218 |
217 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); | 219 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); |
218 if (FAILED(hr)) | 220 if (FAILED(hr)) |
219 return; | 221 return; |
220 Consume(); | 222 Consume(); |
221 Close(); | 223 Close(); |
222 } | 224 } |
223 | 225 |
224 void EtwTracingAgent::FlushOnThread( | 226 void EtwTracingAgent::FlushOnThread( |
225 const StopAgentTracingCallback& callback) { | 227 const StopAgentTracingCallback& callback) { |
226 // Add the header information to the stream. | 228 // Add the header information to the stream. |
227 std::unique_ptr<base::DictionaryValue> header(new base::DictionaryValue()); | 229 std::unique_ptr<base::DictionaryValue> header(new base::DictionaryValue()); |
228 header->Set("name", new base::Value("ETW")); | 230 header->Set("name", new base::Value("ETW")); |
229 | 231 |
230 // Release and pass the events buffer. | 232 // Release and pass the events buffer. |
231 header->Set("content", events_.release()); | 233 header->Set("content", std::move(events_)); |
232 | 234 |
233 // Serialize the results as a JSon string. | 235 // Serialize the results as a JSon string. |
234 std::string output; | 236 std::string output; |
235 JSONStringValueSerializer serializer(&output); | 237 JSONStringValueSerializer serializer(&output); |
236 serializer.Serialize(*header.get()); | 238 serializer.Serialize(*header.get()); |
237 | 239 |
238 // Pass the result to the UI Thread. | 240 // Pass the result to the UI Thread. |
239 scoped_refptr<base::RefCountedString> result = | 241 scoped_refptr<base::RefCountedString> result = |
240 base::RefCountedString::TakeString(&output); | 242 base::RefCountedString::TakeString(&output); |
241 BrowserThread::PostTask( | 243 BrowserThread::PostTask( |
242 BrowserThread::UI, FROM_HERE, | 244 BrowserThread::UI, FROM_HERE, |
243 base::Bind(&EtwTracingAgent::OnStopSystemTracingDone, | 245 base::Bind(&EtwTracingAgent::OnStopSystemTracingDone, |
244 base::Unretained(this), | 246 base::Unretained(this), |
245 callback, | 247 callback, |
246 result)); | 248 result)); |
247 } | 249 } |
248 | 250 |
249 } // namespace content | 251 } // namespace content |
OLD | NEW |