Chromium Code Reviews| 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 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ | 6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| 7 | 7 |
| 8 // This header file defines implementation details of how the trace macros in | 8 // This header file defines implementation details of how the trace macros in |
| 9 // trace_event_common.h collect and store trace events. Anything not | 9 // trace_event_common.h collect and store trace events. Anything not |
| 10 // implementation-specific should go in trace_event_common.h instead of here. | 10 // implementation-specific should go in trace_event_common.h instead of here. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 // DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, | 39 // DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, |
| 40 // instead. By default, pointers are mangled with the Process ID in | 40 // instead. By default, pointers are mangled with the Process ID in |
| 41 // TRACE_EVENT_ASYNC macros. Use this macro to prevent Process ID mangling. | 41 // TRACE_EVENT_ASYNC macros. Use this macro to prevent Process ID mangling. |
| 42 #define TRACE_ID_DONT_MANGLE(id) \ | 42 #define TRACE_ID_DONT_MANGLE(id) \ |
| 43 trace_event_internal::TraceID::DontMangle(id) | 43 trace_event_internal::TraceID::DontMangle(id) |
| 44 | 44 |
| 45 // By default, trace IDs are eventually converted to a single 64-bit number. Use | 45 // By default, trace IDs are eventually converted to a single 64-bit number. Use |
| 46 // this macro to add a scope string. | 46 // this macro to add a scope string. |
| 47 #define TRACE_ID_WITH_SCOPE(scope, id) \ | 47 #define TRACE_ID_WITH_SCOPE(scope, id) \ |
| 48 trace_event_internal::TraceID::WithScope(scope, id) | 48 trace_event_internal::TraceID::MakeScopedID(scope, id) |
| 49 | 49 // Can be nested within TRACE_ID_WITH_SCOPE macro. |
| 50 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id) | 50 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::MakeGlobalID(id) |
| 51 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id) | 51 // Can be nested within TRACE_ID_WITH_SCOPE macro. |
| 52 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::MakeLocalID(id) | |
| 53 // Can be nested within TRACE_ID_{LOCAL, GLOBAL, WITH_SCOPE} macros. | |
| 54 #define TRACE_ID_COMPOSITE(prefix, id) \ | |
| 55 trace_event_internal::TraceID::CompositeID(prefix, id) | |
| 52 | 56 |
| 53 #define TRACE_EVENT_API_CURRENT_THREAD_ID \ | 57 #define TRACE_EVENT_API_CURRENT_THREAD_ID \ |
| 54 static_cast<int>(base::PlatformThread::CurrentId()) | 58 static_cast<int>(base::PlatformThread::CurrentId()) |
| 55 | 59 |
| 56 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ | 60 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ |
| 57 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ | 61 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
| 58 (base::trace_event::TraceCategory::ENABLED_FOR_RECORDING | \ | 62 (base::trace_event::TraceCategory::ENABLED_FOR_RECORDING | \ |
| 59 base::trace_event::TraceCategory::ENABLED_FOR_ETW_EXPORT | \ | 63 base::trace_event::TraceCategory::ENABLED_FOR_ETW_EXPORT | \ |
| 60 base::trace_event::TraceCategory::ENABLED_FOR_FILTERING)) | 64 base::trace_event::TraceCategory::ENABLED_FOR_FILTERING)) |
| 61 | 65 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 // used. | 405 // used. |
| 402 const int kZeroNumArgs = 0; | 406 const int kZeroNumArgs = 0; |
| 403 const std::nullptr_t kGlobalScope = nullptr; | 407 const std::nullptr_t kGlobalScope = nullptr; |
| 404 const unsigned long long kNoId = 0; | 408 const unsigned long long kNoId = 0; |
| 405 | 409 |
| 406 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 410 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
| 407 // are by default mangled with the Process ID so that they are unlikely to | 411 // are by default mangled with the Process ID so that they are unlikely to |
| 408 // collide when the same pointer is used on different processes. | 412 // collide when the same pointer is used on different processes. |
| 409 class BASE_EXPORT TraceID { | 413 class BASE_EXPORT TraceID { |
| 410 public: | 414 public: |
| 411 // Can be combined with WithScope. | 415 class CompositeID { |
| 412 class LocalId { | |
| 413 public: | 416 public: |
| 414 explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {} | 417 CompositeID(unsigned long long prefix, unsigned long long raw_id) |
| 418 : prefix_(prefix), raw_id_(raw_id) {} | |
| 419 | |
| 420 void set_scope(const char* scope) { scope_ = scope; } | |
| 421 | |
| 422 void set_id_flags(unsigned int id_flags) { id_flags_ = id_flags; } | |
| 423 | |
| 424 const char* scope() const { return scope_; } | |
| 425 unsigned long long prefix() const { return prefix_; } | |
| 426 unsigned long long raw_id() const { return raw_id_; } | |
| 427 unsigned int id_flags() const { return id_flags_; } | |
| 428 | |
| 429 private: | |
| 430 const char* scope_ = nullptr; | |
| 431 unsigned long long prefix_; | |
| 432 unsigned long long raw_id_; | |
| 433 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; | |
| 434 }; | |
| 435 | |
| 436 class LocalID { | |
| 437 public: | |
| 438 explicit LocalID(unsigned long long raw_id) : raw_id_(raw_id) {} | |
| 415 unsigned long long raw_id() const { return raw_id_; } | 439 unsigned long long raw_id() const { return raw_id_; } |
| 416 private: | 440 private: |
| 417 unsigned long long raw_id_; | 441 unsigned long long raw_id_; |
| 418 }; | 442 }; |
| 419 | 443 |
| 420 // Can be combined with WithScope. | 444 class GlobalID { |
| 421 class GlobalId { | |
| 422 public: | 445 public: |
| 423 explicit GlobalId(unsigned long long raw_id) : raw_id_(raw_id) {} | 446 explicit GlobalID(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 424 unsigned long long raw_id() const { return raw_id_; } | 447 unsigned long long raw_id() const { return raw_id_; } |
| 425 private: | 448 private: |
| 426 unsigned long long raw_id_; | 449 unsigned long long raw_id_; |
| 427 }; | 450 }; |
| 428 | 451 |
| 429 class WithScope { | 452 class ScopedID { |
| 430 public: | 453 public: |
| 431 WithScope(const char* scope, unsigned long long raw_id) | 454 ScopedID(const char* scope, unsigned long long raw_id) |
| 432 : scope_(scope), raw_id_(raw_id) {} | 455 : scope_(scope), raw_id_(raw_id) {} |
| 433 WithScope(const char* scope, LocalId local_id) | 456 ScopedID(const char* scope, LocalID local_id) |
| 434 : scope_(scope), raw_id_(local_id.raw_id()) { | 457 : scope_(scope), raw_id_(local_id.raw_id()) { |
| 435 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; | 458 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; |
| 436 } | 459 } |
| 437 WithScope(const char* scope, GlobalId global_id) | 460 ScopedID(const char* scope, GlobalID global_id) |
| 438 : scope_(scope), raw_id_(global_id.raw_id()) { | 461 : scope_(scope), raw_id_(global_id.raw_id()) { |
| 439 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; | 462 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; |
| 440 } | 463 } |
| 464 const char* scope() const { return scope_; } | |
| 441 unsigned long long raw_id() const { return raw_id_; } | 465 unsigned long long raw_id() const { return raw_id_; } |
| 442 const char* scope() const { return scope_; } | |
| 443 unsigned int id_flags() const { return id_flags_; } | 466 unsigned int id_flags() const { return id_flags_; } |
| 444 private: | 467 private: |
| 445 const char* scope_ = nullptr; | 468 const char* scope_ = nullptr; |
| 446 unsigned long long raw_id_; | 469 unsigned long long raw_id_; |
| 447 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; | 470 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; |
| 448 }; | 471 }; |
| 449 | 472 |
| 450 // DEPRECATED: consider using LocalId or GlobalId, instead. | 473 static inline CompositeID MakeLocalID(CompositeID& composite_id) { |
| 474 composite_id.set_id_flags(TRACE_EVENT_FLAG_HAS_LOCAL_ID); | |
| 475 return composite_id; | |
| 476 } | |
| 477 | |
| 478 static inline LocalID MakeLocalID(unsigned long long raw_id) { | |
| 479 return LocalID(raw_id); | |
| 480 } | |
| 481 | |
| 482 static inline CompositeID MakeGlobalID(CompositeID& composite_id) { | |
| 483 composite_id.set_id_flags(TRACE_EVENT_FLAG_HAS_GLOBAL_ID); | |
| 484 return composite_id; | |
| 485 } | |
| 486 | |
| 487 static inline GlobalID MakeGlobalID(unsigned long long raw_id) { | |
| 488 return GlobalID(raw_id); | |
| 489 } | |
| 490 | |
| 491 static inline CompositeID MakeScopedID(const char* scope, | |
| 492 CompositeID& composite_id) { | |
|
caseq
2016/11/21 19:47:20
const ComositeID&
chiniforooshan
2016/11/21 21:12:15
But composite_id is actually modified in this func
| |
| 493 composite_id.set_scope(scope); | |
| 494 return composite_id; | |
| 495 } | |
| 496 | |
| 497 template <typename T> | |
| 498 static inline ScopedID MakeScopedID(const char* scope, T raw_id) { | |
|
caseq
2016/11/21 19:47:20
why do we need it to be template? looks like we on
chiniforooshan
2016/11/21 21:12:15
I think you missed the other two constructors :) S
| |
| 499 return ScopedID(scope, raw_id); | |
| 500 } | |
| 501 | |
| 502 // DEPRECATED: consider using LocalID or GlobalID, instead. | |
| 451 class DontMangle { | 503 class DontMangle { |
| 452 public: | 504 public: |
| 453 explicit DontMangle(const void* raw_id) | 505 explicit DontMangle(const void* raw_id) |
| 454 : raw_id_(static_cast<unsigned long long>( | 506 : raw_id_(static_cast<unsigned long long>( |
| 455 reinterpret_cast<uintptr_t>(raw_id))) {} | 507 reinterpret_cast<uintptr_t>(raw_id))) {} |
| 456 explicit DontMangle(unsigned long long raw_id) : raw_id_(raw_id) {} | 508 explicit DontMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 457 explicit DontMangle(unsigned long raw_id) : raw_id_(raw_id) {} | 509 explicit DontMangle(unsigned long raw_id) : raw_id_(raw_id) {} |
| 458 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {} | 510 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {} |
| 459 explicit DontMangle(unsigned short raw_id) : raw_id_(raw_id) {} | 511 explicit DontMangle(unsigned short raw_id) : raw_id_(raw_id) {} |
| 460 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {} | 512 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {} |
| 461 explicit DontMangle(long long raw_id) | 513 explicit DontMangle(long long raw_id) |
| 462 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 514 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 463 explicit DontMangle(long raw_id) | 515 explicit DontMangle(long raw_id) |
| 464 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 516 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 465 explicit DontMangle(int raw_id) | 517 explicit DontMangle(int raw_id) |
| 466 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 518 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 467 explicit DontMangle(short raw_id) | 519 explicit DontMangle(short raw_id) |
| 468 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 520 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 469 explicit DontMangle(signed char raw_id) | 521 explicit DontMangle(signed char raw_id) |
| 470 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 522 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 471 unsigned long long raw_id() const { return raw_id_; } | 523 unsigned long long raw_id() const { return raw_id_; } |
| 472 private: | 524 private: |
| 473 unsigned long long raw_id_; | 525 unsigned long long raw_id_; |
| 474 }; | 526 }; |
| 475 | 527 |
| 476 // DEPRECATED: consider using LocalId or GlobalId, instead. | 528 // DEPRECATED: consider using LocalID or GlobalID, instead. |
| 477 class ForceMangle { | 529 class ForceMangle { |
| 478 public: | 530 public: |
| 479 explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} | 531 explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 480 explicit ForceMangle(unsigned long raw_id) : raw_id_(raw_id) {} | 532 explicit ForceMangle(unsigned long raw_id) : raw_id_(raw_id) {} |
| 481 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {} | 533 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {} |
| 482 explicit ForceMangle(unsigned short raw_id) : raw_id_(raw_id) {} | 534 explicit ForceMangle(unsigned short raw_id) : raw_id_(raw_id) {} |
| 483 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {} | 535 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {} |
| 484 explicit ForceMangle(long long raw_id) | 536 explicit ForceMangle(long long raw_id) |
| 485 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 537 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 486 explicit ForceMangle(long raw_id) | 538 explicit ForceMangle(long raw_id) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 512 TraceID(long long raw_id) | 564 TraceID(long long raw_id) |
| 513 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 565 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 514 TraceID(long raw_id) | 566 TraceID(long raw_id) |
| 515 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 567 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 516 TraceID(int raw_id) | 568 TraceID(int raw_id) |
| 517 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 569 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 518 TraceID(short raw_id) | 570 TraceID(short raw_id) |
| 519 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 571 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 520 TraceID(signed char raw_id) | 572 TraceID(signed char raw_id) |
| 521 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 573 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 522 TraceID(LocalId raw_id) : raw_id_(raw_id.raw_id()) { | 574 TraceID(LocalID local_id) : raw_id_(local_id.raw_id()) { |
| 523 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; | 575 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; |
| 524 } | 576 } |
| 525 TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) { | 577 TraceID(GlobalID global_id) : raw_id_(global_id.raw_id()) { |
| 526 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; | 578 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; |
| 527 } | 579 } |
| 528 TraceID(WithScope scoped_id) : scope_(scoped_id.scope()), | 580 TraceID(ScopedID scoped_id) |
| 529 raw_id_(scoped_id.raw_id()), id_flags_(scoped_id.id_flags()) {} | 581 : scope_(scoped_id.scope()), |
| 582 raw_id_(scoped_id.raw_id()), | |
| 583 id_flags_(scoped_id.id_flags()) {} | |
| 584 TraceID(CompositeID composite_id) | |
| 585 : scope_(composite_id.scope()), | |
| 586 has_prefix_(true), | |
| 587 prefix_(composite_id.prefix()), | |
| 588 raw_id_(composite_id.raw_id()), | |
| 589 id_flags_(composite_id.id_flags()) {} | |
| 530 | 590 |
| 591 const char* scope() const { return scope_; } | |
| 592 bool has_prefix() const { return has_prefix_; } | |
| 593 unsigned long long prefix() const { return prefix_; } | |
| 531 unsigned long long raw_id() const { return raw_id_; } | 594 unsigned long long raw_id() const { return raw_id_; } |
| 532 const char* scope() const { return scope_; } | |
| 533 unsigned int id_flags() const { return id_flags_; } | 595 unsigned int id_flags() const { return id_flags_; } |
| 534 | 596 |
| 535 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 597 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 536 AsConvertableToTraceFormat() const; | 598 AsConvertableToTraceFormat() const; |
| 537 | 599 |
| 538 private: | 600 private: |
| 539 const char* scope_ = nullptr; | 601 const char* scope_ = nullptr; |
| 602 bool has_prefix_ = false; | |
| 603 unsigned long long prefix_; | |
| 540 unsigned long long raw_id_; | 604 unsigned long long raw_id_; |
| 541 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; | 605 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; |
| 542 }; | 606 }; |
| 543 | 607 |
| 544 // Simple union to store various types as unsigned long long. | 608 // Simple union to store various types as unsigned long long. |
| 545 union TraceValueUnion { | 609 union TraceValueUnion { |
| 546 bool as_bool; | 610 bool as_bool; |
| 547 unsigned long long as_uint; | 611 unsigned long long as_uint; |
| 548 long long as_int; | 612 long long as_int; |
| 549 double as_double; | 613 double as_double; |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 const char* name_; | 1145 const char* name_; |
| 1082 IDType id_; | 1146 IDType id_; |
| 1083 | 1147 |
| 1084 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1148 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 1085 }; | 1149 }; |
| 1086 | 1150 |
| 1087 } // namespace trace_event | 1151 } // namespace trace_event |
| 1088 } // namespace base | 1152 } // namespace base |
| 1089 | 1153 |
| 1090 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 1154 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| OLD | NEW |