| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 trace_event_trace_id.id_flags(); \ | 369 trace_event_trace_id.id_flags(); \ |
| 370 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 370 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
| 371 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 371 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
| 372 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ | 372 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
| 373 thread_id, timestamp, \ | 373 thread_id, timestamp, \ |
| 374 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 374 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
| 375 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 375 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 376 } \ | 376 } \ |
| 377 } while (0) | 377 } while (0) |
| 378 | 378 |
| 379 // This macro ignores whether the bind_id is local, global, or mangled. | 379 // The linked ID will not be mangled. |
| 380 #define INTERNAL_TRACE_EVENT_ADD_BIND_IDS(category_group, name, id, bind_id, \ | 380 #define INTERNAL_TRACE_EVENT_ADD_LINK_IDS(category_group, name, id1, id2) \ |
| 381 ...) \ | |
| 382 do { \ | 381 do { \ |
| 383 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 382 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 384 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 383 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 385 trace_event_internal::TraceID source_id((id)); \ | 384 trace_event_internal::TraceID source_id((id1)); \ |
| 386 unsigned int source_flags = source_id.id_flags(); \ | 385 unsigned int source_flags = source_id.id_flags(); \ |
| 387 trace_event_internal::TraceID target_id((bind_id)); \ | 386 trace_event_internal::TraceID target_id((id2)); \ |
| 388 if (target_id.scope() == trace_event_internal::kGlobalScope) { \ | 387 trace_event_internal::AddTraceEvent( \ |
| 389 trace_event_internal::AddTraceEvent( \ | 388 TRACE_EVENT_PHASE_LINK_IDS, \ |
| 390 TRACE_EVENT_PHASE_BIND_IDS, \ | 389 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| 391 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 390 name, source_id.scope(), source_id.raw_id(), source_flags, \ |
| 392 name, source_id.scope(), source_id.raw_id(), \ | 391 trace_event_internal::kNoId, \ |
| 393 source_flags, target_id.raw_id(), ##__VA_ARGS__); \ | 392 "linked_id", target_id.AsConvertableToTraceFormat()); \ |
| 394 } else { \ | |
| 395 trace_event_internal::AddTraceEvent( \ | |
| 396 TRACE_EVENT_PHASE_BIND_IDS, \ | |
| 397 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | |
| 398 name, source_id.scope(), source_id.raw_id(), \ | |
| 399 source_flags, target_id.raw_id(), \ | |
| 400 "bind_scope", target_id.scope(), ##__VA_ARGS__); \ | |
| 401 } \ | |
| 402 } \ | 393 } \ |
| 403 } while (0) | 394 } while (0) |
| 404 | 395 |
| 405 // Implementation detail: internal macro to create static category and add | 396 // Implementation detail: internal macro to create static category and add |
| 406 // metadata event if the category is enabled. | 397 // metadata event if the category is enabled. |
| 407 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ | 398 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ |
| 408 do { \ | 399 do { \ |
| 409 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 400 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 410 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 401 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 411 TRACE_EVENT_API_ADD_METADATA_EVENT( \ | 402 TRACE_EVENT_API_ADD_METADATA_EVENT( \ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 440 |
| 450 // Specify these values when the corresponding argument of AddTraceEvent is not | 441 // Specify these values when the corresponding argument of AddTraceEvent is not |
| 451 // used. | 442 // used. |
| 452 const int kZeroNumArgs = 0; | 443 const int kZeroNumArgs = 0; |
| 453 const std::nullptr_t kGlobalScope = nullptr; | 444 const std::nullptr_t kGlobalScope = nullptr; |
| 454 const unsigned long long kNoId = 0; | 445 const unsigned long long kNoId = 0; |
| 455 | 446 |
| 456 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 447 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
| 457 // are by default mangled with the Process ID so that they are unlikely to | 448 // are by default mangled with the Process ID so that they are unlikely to |
| 458 // collide when the same pointer is used on different processes. | 449 // collide when the same pointer is used on different processes. |
| 459 class TraceID { | 450 class BASE_EXPORT TraceID { |
| 460 public: | 451 public: |
| 461 // Can be combined with WithScope. | 452 // Can be combined with WithScope. |
| 462 class LocalId { | 453 class LocalId { |
| 463 public: | 454 public: |
| 464 explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {} | 455 explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 465 unsigned long long raw_id() const { return raw_id_; } | 456 unsigned long long raw_id() const { return raw_id_; } |
| 466 private: | 457 private: |
| 467 unsigned long long raw_id_; | 458 unsigned long long raw_id_; |
| 468 }; | 459 }; |
| 469 | 460 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) { | 566 TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) { |
| 576 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; | 567 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; |
| 577 } | 568 } |
| 578 TraceID(WithScope scoped_id) : scope_(scoped_id.scope()), | 569 TraceID(WithScope scoped_id) : scope_(scoped_id.scope()), |
| 579 raw_id_(scoped_id.raw_id()), id_flags_(scoped_id.id_flags()) {} | 570 raw_id_(scoped_id.raw_id()), id_flags_(scoped_id.id_flags()) {} |
| 580 | 571 |
| 581 unsigned long long raw_id() const { return raw_id_; } | 572 unsigned long long raw_id() const { return raw_id_; } |
| 582 const char* scope() const { return scope_; } | 573 const char* scope() const { return scope_; } |
| 583 unsigned int id_flags() const { return id_flags_; } | 574 unsigned int id_flags() const { return id_flags_; } |
| 584 | 575 |
| 576 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 577 AsConvertableToTraceFormat() const; |
| 578 |
| 585 private: | 579 private: |
| 586 const char* scope_ = nullptr; | 580 const char* scope_ = nullptr; |
| 587 unsigned long long raw_id_; | 581 unsigned long long raw_id_; |
| 588 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; | 582 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; |
| 589 }; | 583 }; |
| 590 | 584 |
| 591 // Simple union to store various types as unsigned long long. | 585 // Simple union to store various types as unsigned long long. |
| 592 union TraceValueUnion { | 586 union TraceValueUnion { |
| 593 bool as_bool; | 587 bool as_bool; |
| 594 unsigned long long as_uint; | 588 unsigned long long as_uint; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 const char* name_; | 1153 const char* name_; |
| 1160 IDType id_; | 1154 IDType id_; |
| 1161 | 1155 |
| 1162 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1156 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 1163 }; | 1157 }; |
| 1164 | 1158 |
| 1165 } // namespace trace_event | 1159 } // namespace trace_event |
| 1166 } // namespace base | 1160 } // namespace base |
| 1167 | 1161 |
| 1168 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 1162 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| OLD | NEW |