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