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_internal:: \ |
305 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(category "\0" name)); | 305 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) |
| 306 |
| 307 // Returns a current sampling state of the given bucket. |
| 308 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \ |
| 309 trace_event_internal::TraceEventSamplingStateScope<bucket_number>::Current() |
| 310 |
| 311 // Creates a scope of a sampling state of the given bucket. |
| 312 // |
| 313 // { // The sampling state is set within this scope. |
| 314 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); |
| 315 // ...; |
| 316 // } |
| 317 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \ |
| 318 bucket_number, category, name) \ |
| 319 trace_event_internal::TraceEventSamplingStateScope<bucket_number> \ |
| 320 traceEventSamplingScope(category "\0" name); |
| 321 |
| 322 // Syntactic sugars for the sampling tracing in the main thread. |
| 323 #define TRACE_EVENT_SCOPED_SAMPLING_STATE(category, name) \ |
| 324 TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(0, category, name) |
| 325 #define TRACE_EVENT_GET_SAMPLING_STATE() \ |
| 326 TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(0) |
| 327 #define TRACE_EVENT_SET_SAMPLING_STATE(category, name) \ |
| 328 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(0, category, name) |
| 329 |
306 | 330 |
307 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 | 331 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
308 // associated arguments. If the category is not enabled, then this | 332 // associated arguments. If the category is not enabled, then this |
309 // does nothing. | 333 // does nothing. |
310 // - category and name strings must have application lifetime (statics or | 334 // - category and name strings must have application lifetime (statics or |
311 // literals). They may not include " chars. | 335 // literals). They may not include " chars. |
312 #define TRACE_EVENT_BEGIN0(category_group, name) \ | 336 #define TRACE_EVENT_BEGIN0(category_group, name) \ |
313 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 337 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
314 category_group, name, TRACE_EVENT_FLAG_NONE) | 338 category_group, name, TRACE_EVENT_FLAG_NONE) |
315 #define TRACE_EVENT_BEGIN1(category_group, name, arg1_name, arg1_val) \ | 339 #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 | 772 |
749 // Defines atomic operations used internally by the tracing system. | 773 // Defines atomic operations used internally by the tracing system. |
750 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord | 774 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord |
751 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) | 775 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) |
752 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ | 776 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ |
753 base::subtle::NoBarrier_Store(&(var), (value)) | 777 base::subtle::NoBarrier_Store(&(var), (value)) |
754 | 778 |
755 // Defines visibility for classes in trace_event.h | 779 // Defines visibility for classes in trace_event.h |
756 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT | 780 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT |
757 | 781 |
758 // Not supported in split-dll build. http://crbug.com/237249 | 782 // Not supported in split-dll build. http://crbug.com/256965 |
759 #if !defined(CHROME_SPLIT_DLL) | 783 #if !defined(CHROME_SPLIT_DLL) |
760 // The thread buckets for the sampling profiler. | 784 // The thread buckets for the sampling profiler. |
761 TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state0; | 785 TRACE_EVENT_API_CLASS_EXPORT extern \ |
762 TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state1; | 786 TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; |
763 TRACE_EVENT_API_CLASS_EXPORT extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state2; | 787 |
764 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ | 788 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \ |
765 g_trace_state##thread_bucket | 789 g_trace_state[thread_bucket] |
| 790 |
766 #endif | 791 #endif |
767 | 792 |
768 //////////////////////////////////////////////////////////////////////////////// | 793 //////////////////////////////////////////////////////////////////////////////// |
769 | 794 |
770 // Implementation detail: trace event macros create temporary variables | 795 // Implementation detail: trace event macros create temporary variables |
771 // to keep instrumentation overhead low. These macros give each temporary | 796 // to keep instrumentation overhead low. These macros give each temporary |
772 // variable a unique name based on the line number to prevent name collissions. | 797 // variable a unique name based on the line number to prevent name collissions. |
773 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 798 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
774 trace_event_unique_##a##b | 799 trace_event_unique_##a##b |
775 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 800 #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)( \ | 1457 INTERNAL_TRACE_EVENT_UID(profileScope)( \ |
1433 &INTERNAL_TRACE_EVENT_UID(atomic), name); \ | 1458 &INTERNAL_TRACE_EVENT_UID(atomic), name); \ |
1434 | 1459 |
1435 // This macro generates less code then TRACE_EVENT0 but is also | 1460 // This macro generates less code then TRACE_EVENT0 but is also |
1436 // slower to execute when tracing is off. It should generally only be | 1461 // slower to execute when tracing is off. It should generally only be |
1437 // used with code that is seldom executed or conditionally executed | 1462 // used with code that is seldom executed or conditionally executed |
1438 // when debugging. | 1463 // when debugging. |
1439 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ | 1464 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ |
1440 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category_group, name) | 1465 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category_group, name) |
1441 | 1466 |
| 1467 // TraceEventSamplingStateScope records the current sampling state |
| 1468 // and sets a new sampling state. When the scope exists, it restores |
| 1469 // the sampling state having recorded. |
| 1470 template<size_t BucketNumber> |
| 1471 class TraceEventSamplingStateScope { |
| 1472 public: |
| 1473 TraceEventSamplingStateScope(const char* category_and_name) { |
| 1474 previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current(); |
| 1475 TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name); |
| 1476 } |
| 1477 |
| 1478 ~TraceEventSamplingStateScope() { |
| 1479 TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_); |
| 1480 } |
| 1481 |
| 1482 static inline const char* Current() { |
| 1483 // Not supported in split-dll build. http://crbug.com/256965 |
| 1484 #if !defined(CHROME_SPLIT_DLL) |
| 1485 return reinterpret_cast<const char*>(TRACE_EVENT_API_ATOMIC_LOAD( |
| 1486 g_trace_state[BucketNumber])); |
| 1487 #else |
| 1488 return NULL; |
| 1489 #endif |
| 1490 } |
| 1491 |
| 1492 static inline void Set(const char* category_and_name) { |
| 1493 // Not supported in split-dll build. http://crbug.com/256965 |
| 1494 #if !defined(CHROME_SPLIT_DLL) |
| 1495 TRACE_EVENT_API_ATOMIC_STORE( |
| 1496 g_trace_state[BucketNumber], |
| 1497 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( |
| 1498 const_cast<char*>(category_and_name))); |
| 1499 #endif |
| 1500 } |
| 1501 |
| 1502 private: |
| 1503 const char* previous_state_; |
| 1504 }; |
| 1505 |
1442 } // namespace trace_event_internal | 1506 } // namespace trace_event_internal |
1443 | 1507 |
1444 namespace base { | 1508 namespace base { |
1445 namespace debug { | 1509 namespace debug { |
1446 | 1510 |
1447 template<typename IDType> class TraceScopedTrackableObject { | 1511 template<typename IDType> class TraceScopedTrackableObject { |
1448 public: | 1512 public: |
1449 TraceScopedTrackableObject(const char* category_group, const char* name, | 1513 TraceScopedTrackableObject(const char* category_group, const char* name, |
1450 IDType id) | 1514 IDType id) |
1451 : category_group_(category_group), | 1515 : category_group_(category_group), |
(...skipping 15 matching lines...) Expand all Loading... |
1467 const char* name_; | 1531 const char* name_; |
1468 IDType id_; | 1532 IDType id_; |
1469 | 1533 |
1470 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1534 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
1471 }; | 1535 }; |
1472 | 1536 |
1473 } // namespace debug | 1537 } // namespace debug |
1474 } // namespace base | 1538 } // namespace base |
1475 | 1539 |
1476 #endif /* BASE_DEBUG_TRACE_EVENT_H_ */ | 1540 #endif /* BASE_DEBUG_TRACE_EVENT_H_ */ |
OLD | NEW |