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" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // Sync the clocks. | 159 // Sync the clocks. |
160 base::Time walltime = base::Time::NowFromSystemTime(); | 160 base::Time walltime = base::Time::NowFromSystemTime(); |
161 base::TimeTicks now = base::TimeTicks::Now(); | 161 base::TimeTicks now = base::TimeTicks::Now(); |
162 | 162 |
163 LARGE_INTEGER walltime_in_us; | 163 LARGE_INTEGER walltime_in_us; |
164 walltime_in_us.QuadPart = walltime.ToInternalValue(); | 164 walltime_in_us.QuadPart = walltime.ToInternalValue(); |
165 LARGE_INTEGER now_in_us; | 165 LARGE_INTEGER now_in_us; |
166 now_in_us.QuadPart = now.ToInternalValue(); | 166 now_in_us.QuadPart = now.ToInternalValue(); |
167 | 167 |
168 // Add fields to the event. | 168 // Add fields to the event. |
169 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 169 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
170 value->Set("guid", new base::StringValue("ClockSync")); | 170 value->Set("guid", new base::StringValue("ClockSync")); |
171 value->Set("walltime", new base::StringValue( | 171 value->Set("walltime", new base::StringValue( |
172 base::StringPrintf("%08X%08X", | 172 base::StringPrintf("%08X%08X", |
173 walltime_in_us.HighPart, | 173 walltime_in_us.HighPart, |
174 walltime_in_us.LowPart))); | 174 walltime_in_us.LowPart))); |
175 value->Set("tick", new base::StringValue( | 175 value->Set("tick", new base::StringValue( |
176 base::StringPrintf("%08X%08X", | 176 base::StringPrintf("%08X%08X", |
177 now_in_us.HighPart, | 177 now_in_us.HighPart, |
178 now_in_us.LowPart))); | 178 now_in_us.LowPart))); |
179 | 179 |
180 // Append it to the events buffer. | 180 // Append it to the events buffer. |
181 events_->Append(value.release()); | 181 events_->Append(value.release()); |
182 } | 182 } |
183 | 183 |
184 void EtwSystemEventConsumer::AppendEventToBuffer(EVENT_TRACE* event) { | 184 void EtwSystemEventConsumer::AppendEventToBuffer(EVENT_TRACE* event) { |
185 using base::FundamentalValue; | 185 using base::FundamentalValue; |
186 | 186 |
187 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 187 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
188 | 188 |
189 // Add header fields to the event. | 189 // Add header fields to the event. |
190 LARGE_INTEGER ts_us; | 190 LARGE_INTEGER ts_us; |
191 ts_us.QuadPart = event->Header.TimeStamp.QuadPart / 10; | 191 ts_us.QuadPart = event->Header.TimeStamp.QuadPart / 10; |
192 value->Set("ts", new base::StringValue( | 192 value->Set("ts", new base::StringValue( |
193 base::StringPrintf("%08X%08X", ts_us.HighPart, ts_us.LowPart))); | 193 base::StringPrintf("%08X%08X", ts_us.HighPart, ts_us.LowPart))); |
194 | 194 |
195 value->Set("guid", new base::StringValue(GuidToString(event->Header.Guid))); | 195 value->Set("guid", new base::StringValue(GuidToString(event->Header.Guid))); |
196 | 196 |
197 value->Set("op", new FundamentalValue(event->Header.Class.Type)); | 197 value->Set("op", new FundamentalValue(event->Header.Class.Type)); |
(...skipping 25 matching lines...) Expand all Loading... |
223 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); | 223 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); |
224 if (FAILED(hr)) | 224 if (FAILED(hr)) |
225 return; | 225 return; |
226 Consume(); | 226 Consume(); |
227 Close(); | 227 Close(); |
228 } | 228 } |
229 | 229 |
230 void EtwSystemEventConsumer::FlushOnThread( | 230 void EtwSystemEventConsumer::FlushOnThread( |
231 const StopAgentTracingCallback& callback) { | 231 const StopAgentTracingCallback& callback) { |
232 // Add the header information to the stream. | 232 // Add the header information to the stream. |
233 scoped_ptr<base::DictionaryValue> header(new base::DictionaryValue()); | 233 std::unique_ptr<base::DictionaryValue> header(new base::DictionaryValue()); |
234 header->Set("name", new base::StringValue("ETW")); | 234 header->Set("name", new base::StringValue("ETW")); |
235 | 235 |
236 // Release and pass the events buffer. | 236 // Release and pass the events buffer. |
237 header->Set("content", events_.release()); | 237 header->Set("content", events_.release()); |
238 | 238 |
239 // Serialize the results as a JSon string. | 239 // Serialize the results as a JSon string. |
240 std::string output; | 240 std::string output; |
241 JSONStringValueSerializer serializer(&output); | 241 JSONStringValueSerializer serializer(&output); |
242 serializer.Serialize(*header.get()); | 242 serializer.Serialize(*header.get()); |
243 | 243 |
244 // Pass the result to the UI Thread. | 244 // Pass the result to the UI Thread. |
245 scoped_refptr<base::RefCountedString> result = | 245 scoped_refptr<base::RefCountedString> result = |
246 base::RefCountedString::TakeString(&output); | 246 base::RefCountedString::TakeString(&output); |
247 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
248 BrowserThread::UI, FROM_HERE, | 248 BrowserThread::UI, FROM_HERE, |
249 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone, | 249 base::Bind(&EtwSystemEventConsumer::OnStopSystemTracingDone, |
250 base::Unretained(this), | 250 base::Unretained(this), |
251 callback, | 251 callback, |
252 result)); | 252 result)); |
253 } | 253 } |
254 | 254 |
255 } // namespace content | 255 } // namespace content |
OLD | NEW |