OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/trace_event/trace_event_impl.h" | 5 #include "base/trace_event/trace_event_impl.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
8 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
9 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
16 #include "base/trace_event/trace_log.h" | 18 #include "base/trace_event/trace_log.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 205 |
204 // static | 206 // static |
205 void TraceEvent::AppendValueAsJSON(unsigned char type, | 207 void TraceEvent::AppendValueAsJSON(unsigned char type, |
206 TraceEvent::TraceValue value, | 208 TraceEvent::TraceValue value, |
207 std::string* out) { | 209 std::string* out) { |
208 switch (type) { | 210 switch (type) { |
209 case TRACE_VALUE_TYPE_BOOL: | 211 case TRACE_VALUE_TYPE_BOOL: |
210 *out += value.as_bool ? "true" : "false"; | 212 *out += value.as_bool ? "true" : "false"; |
211 break; | 213 break; |
212 case TRACE_VALUE_TYPE_UINT: | 214 case TRACE_VALUE_TYPE_UINT: |
213 StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint)); | 215 StringAppendF(out, "%" PRIu64, static_cast<uint64_t>(value.as_uint)); |
214 break; | 216 break; |
215 case TRACE_VALUE_TYPE_INT: | 217 case TRACE_VALUE_TYPE_INT: |
216 StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int)); | 218 StringAppendF(out, "%" PRId64, static_cast<int64_t>(value.as_int)); |
217 break; | 219 break; |
218 case TRACE_VALUE_TYPE_DOUBLE: { | 220 case TRACE_VALUE_TYPE_DOUBLE: { |
219 // FIXME: base/json/json_writer.cc is using the same code, | 221 // FIXME: base/json/json_writer.cc is using the same code, |
220 // should be made into a common method. | 222 // should be made into a common method. |
221 std::string real; | 223 std::string real; |
222 double val = value.as_double; | 224 double val = value.as_double; |
223 if (std::isfinite(val)) { | 225 if (std::isfinite(val)) { |
224 real = DoubleToString(val); | 226 real = DoubleToString(val); |
225 // Ensure that the number has a .0 if there's no decimal or 'e'. This | 227 // Ensure that the number has a .0 if there's no decimal or 'e'. This |
226 // makes sure that when we read the JSON back, it's interpreted as a | 228 // makes sure that when we read the JSON back, it's interpreted as a |
(...skipping 19 matching lines...) Expand all Loading... |
246 real = "\"-Infinity\""; | 248 real = "\"-Infinity\""; |
247 } else { | 249 } else { |
248 real = "\"Infinity\""; | 250 real = "\"Infinity\""; |
249 } | 251 } |
250 StringAppendF(out, "%s", real.c_str()); | 252 StringAppendF(out, "%s", real.c_str()); |
251 break; | 253 break; |
252 } | 254 } |
253 case TRACE_VALUE_TYPE_POINTER: | 255 case TRACE_VALUE_TYPE_POINTER: |
254 // JSON only supports double and int numbers. | 256 // JSON only supports double and int numbers. |
255 // So as not to lose bits from a 64-bit pointer, output as a hex string. | 257 // So as not to lose bits from a 64-bit pointer, output as a hex string. |
256 StringAppendF(out, "\"0x%" PRIx64 "\"", static_cast<uint64>( | 258 StringAppendF( |
257 reinterpret_cast<intptr_t>( | 259 out, "\"0x%" PRIx64 "\"", |
258 value.as_pointer))); | 260 static_cast<uint64_t>(reinterpret_cast<intptr_t>(value.as_pointer))); |
259 break; | 261 break; |
260 case TRACE_VALUE_TYPE_STRING: | 262 case TRACE_VALUE_TYPE_STRING: |
261 case TRACE_VALUE_TYPE_COPY_STRING: | 263 case TRACE_VALUE_TYPE_COPY_STRING: |
262 EscapeJSONString(value.as_string ? value.as_string : "NULL", true, out); | 264 EscapeJSONString(value.as_string ? value.as_string : "NULL", true, out); |
263 break; | 265 break; |
264 default: | 266 default: |
265 NOTREACHED() << "Don't know how to print this value"; | 267 NOTREACHED() << "Don't know how to print this value"; |
266 break; | 268 break; |
267 } | 269 } |
268 } | 270 } |
269 | 271 |
270 void TraceEvent::AppendAsJSON( | 272 void TraceEvent::AppendAsJSON( |
271 std::string* out, | 273 std::string* out, |
272 const ArgumentFilterPredicate& argument_filter_predicate) const { | 274 const ArgumentFilterPredicate& argument_filter_predicate) const { |
273 int64 time_int64 = timestamp_.ToInternalValue(); | 275 int64_t time_int64 = timestamp_.ToInternalValue(); |
274 int process_id; | 276 int process_id; |
275 int thread_id; | 277 int thread_id; |
276 if ((flags_ & TRACE_EVENT_FLAG_HAS_PROCESS_ID) && | 278 if ((flags_ & TRACE_EVENT_FLAG_HAS_PROCESS_ID) && |
277 process_id_ != kNullProcessId) { | 279 process_id_ != kNullProcessId) { |
278 process_id = process_id_; | 280 process_id = process_id_; |
279 thread_id = -1; | 281 thread_id = -1; |
280 } else { | 282 } else { |
281 process_id = TraceLog::GetInstance()->process_id(); | 283 process_id = TraceLog::GetInstance()->process_id(); |
282 thread_id = thread_id_; | 284 thread_id = thread_id_; |
283 } | 285 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 AppendValueAsJSON(arg_types_[i], arg_values_[i], out); | 324 AppendValueAsJSON(arg_types_[i], arg_values_[i], out); |
323 } else { | 325 } else { |
324 *out += "\"__stripped__\""; | 326 *out += "\"__stripped__\""; |
325 } | 327 } |
326 } | 328 } |
327 | 329 |
328 *out += "}"; | 330 *out += "}"; |
329 } | 331 } |
330 | 332 |
331 if (phase_ == TRACE_EVENT_PHASE_COMPLETE) { | 333 if (phase_ == TRACE_EVENT_PHASE_COMPLETE) { |
332 int64 duration = duration_.ToInternalValue(); | 334 int64_t duration = duration_.ToInternalValue(); |
333 if (duration != -1) | 335 if (duration != -1) |
334 StringAppendF(out, ",\"dur\":%" PRId64, duration); | 336 StringAppendF(out, ",\"dur\":%" PRId64, duration); |
335 if (!thread_timestamp_.is_null()) { | 337 if (!thread_timestamp_.is_null()) { |
336 int64 thread_duration = thread_duration_.ToInternalValue(); | 338 int64_t thread_duration = thread_duration_.ToInternalValue(); |
337 if (thread_duration != -1) | 339 if (thread_duration != -1) |
338 StringAppendF(out, ",\"tdur\":%" PRId64, thread_duration); | 340 StringAppendF(out, ",\"tdur\":%" PRId64, thread_duration); |
339 } | 341 } |
340 } | 342 } |
341 | 343 |
342 // Output tts if thread_timestamp is valid. | 344 // Output tts if thread_timestamp is valid. |
343 if (!thread_timestamp_.is_null()) { | 345 if (!thread_timestamp_.is_null()) { |
344 int64 thread_time_int64 = thread_timestamp_.ToInternalValue(); | 346 int64_t thread_time_int64 = thread_timestamp_.ToInternalValue(); |
345 StringAppendF(out, ",\"tts\":%" PRId64, thread_time_int64); | 347 StringAppendF(out, ",\"tts\":%" PRId64, thread_time_int64); |
346 } | 348 } |
347 | 349 |
348 // Output async tts marker field if flag is set. | 350 // Output async tts marker field if flag is set. |
349 if (flags_ & TRACE_EVENT_FLAG_ASYNC_TTS) { | 351 if (flags_ & TRACE_EVENT_FLAG_ASYNC_TTS) { |
350 StringAppendF(out, ", \"use_async_tts\":1"); | 352 StringAppendF(out, ", \"use_async_tts\":1"); |
351 } | 353 } |
352 | 354 |
353 // If id_ is set, print it out as a hex string so we don't loose any | 355 // If id_ is set, print it out as a hex string so we don't loose any |
354 // bits (it might be a 64-bit pointer). | 356 // bits (it might be a 64-bit pointer). |
355 if (flags_ & TRACE_EVENT_FLAG_HAS_ID) | 357 if (flags_ & TRACE_EVENT_FLAG_HAS_ID) |
356 StringAppendF(out, ",\"id\":\"0x%" PRIx64 "\"", static_cast<uint64>(id_)); | 358 StringAppendF(out, ",\"id\":\"0x%" PRIx64 "\"", static_cast<uint64_t>(id_)); |
357 | 359 |
358 if (flags_ & TRACE_EVENT_FLAG_BIND_TO_ENCLOSING) | 360 if (flags_ & TRACE_EVENT_FLAG_BIND_TO_ENCLOSING) |
359 StringAppendF(out, ",\"bp\":\"e\""); | 361 StringAppendF(out, ",\"bp\":\"e\""); |
360 | 362 |
361 if ((flags_ & TRACE_EVENT_FLAG_FLOW_OUT) || | 363 if ((flags_ & TRACE_EVENT_FLAG_FLOW_OUT) || |
362 (flags_ & TRACE_EVENT_FLAG_FLOW_IN)) { | 364 (flags_ & TRACE_EVENT_FLAG_FLOW_IN)) { |
363 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", | 365 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", |
364 static_cast<uint64>(bind_id_)); | 366 static_cast<uint64_t>(bind_id_)); |
365 } | 367 } |
366 if (flags_ & TRACE_EVENT_FLAG_FLOW_IN) | 368 if (flags_ & TRACE_EVENT_FLAG_FLOW_IN) |
367 StringAppendF(out, ",\"flow_in\":true"); | 369 StringAppendF(out, ",\"flow_in\":true"); |
368 if (flags_ & TRACE_EVENT_FLAG_FLOW_OUT) | 370 if (flags_ & TRACE_EVENT_FLAG_FLOW_OUT) |
369 StringAppendF(out, ",\"flow_out\":true"); | 371 StringAppendF(out, ",\"flow_out\":true"); |
370 | 372 |
371 // Instant events also output their scope. | 373 // Instant events also output their scope. |
372 if (phase_ == TRACE_EVENT_PHASE_INSTANT) { | 374 if (phase_ == TRACE_EVENT_PHASE_INSTANT) { |
373 char scope = '?'; | 375 char scope = '?'; |
374 switch (flags_ & TRACE_EVENT_FLAG_SCOPE_MASK) { | 376 switch (flags_ & TRACE_EVENT_FLAG_SCOPE_MASK) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); | 410 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); |
409 | 411 |
410 *out << value_as_text; | 412 *out << value_as_text; |
411 } | 413 } |
412 *out << "}"; | 414 *out << "}"; |
413 } | 415 } |
414 } | 416 } |
415 | 417 |
416 } // namespace trace_event | 418 } // namespace trace_event |
417 } // namespace base | 419 } // namespace base |
OLD | NEW |