| 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. |
| 11 | 11 |
| 12 #include <stddef.h> | 12 #include <stddef.h> |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/atomicops.h" | 17 #include "base/atomicops.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "base/trace_event/common/trace_event_common.h" | 20 #include "base/trace_event/common/trace_event_common.h" |
| 21 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 21 #include "base/trace_event/heap_profiler.h" |
| 22 #include "base/trace_event/trace_event_system_stats_monitor.h" | 22 #include "base/trace_event/trace_event_system_stats_monitor.h" |
| 23 #include "base/trace_event/trace_log.h" | 23 #include "base/trace_event/trace_log.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 | 25 |
| 26 // By default, const char* argument values are assumed to have long-lived scope | 26 // By default, const char* argument values are assumed to have long-lived scope |
| 27 // and will not be copied. Use this macro to force a const char* to be copied. | 27 // and will not be copied. Use this macro to force a const char* to be copied. |
| 28 #define TRACE_STR_COPY(str) \ | 28 #define TRACE_STR_COPY(str) \ |
| 29 trace_event_internal::TraceStringWithCopy(str) | 29 trace_event_internal::TraceStringWithCopy(str) |
| 30 | 30 |
| 31 // By default, uint64_t ID argument values are not mangled with the Process ID | 31 // By default, uint64_t ID argument values are not mangled with the Process ID |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // Defines visibility for classes in trace_event.h | 204 // Defines visibility for classes in trace_event.h |
| 205 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT | 205 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT |
| 206 | 206 |
| 207 // The thread buckets for the sampling profiler. | 207 // The thread buckets for the sampling profiler. |
| 208 TRACE_EVENT_API_CLASS_EXPORT extern \ | 208 TRACE_EVENT_API_CLASS_EXPORT extern \ |
| 209 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; | 209 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; |
| 210 | 210 |
| 211 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ | 211 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ |
| 212 g_trace_state[thread_bucket] | 212 g_trace_state[thread_bucket] |
| 213 | 213 |
| 214 // Scoped tracker for task execution context in the heap profiler. | |
| 215 #define TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT \ | |
| 216 trace_event_internal::ScopedTaskExecutionEvent | |
| 217 | |
| 218 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
| 219 | 215 |
| 220 // Implementation detail: trace event macros create temporary variables | 216 // Implementation detail: trace event macros create temporary variables |
| 221 // to keep instrumentation overhead low. These macros give each temporary | 217 // to keep instrumentation overhead low. These macros give each temporary |
| 222 // variable a unique name based on the line number to prevent name collisions. | 218 // variable a unique name based on the line number to prevent name collisions. |
| 223 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 219 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
| 224 trace_event_unique_##a##b | 220 trace_event_unique_##a##b |
| 225 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 221 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
| 226 INTERNAL_TRACE_EVENT_UID3(a,b) | 222 INTERNAL_TRACE_EVENT_UID3(a,b) |
| 227 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 223 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 private: \ | 376 private: \ |
| 381 uint64_t cid_; \ | 377 uint64_t cid_; \ |
| 382 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ | 378 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ |
| 383 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 379 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| 384 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 380 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| 385 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 381 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| 386 }; \ | 382 }; \ |
| 387 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 383 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| 388 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); | 384 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); |
| 389 | 385 |
| 386 // Implementation detail: internal macro to trace a task execution with the |
| 387 // location where it was posted from. |
| 388 #define INTERNAL_TRACE_TASK_EXECUTION(run_function, task) \ |
| 389 TRACE_EVENT2("toplevel", run_function, "src_file", \ |
| 390 (task).posted_from.file_name(), "src_func", \ |
| 391 (task).posted_from.function_name()); \ |
| 392 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION INTERNAL_TRACE_EVENT_UID( \ |
| 393 task_event)((task).posted_from.file_name()); |
| 394 |
| 390 namespace trace_event_internal { | 395 namespace trace_event_internal { |
| 391 | 396 |
| 392 // Specify these values when the corresponding argument of AddTraceEvent is not | 397 // Specify these values when the corresponding argument of AddTraceEvent is not |
| 393 // used. | 398 // used. |
| 394 const int kZeroNumArgs = 0; | 399 const int kZeroNumArgs = 0; |
| 395 const std::nullptr_t kGlobalScope = nullptr; | 400 const std::nullptr_t kGlobalScope = nullptr; |
| 396 const unsigned long long kNoId = 0; | 401 const unsigned long long kNoId = 0; |
| 397 | 402 |
| 398 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 403 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
| 399 // are by default mangled with the Process ID so that they are unlikely to | 404 // are by default mangled with the Process ID so that they are unlikely to |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 TRACE_EVENT_API_ATOMIC_STORE( | 1048 TRACE_EVENT_API_ATOMIC_STORE( |
| 1044 g_trace_state[BucketNumber], | 1049 g_trace_state[BucketNumber], |
| 1045 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( | 1050 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( |
| 1046 const_cast<char*>(category_and_name))); | 1051 const_cast<char*>(category_and_name))); |
| 1047 } | 1052 } |
| 1048 | 1053 |
| 1049 private: | 1054 private: |
| 1050 const char* previous_state_; | 1055 const char* previous_state_; |
| 1051 }; | 1056 }; |
| 1052 | 1057 |
| 1053 // ScopedTaskExecutionEvent records the current task's context in the heap | |
| 1054 // profiler. | |
| 1055 class ScopedTaskExecutionEvent { | |
| 1056 public: | |
| 1057 explicit ScopedTaskExecutionEvent(const char* task_context) | |
| 1058 : context_(task_context) { | |
| 1059 using base::trace_event::AllocationContextTracker; | |
| 1060 if (UNLIKELY( | |
| 1061 AllocationContextTracker::capture_mode() != | |
| 1062 AllocationContextTracker::CaptureMode::DISABLED)) { | |
| 1063 AllocationContextTracker::GetInstanceForCurrentThread() | |
| 1064 ->PushCurrentTaskContext(context_); | |
| 1065 } | |
| 1066 } | |
| 1067 | |
| 1068 ~ScopedTaskExecutionEvent() { | |
| 1069 using base::trace_event::AllocationContextTracker; | |
| 1070 if (UNLIKELY( | |
| 1071 AllocationContextTracker::capture_mode() != | |
| 1072 AllocationContextTracker::CaptureMode::DISABLED)) { | |
| 1073 AllocationContextTracker::GetInstanceForCurrentThread() | |
| 1074 ->PopCurrentTaskContext(context_); | |
| 1075 } | |
| 1076 } | |
| 1077 | |
| 1078 private: | |
| 1079 const char* context_; | |
| 1080 }; | |
| 1081 | |
| 1082 } // namespace trace_event_internal | 1058 } // namespace trace_event_internal |
| 1083 | 1059 |
| 1084 namespace base { | 1060 namespace base { |
| 1085 namespace trace_event { | 1061 namespace trace_event { |
| 1086 | 1062 |
| 1087 template<typename IDType> class TraceScopedTrackableObject { | 1063 template<typename IDType> class TraceScopedTrackableObject { |
| 1088 public: | 1064 public: |
| 1089 TraceScopedTrackableObject(const char* category_group, const char* name, | 1065 TraceScopedTrackableObject(const char* category_group, const char* name, |
| 1090 IDType id) | 1066 IDType id) |
| 1091 : category_group_(category_group), | 1067 : category_group_(category_group), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1107 const char* name_; | 1083 const char* name_; |
| 1108 IDType id_; | 1084 IDType id_; |
| 1109 | 1085 |
| 1110 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1086 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 1111 }; | 1087 }; |
| 1112 | 1088 |
| 1113 } // namespace trace_event | 1089 } // namespace trace_event |
| 1114 } // namespace base | 1090 } // namespace base |
| 1115 | 1091 |
| 1116 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 1092 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| OLD | NEW |