OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Trace events are for tracking application performance. | 5 // Trace events are for tracking application performance. |
6 // | 6 // |
7 // Events are issued against categories. Whereas LOG's | 7 // Events are issued against categories. Whereas LOG's |
8 // categories are statically defined, TRACE categories are created | 8 // categories are statically defined, TRACE categories are created |
9 // implicitly with a string. For example: | 9 // implicitly with a string. For example: |
10 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") | 10 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 return value; | 396 return value; |
397 } | 397 } |
398 | 398 |
399 static TraceValue ForceCopy(const TraceValue& rhs) { | 399 static TraceValue ForceCopy(const TraceValue& rhs) { |
400 TraceValue value(rhs); | 400 TraceValue value(rhs); |
401 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) | 401 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) |
402 value.type_ = TRACE_TYPE_STRING; | 402 value.type_ = TRACE_TYPE_STRING; |
403 return value; | 403 return value; |
404 } | 404 } |
405 | 405 |
| 406 bool is_string() const { |
| 407 return type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING; |
| 408 } |
| 409 |
406 void AppendAsJSON(std::string* out) const; | 410 void AppendAsJSON(std::string* out) const; |
407 | 411 |
408 Type type() const { | 412 Type type() const { |
409 return type_; | 413 return type_; |
410 } | 414 } |
411 uint64 as_uint() const { | 415 uint64 as_uint() const { |
412 DCHECK_EQ(TRACE_TYPE_UINT, type_); | 416 DCHECK_EQ(TRACE_TYPE_UINT, type_); |
413 return value_.as_uint; | 417 return value_.as_uint; |
414 } | 418 } |
415 bool as_bool() const { | 419 bool as_bool() const { |
416 DCHECK_EQ(TRACE_TYPE_BOOL, type_); | 420 DCHECK_EQ(TRACE_TYPE_BOOL, type_); |
417 return value_.as_bool; | 421 return value_.as_bool; |
418 } | 422 } |
419 int64 as_int() const { | 423 int64 as_int() const { |
420 DCHECK_EQ(TRACE_TYPE_INT, type_); | 424 DCHECK_EQ(TRACE_TYPE_INT, type_); |
421 return value_.as_int; | 425 return value_.as_int; |
422 } | 426 } |
423 double as_double() const { | 427 double as_double() const { |
424 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); | 428 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); |
425 return value_.as_double; | 429 return value_.as_double; |
426 } | 430 } |
427 const void* as_pointer() const { | 431 const void* as_pointer() const { |
428 DCHECK_EQ(TRACE_TYPE_POINTER, type_); | 432 DCHECK_EQ(TRACE_TYPE_POINTER, type_); |
429 return value_.as_pointer; | 433 return value_.as_pointer; |
430 } | 434 } |
431 const char* as_string() const { | 435 const char* as_string() const { |
432 DCHECK(type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING); | 436 DCHECK(is_string()); |
433 return value_.as_string; | 437 return value_.as_string; |
434 } | 438 } |
435 const char** as_assignable_string() { | 439 const char** as_assignable_string() { |
436 DCHECK_EQ(TRACE_TYPE_STRING, type_); | 440 DCHECK_EQ(TRACE_TYPE_STRING, type_); |
437 return &value_.as_string; | 441 return &value_.as_string; |
438 } | 442 } |
439 | 443 |
440 private: | 444 private: |
441 union Value { | 445 union Value { |
442 bool as_bool; | 446 bool as_bool; |
(...skipping 19 matching lines...) Expand all Loading... |
462 unsigned long thread_id, | 466 unsigned long thread_id, |
463 TimeTicks timestamp, | 467 TimeTicks timestamp, |
464 TraceEventPhase phase, | 468 TraceEventPhase phase, |
465 const TraceCategory* category, | 469 const TraceCategory* category, |
466 const char* name, | 470 const char* name, |
467 const char* arg1_name, const TraceValue& arg1_val, | 471 const char* arg1_name, const TraceValue& arg1_val, |
468 const char* arg2_name, const TraceValue& arg2_val, | 472 const char* arg2_name, const TraceValue& arg2_val, |
469 bool copy); | 473 bool copy); |
470 ~TraceEvent(); | 474 ~TraceEvent(); |
471 | 475 |
| 476 static const char* GetPhaseStr(TraceEventPhase phase); |
| 477 static TraceEventPhase GetPhase(const char* phase); |
| 478 |
472 // Serialize event data to JSON | 479 // Serialize event data to JSON |
473 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, | 480 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
474 size_t start, | 481 size_t start, |
475 size_t count, | 482 size_t count, |
476 std::string* out); | 483 std::string* out); |
477 void AppendAsJSON(std::string* out) const; | 484 void AppendAsJSON(std::string* out) const; |
478 | 485 |
479 TimeTicks timestamp() const { return timestamp_; } | 486 TimeTicks timestamp() const { return timestamp_; } |
480 | 487 |
481 // Exposed for unittesting: | 488 // Exposed for unittesting: |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 Data* p_data_; | 686 Data* p_data_; |
680 Data data_; | 687 Data data_; |
681 }; | 688 }; |
682 | 689 |
683 } // namespace internal | 690 } // namespace internal |
684 | 691 |
685 } // namespace debug | 692 } // namespace debug |
686 } // namespace base | 693 } // namespace base |
687 | 694 |
688 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 695 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
OLD | NEW |