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 // This header file defines the set of trace_event macros without specifying | 5 // This header file defines the set of trace_event macros without specifying |
| 6 // how the events actually get collected and stored. If you need to expose trace | 6 // how the events actually get collected and stored. If you need to expose trace |
| 7 // events to some other universe, you can copy-and-paste this file as well as | 7 // events to some other universe, you can copy-and-paste this file as well as |
| 8 // trace_event.h, modifying the macros contained there as necessary for the | 8 // trace_event.h, modifying the macros contained there as necessary for the |
| 9 // target platform. The end result is that multiple libraries can funnel events | 9 // target platform. The end result is that multiple libraries can funnel events |
| 10 // through to a shared trace event collector. | 10 // through to a shared trace event collector. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | 292 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 293 category_group, name, TRACE_EVENT_FLAG_COPY | scope, \ | 293 category_group, name, TRACE_EVENT_FLAG_COPY | scope, \ |
| 294 arg1_name, arg1_val, arg2_name, arg2_val) | 294 arg1_name, arg1_val, arg2_name, arg2_val) |
| 295 | 295 |
| 296 // Sets the current sample state to the given category and name (both must be | 296 // Sets the current sample state to the given category and name (both must be |
| 297 // constant strings). These states are intended for a sampling profiler. | 297 // constant strings). These states are intended for a sampling profiler. |
| 298 // Implementation note: we store category and name together because we don't | 298 // Implementation note: we store category and name together because we don't |
| 299 // want the inconsistency/expense of storing two pointers. | 299 // want the inconsistency/expense of storing two pointers. |
| 300 // |thread_bucket| is [0..2] and is used to statically isolate samples in one | 300 // |thread_bucket| is [0..2] and is used to statically isolate samples in one |
| 301 // thread from others. | 301 // thread from others. |
| 302 #define TRACE_EVENT_SAMPLE_STATE(thread_bucket, category, name) \ | 302 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ |
| 303 TRACE_EVENT_API_ATOMIC_STORE( \ | 303 bucket_number, category, name) \ |
| 304 TRACE_EVENT_API_THREAD_BUCKET(thread_bucket), \ | 304 TRACE_EVENT_API_ATOMIC_STORE( \ |
| 305 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category "\0" name)); | 305 TRACE_EVENT_API_THREAD_BUCKET(bucket_number), \ |
| 306 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category "\0" name)); | |
| 307 | |
| 308 // Creates a scope of a sampling state of the given bucket. | |
| 309 // | |
| 310 // { // The sampling state is set within this scope. | |
| 311 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); | |
|
nduca
2013/07/03 09:54:34
bikeshed: how about TRACE_EVENT_SCOPED_SET_SAMPLIN
haraken
2013/07/04 02:03:16
Done.
| |
| 312 // ...; | |
| 313 // } | |
| 314 #define TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET( \ | |
| 315 bucket_number, category, name) \ | |
| 316 trace_event_internal::TraceEventSamplingStateScope<bucket_number> \ | |
| 317 traceEventSamplingScope(category "\0" name); | |
| 318 | |
| 319 // Returns a current sampling state of the current scope of the given bucket. | |
| 320 #define TRACE_EVENT_SAMPLING_STATE_SCOPE_CURRENT_FOR_BUCKET(bucket_number) \ | |
| 321 trace_event_internal::TraceEventSamplingStateScope<bucket_number>::Current() | |
| 322 | |
| 323 // Updates a sampling state of the current scope of the given bucket. | |
| 324 // You should use this macro only when the overhead of | |
| 325 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET is not acceptable. | |
| 326 #define TRACE_EVENT_SAMPLING_STATE_SCOPE_SET_CURRENT_FOR_BUCKET( \ | |
| 327 bucket_number, category, name) \ | |
| 328 trace_event_internal:: \ | |
| 329 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) | |
| 330 | |
| 331 // Syntactic sugars for the sampling tracing in the main thread. | |
| 332 #define TRACE_EVENT_SAMPLING_STATE_SCOPE(category, name) \ | |
| 333 TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, category, name) | |
| 334 #define TRACE_EVENT_SAMPLING_STATE_SCOPE_CURRENT() \ | |
| 335 TRACE_EVENT_SAMPLING_STATE_SCOPE_CURRENT_FOR_BUCKET(0) | |
| 336 #define TRACE_EVENT_SAMPLING_STATE_SCOPE_SET_CURRENT(category, name) \ | |
| 337 TRACE_EVENT_SAMPLING_STATE_SCOPE_SET_CURRENT_FOR_BUCKET(0, category, name) | |
| 338 | |
| 306 | 339 |
| 307 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 | 340 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
| 308 // associated arguments. If the category is not enabled, then this | 341 // associated arguments. If the category is not enabled, then this |
| 309 // does nothing. | 342 // does nothing. |
| 310 // - category and name strings must have application lifetime (statics or | 343 // - category and name strings must have application lifetime (statics or |
| 311 // literals). They may not include " chars. | 344 // literals). They may not include " chars. |
| 312 #define TRACE_EVENT_BEGIN0(category_group, name) \ | 345 #define TRACE_EVENT_BEGIN0(category_group, name) \ |
| 313 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 346 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 314 category_group, name, TRACE_EVENT_FLAG_NONE) | 347 category_group, name, TRACE_EVENT_FLAG_NONE) |
| 315 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \ | 348 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \ |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 | 781 |
| 749 // Defines atomic operations used internally by the tracing system. | 782 // Defines atomic operations used internally by the tracing system. |
| 750 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord | 783 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord |
| 751 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) | 784 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) |
| 752 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ | 785 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ |
| 753 base::subtle::NoBarrier_Store(&(var), (value)) | 786 base::subtle::NoBarrier_Store(&(var), (value)) |
| 754 | 787 |
| 755 // Defines visibility for classes in trace_event.h | 788 // Defines visibility for classes in trace_event.h |
| 756 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT | 789 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT |
| 757 | 790 |
| 758 // Not supported in split-dll build. http://crbug.com/237249 | 791 // Not supported in split-dll build. http://crbug.com/256965 |
| 759 #if !defined(CHROME_SPLIT_DLL) | 792 #if !defined(CHROME_SPLIT_DLL) |
| 760 // The thread buckets for the sampling profiler. | 793 // The thread buckets for the sampling profiler. |
| 761 TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state0; | 794 TRACE_EVENT_API_CLASS_EXPORT extern \ |
| 762 TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state1; | 795 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; |
| 763 TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state2; | 796 |
| 764 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ | 797 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ |
| 765 g_trace_state##thread_bucket | 798 g_trace_state[thread_bucket] |
| 799 | |
| 766 #endif | 800 #endif |
| 767 | 801 |
| 768 //////////////////////////////////////////////////////////////////////////////// | 802 //////////////////////////////////////////////////////////////////////////////// |
| 769 | 803 |
| 770 // Implementation detail: trace event macros create temporary variables | 804 // Implementation detail: trace event macros create temporary variables |
| 771 // to keep instrumentation overhead low. These macros give each temporary | 805 // to keep instrumentation overhead low. These macros give each temporary |
| 772 // variable a unique name based on the line number to prevent name collissions. | 806 // variable a unique name based on the line number to prevent name collissions. |
| 773 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 807 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
| 774 trace_event_unique_##a##b | 808 trace_event_unique_##a##b |
| 775 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 809 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 INTERNAL_TRACE_EVENT_UID(profileScope)( \ | 1466 INTERNAL_TRACE_EVENT_UID(profileScope)( \ |
| 1433 &INTERNAL_TRACE_EVENT_UID(atomic), name); \ | 1467 &INTERNAL_TRACE_EVENT_UID(atomic), name); \ |
| 1434 | 1468 |
| 1435 // This macro generates less code then TRACE_EVENT0 but is also | 1469 // This macro generates less code then TRACE_EVENT0 but is also |
| 1436 // slower to execute when tracing is off. It should generally only be | 1470 // slower to execute when tracing is off. It should generally only be |
| 1437 // used with code that is seldom executed or conditionally executed | 1471 // used with code that is seldom executed or conditionally executed |
| 1438 // when debugging. | 1472 // when debugging. |
| 1439 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ | 1473 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ |
| 1440 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category_group, name) | 1474 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category_group, name) |
| 1441 | 1475 |
| 1476 // TraceEventSamplingStateScope records the current sampling state | |
| 1477 // and sets a new sampling state. When the scope exists, it restores | |
| 1478 // the sampling state having recorded. | |
| 1479 template<size_t BucketNumber> | |
| 1480 class TraceEventSamplingStateScope { | |
| 1481 public: | |
| 1482 TraceEventSamplingStateScope(const char* category_and_name) { | |
| 1483 previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current(); | |
| 1484 TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name); | |
| 1485 } | |
| 1486 | |
| 1487 ~TraceEventSamplingStateScope() { | |
| 1488 TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_); | |
| 1489 } | |
| 1490 | |
| 1491 static inline const char* Current() { | |
| 1492 return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( | |
| 1493 g_trace_state[BucketNumber])); | |
| 1494 } | |
| 1495 | |
| 1496 static inline void Set(const char* category_and_name) { | |
| 1497 TRACE_EVENT_API_ATOMIC_STORE( | |
| 1498 g_trace_state[BucketNumber], | |
| 1499 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( | |
| 1500 const_cast<char*>(category_and_name))); | |
| 1501 } | |
| 1502 | |
| 1503 private: | |
| 1504 const char* previous_state_; | |
| 1505 }; | |
| 1506 | |
| 1442 } // namespace trace_event_internal | 1507 } // namespace trace_event_internal |
| 1443 | 1508 |
| 1444 namespace base { | 1509 namespace base { |
| 1445 namespace debug { | 1510 namespace debug { |
| 1446 | 1511 |
| 1447 template<typename IDType> class TraceScopedTrackableObject { | 1512 template<typename IDType> class TraceScopedTrackableObject { |
| 1448 public: | 1513 public: |
| 1449 TraceScopedTrackableObject(const char* category_group, const char* name, | 1514 TraceScopedTrackableObject(const char* category_group, const char* name, |
| 1450 IDType id) | 1515 IDType id) |
| 1451 : category_group_(category_group), | 1516 : category_group_(category_group), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1467 const char* name_; | 1532 const char* name_; |
| 1468 IDType id_; | 1533 IDType id_; |
| 1469 | 1534 |
| 1470 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1535 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 1471 }; | 1536 }; |
| 1472 | 1537 |
| 1473 } // namespace debug | 1538 } // namespace debug |
| 1474 } // namespace base | 1539 } // namespace base |
| 1475 | 1540 |
| 1476 #endif /* BASE_DEBUG_TRACE_EVENT_H_ */ | 1541 #endif /* BASE_DEBUG_TRACE_EVENT_H_ */ |
| OLD | NEW |