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> | 9 #include <utility> |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Sync the clocks. | 161 // Sync the clocks. |
162 base::Time walltime = base::Time::NowFromSystemTime(); | 162 base::Time walltime = base::Time::NowFromSystemTime(); |
163 base::TimeTicks now = base::TimeTicks::Now(); | 163 base::TimeTicks now = base::TimeTicks::Now(); |
164 | 164 |
165 LARGE_INTEGER walltime_in_us; | 165 LARGE_INTEGER walltime_in_us; |
166 walltime_in_us.QuadPart = walltime.ToInternalValue(); | 166 walltime_in_us.QuadPart = walltime.ToInternalValue(); |
167 LARGE_INTEGER now_in_us; | 167 LARGE_INTEGER now_in_us; |
168 now_in_us.QuadPart = now.ToInternalValue(); | 168 now_in_us.QuadPart = now.ToInternalValue(); |
169 | 169 |
170 // Add fields to the event. | 170 // Add fields to the event. |
171 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 171 auto value = base::MakeUnique<base::DictionaryValue>(); |
172 value->Set("guid", new base::Value("ClockSync")); | 172 value->SetString("guid", "ClockSync"); |
173 value->Set("walltime", | 173 value->SetString("walltime", |
174 new base::Value(base::StringPrintf( | 174 base::StringPrintf("%08X%08X", walltime_in_us.HighPart, |
175 "%08X%08X", walltime_in_us.HighPart, walltime_in_us.LowPart))); | 175 walltime_in_us.LowPart)); |
176 value->Set("tick", new base::Value(base::StringPrintf( | 176 value->SetString("tick", base::StringPrintf("%08X%08X", now_in_us.HighPart, |
177 "%08X%08X", now_in_us.HighPart, now_in_us.LowPart))); | 177 now_in_us.LowPart)); |
178 | 178 |
179 // Append it to the events buffer. | 179 // Append it to the events buffer. |
180 events_->Append(std::move(value)); | 180 events_->Append(std::move(value)); |
181 } | 181 } |
182 | 182 |
183 void EtwTracingAgent::AppendEventToBuffer(EVENT_TRACE* event) { | 183 void EtwTracingAgent::AppendEventToBuffer(EVENT_TRACE* event) { |
184 using base::Value; | 184 auto value = base::MakeUnique<base::DictionaryValue>(); |
185 | |
186 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
187 | 185 |
188 // Add header fields to the event. | 186 // Add header fields to the event. |
189 LARGE_INTEGER ts_us; | 187 LARGE_INTEGER ts_us; |
190 ts_us.QuadPart = event->Header.TimeStamp.QuadPart / 10; | 188 ts_us.QuadPart = event->Header.TimeStamp.QuadPart / 10; |
191 value->Set("ts", new base::Value(base::StringPrintf( | 189 value->SetString( |
192 "%08X%08X", ts_us.HighPart, ts_us.LowPart))); | 190 "ts", base::StringPrintf("%08X%08X", ts_us.HighPart, ts_us.LowPart)); |
193 | 191 |
194 value->Set("guid", new base::Value(GuidToString(event->Header.Guid))); | 192 value->SetString("guid", GuidToString(event->Header.Guid)); |
195 | 193 |
196 value->Set("op", new Value(event->Header.Class.Type)); | 194 value->SetInteger("op", event->Header.Class.Type); |
197 value->Set("ver", new Value(event->Header.Class.Version)); | 195 value->SetInteger("ver", event->Header.Class.Version); |
198 value->Set("pid", new Value(static_cast<int>(event->Header.ProcessId))); | 196 value->SetInteger("pid", static_cast<int>(event->Header.ProcessId)); |
199 value->Set("tid", new Value(static_cast<int>(event->Header.ThreadId))); | 197 value->SetInteger("tid", static_cast<int>(event->Header.ThreadId)); |
200 value->Set("cpu", new Value(event->BufferContext.ProcessorNumber)); | 198 value->SetInteger("cpu", event->BufferContext.ProcessorNumber); |
201 | 199 |
202 // Base64 encode the payload bytes. | 200 // Base64 encode the payload bytes. |
203 base::StringPiece buffer(static_cast<const char*>(event->MofData), | 201 base::StringPiece buffer(static_cast<const char*>(event->MofData), |
204 event->MofLength); | 202 event->MofLength); |
205 std::string payload; | 203 std::string payload; |
206 base::Base64Encode(buffer, &payload); | 204 base::Base64Encode(buffer, &payload); |
207 value->Set("payload", new base::Value(payload)); | 205 value->SetString("payload", payload); |
208 | 206 |
209 // Append it to the events buffer. | 207 // Append it to the events buffer. |
210 events_->Append(std::move(value)); | 208 events_->Append(std::move(value)); |
211 } | 209 } |
212 | 210 |
213 void EtwTracingAgent::TraceAndConsumeOnThread() { | 211 void EtwTracingAgent::TraceAndConsumeOnThread() { |
214 // Create the events buffer. | 212 // Create the events buffer. |
215 events_.reset(new base::ListValue()); | 213 events_.reset(new base::ListValue()); |
216 | 214 |
217 // Output a clock sync event. | 215 // Output a clock sync event. |
218 AddSyncEventToBuffer(); | 216 AddSyncEventToBuffer(); |
219 | 217 |
220 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); | 218 HRESULT hr = OpenRealtimeSession(KERNEL_LOGGER_NAME); |
221 if (FAILED(hr)) | 219 if (FAILED(hr)) |
222 return; | 220 return; |
223 Consume(); | 221 Consume(); |
224 Close(); | 222 Close(); |
225 } | 223 } |
226 | 224 |
227 void EtwTracingAgent::FlushOnThread( | 225 void EtwTracingAgent::FlushOnThread( |
228 const StopAgentTracingCallback& callback) { | 226 const StopAgentTracingCallback& callback) { |
229 // Add the header information to the stream. | 227 // Add the header information to the stream. |
230 std::unique_ptr<base::DictionaryValue> header(new base::DictionaryValue()); | 228 auto header = base::MakeUnique<base::DictionaryValue>(); |
231 header->Set("name", new base::Value("ETW")); | 229 header->SetString("name", "ETW"); |
232 | 230 |
233 // Release and pass the events buffer. | 231 // Release and pass the events buffer. |
234 header->Set("content", std::move(events_)); | 232 header->Set("content", std::move(events_)); |
235 | 233 |
236 // Serialize the results as a JSon string. | 234 // Serialize the results as a JSon string. |
237 std::string output; | 235 std::string output; |
238 JSONStringValueSerializer serializer(&output); | 236 JSONStringValueSerializer serializer(&output); |
239 serializer.Serialize(*header.get()); | 237 serializer.Serialize(*header.get()); |
240 | 238 |
241 // Pass the result to the UI Thread. | 239 // Pass the result to the UI Thread. |
242 scoped_refptr<base::RefCountedString> result = | 240 scoped_refptr<base::RefCountedString> result = |
243 base::RefCountedString::TakeString(&output); | 241 base::RefCountedString::TakeString(&output); |
244 BrowserThread::PostTask( | 242 BrowserThread::PostTask( |
245 BrowserThread::UI, FROM_HERE, | 243 BrowserThread::UI, FROM_HERE, |
246 base::Bind(&EtwTracingAgent::OnStopSystemTracingDone, | 244 base::Bind(&EtwTracingAgent::OnStopSystemTracingDone, |
247 base::Unretained(this), | 245 base::Unretained(this), |
248 callback, | 246 callback, |
249 result)); | 247 result)); |
250 } | 248 } |
251 | 249 |
252 } // namespace content | 250 } // namespace content |
OLD | NEW |