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 is designed to give you trace_event macros without specifying | 5 // This header is designed to give you 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 // event to some other universe, you can copy-and-paste this file, | 7 // event to some other universe, you can copy-and-paste this file, |
| 8 // implement the TRACE_EVENT_API macros, and do any other necessary fixup for | 8 // implement the TRACE_EVENT_API macros, and do any other necessary fixup for |
| 9 // the target platform. The end result is that multiple libraries can funnel | 9 // the target platform. The end result is that multiple libraries can funnel |
| 10 // events through to a shared trace event collector. | 10 // events through to a shared trace event collector. |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 category, name, TRACE_EVENT_FLAG_COPY) | 258 category, name, TRACE_EVENT_FLAG_COPY) |
| 259 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ | 259 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ |
| 260 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 260 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 261 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | 261 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
| 262 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ | 262 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ |
| 263 arg2_name, arg2_val) \ | 263 arg2_name, arg2_val) \ |
| 264 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 264 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 265 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | 265 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| 266 arg2_name, arg2_val) | 266 arg2_name, arg2_val) |
| 267 | 267 |
| 268 // Similar to TRACE_EVENT_BEGINx but allowing a custom |thread_name| and | |
| 269 // a custom |at| timestamp to be provided. | |
| 270 #define TRACE_RAW_EVENT_BEGIN_AT0(category, thread_name, name, at) \ | |
| 271 INTERNAL_TRACE_RAW_EVENT_ADD_AT(TRACE_EVENT_PHASE_BEGIN, \ | |
| 272 category, thread_name, name, at, TRACE_EVENT_FLAG_NONE) | |
| 273 | |
| 268 // Records a single END event for "name" immediately. If the category | 274 // Records a single END event for "name" immediately. If the category |
| 269 // is not enabled, then this does nothing. | 275 // is not enabled, then this does nothing. |
| 270 // - category and name strings must have application lifetime (statics or | 276 // - category and name strings must have application lifetime (statics or |
| 271 // literals). They may not include " chars. | 277 // literals). They may not include " chars. |
| 272 #define TRACE_EVENT_END0(category, name) \ | 278 #define TRACE_EVENT_END0(category, name) \ |
| 273 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 279 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 274 category, name, TRACE_EVENT_FLAG_NONE) | 280 category, name, TRACE_EVENT_FLAG_NONE) |
| 275 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ | 281 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ |
| 276 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 282 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 277 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | 283 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) |
| 278 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ | 284 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ |
| 279 arg2_name, arg2_val) \ | 285 arg2_name, arg2_val) \ |
| 280 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 286 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 281 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | 287 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| 282 arg2_name, arg2_val) | 288 arg2_name, arg2_val) |
| 283 #define TRACE_EVENT_COPY_END0(category, name) \ | 289 #define TRACE_EVENT_COPY_END0(category, name) \ |
| 284 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 290 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 285 category, name, TRACE_EVENT_FLAG_COPY) | 291 category, name, TRACE_EVENT_FLAG_COPY) |
| 286 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ | 292 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ |
| 287 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 293 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 288 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | 294 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
| 289 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ | 295 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ |
| 290 arg2_name, arg2_val) \ | 296 arg2_name, arg2_val) \ |
| 291 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 297 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 292 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | 298 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| 293 arg2_name, arg2_val) | 299 arg2_name, arg2_val) |
| 294 | 300 |
| 301 // Similar to TRACE_EVENT_ENDx but allowing a custom |thread_name| and | |
| 302 // a custom |at| timestamp to be provided. | |
| 303 #define TRACE_RAW_EVENT_END_AT0(category, thread_name, name, at) \ | |
| 304 INTERNAL_TRACE_RAW_EVENT_ADD_AT(TRACE_EVENT_PHASE_END, \ | |
| 305 category, thread_name, name, at, TRACE_EVENT_FLAG_NONE) | |
| 306 | |
| 307 // Adds trace BEGIN and END events for the provided |start| and |end| times. | |
| 308 #define TRACE_RAW_EVENT_BETWEEN0(category, thread_name, name, start, end) \ | |
|
dsinclair
2012/11/06 16:25:46
This was added purely for convenience. At the poin
| |
| 309 TRACE_RAW_EVENT_BEGIN_AT0(category, thread_name, name, start); \ | |
| 310 TRACE_RAW_EVENT_END_AT0(category, thread_name, name, end) | |
| 311 | |
| 295 // Time threshold event: | 312 // Time threshold event: |
| 296 // Only record the event if the duration is greater than the specified | 313 // Only record the event if the duration is greater than the specified |
| 297 // threshold_us (time in microseconds). | 314 // threshold_us (time in microseconds). |
| 298 // Records a pair of begin and end events called "name" for the current | 315 // Records a pair of begin and end events called "name" for the current |
| 299 // scope, with 0, 1 or 2 associated arguments. If the category is not | 316 // scope, with 0, 1 or 2 associated arguments. If the category is not |
| 300 // enabled, then this does nothing. | 317 // enabled, then this does nothing. |
| 301 // - category and name strings must have application lifetime (statics or | 318 // - category and name strings must have application lifetime (statics or |
| 302 // literals). They may not include " chars. | 319 // literals). They may not include " chars. |
| 303 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ | 320 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ |
| 304 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) | 321 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 base::debug::TraceLog::GetInstance()->AddTraceEvent | 615 base::debug::TraceLog::GetInstance()->AddTraceEvent |
| 599 | 616 |
| 600 // Checks if Android ATrace is enabled. | 617 // Checks if Android ATrace is enabled. |
| 601 #if defined(OS_ANDROID) | 618 #if defined(OS_ANDROID) |
| 602 #define TRACE_EVENT_API_IS_ATRACE_ENABLED() \ | 619 #define TRACE_EVENT_API_IS_ATRACE_ENABLED() \ |
| 603 base::debug::TraceLog::IsATraceEnabled() | 620 base::debug::TraceLog::IsATraceEnabled() |
| 604 #else | 621 #else |
| 605 #define TRACE_EVENT_API_IS_ATRACE_ENABLED() false | 622 #define TRACE_EVENT_API_IS_ATRACE_ENABLED() false |
| 606 #endif | 623 #endif |
| 607 | 624 |
| 625 // Add a trace event to the platform tracing system. Returns thresholdBeginId | |
|
dsinclair
2012/11/06 16:25:46
If this isn't part of the API then I'm not going t
| |
| 626 // for use in a corresponding end TRACE_EVENT_API_ADD_TRACE_RAW_EVENT call. | |
| 627 // int TRACE_EVENT_API_ADD_TRACE_RAW_EVENT( | |
| 628 // char phase, | |
| 629 // const unsigned char* category_enabled, | |
| 630 // const char* thread_name, | |
| 631 // const char* name, | |
| 632 // int64 timestamp, | |
| 633 // unsigned long long id, | |
| 634 // int num_args, | |
| 635 // const char** arg_names, | |
| 636 // const unsigned char* arg_types, | |
| 637 // const unsigned long long* arg_values, | |
| 638 // int threshold_begin_id, | |
| 639 // long long threshold, | |
| 640 // unsigned char flags) | |
| 641 #define TRACE_EVENT_API_ADD_TRACE_RAW_EVENT \ | |
| 642 base::debug::TraceLog::GetInstance()->AddTraceRawEvent | |
| 643 | |
| 608 //////////////////////////////////////////////////////////////////////////////// | 644 //////////////////////////////////////////////////////////////////////////////// |
| 609 | 645 |
| 610 // Implementation detail: trace event macros create temporary variables | 646 // Implementation detail: trace event macros create temporary variables |
| 611 // to keep instrumentation overhead low. These macros give each temporary | 647 // to keep instrumentation overhead low. These macros give each temporary |
| 612 // variable a unique name based on the line number to prevent name collissions. | 648 // variable a unique name based on the line number to prevent name collissions. |
| 613 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 649 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
| 614 trace_event_unique_##a##b | 650 trace_event_unique_##a##b |
| 615 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 651 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
| 616 INTERNAL_TRACE_EVENT_UID3(a,b) | 652 INTERNAL_TRACE_EVENT_UID3(a,b) |
| 617 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 653 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 644 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ | 680 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ |
| 645 do { \ | 681 do { \ |
| 646 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 682 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 647 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \ | 683 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \ |
| 648 trace_event_internal::AddTraceEvent( \ | 684 trace_event_internal::AddTraceEvent( \ |
| 649 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ | 685 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
| 650 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ | 686 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ |
| 651 } \ | 687 } \ |
| 652 } while (0) | 688 } while (0) |
| 653 | 689 |
| 690 // Implementation detail: internal macro to create static category and add | |
| 691 // event if the category is enabled. | |
| 692 #define INTERNAL_TRACE_RAW_EVENT_ADD_AT(phase, category, thread_name, name, \ | |
| 693 at, flags, ...) \ | |
| 694 do { \ | |
| 695 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | |
| 696 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | |
| 697 trace_event_internal::AddTraceRawEvent( \ | |
| 698 phase, INTERNAL_TRACE_EVENT_UID(catstatic), thread_name, name, \ | |
| 699 at, trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ | |
| 700 } \ | |
| 701 } while (0) | |
| 702 | |
| 654 // Implementation detail: internal macro to create static category and add begin | 703 // Implementation detail: internal macro to create static category and add begin |
| 655 // event if the category is enabled. Also adds the end event when the scope | 704 // event if the category is enabled. Also adds the end event when the scope |
| 656 // ends. | 705 // ends. |
| 657 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ | 706 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
| 658 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 707 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 659 trace_event_internal::TraceEndOnScopeClose \ | 708 trace_event_internal::TraceEndOnScopeClose \ |
| 660 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 709 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| 661 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \ | 710 if (INTERNAL_TRACE_EVENT_IS_ATRACE_OR_CATEGORY_ENABLED()) { \ |
| 662 trace_event_internal::AddTraceEvent( \ | 711 trace_event_internal::AddTraceEvent( \ |
| 663 TRACE_EVENT_PHASE_BEGIN, \ | 712 TRACE_EVENT_PHASE_BEGIN, \ |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 unsigned char arg_types[2]; | 985 unsigned char arg_types[2]; |
| 937 unsigned long long arg_values[2]; | 986 unsigned long long arg_values[2]; |
| 938 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 987 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
| 939 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 988 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
| 940 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 989 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 941 phase, category_enabled, name, id, | 990 phase, category_enabled, name, id, |
| 942 num_args, arg_names, arg_types, arg_values, | 991 num_args, arg_names, arg_types, arg_values, |
| 943 kNoThreshholdBeginId, kNoThresholdValue, flags); | 992 kNoThreshholdBeginId, kNoThresholdValue, flags); |
| 944 } | 993 } |
| 945 | 994 |
| 995 static inline int AddTraceRawEvent(char phase, | |
| 996 const unsigned char* category_enabled, | |
| 997 const char* thread_name, | |
| 998 const char* name, | |
| 999 int64 timestamp, | |
| 1000 unsigned long long id, | |
| 1001 unsigned char flags) { | |
| 1002 return TRACE_EVENT_API_ADD_TRACE_RAW_EVENT( | |
| 1003 phase, category_enabled, thread_name, name, timestamp, id, kZeroNumArgs, | |
| 1004 NULL, NULL, NULL, kNoThreshholdBeginId, kNoThresholdValue, flags); | |
| 1005 } | |
| 1006 | |
| 946 // Used by TRACE_EVENTx macro. Do not use directly. | 1007 // Used by TRACE_EVENTx macro. Do not use directly. |
| 947 class BASE_EXPORT TraceEndOnScopeClose { | 1008 class BASE_EXPORT TraceEndOnScopeClose { |
| 948 public: | 1009 public: |
| 949 // Note: members of data_ intentionally left uninitialized. See Initialize. | 1010 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 950 TraceEndOnScopeClose() : p_data_(NULL) {} | 1011 TraceEndOnScopeClose() : p_data_(NULL) {} |
| 951 ~TraceEndOnScopeClose() { | 1012 ~TraceEndOnScopeClose() { |
| 952 if (p_data_) | 1013 if (p_data_) |
| 953 AddEventIfEnabled(); | 1014 AddEventIfEnabled(); |
| 954 } | 1015 } |
| 955 | 1016 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 const char* name; | 1066 const char* name; |
| 1006 int threshold_begin_id; | 1067 int threshold_begin_id; |
| 1007 }; | 1068 }; |
| 1008 Data* p_data_; | 1069 Data* p_data_; |
| 1009 Data data_; | 1070 Data data_; |
| 1010 }; | 1071 }; |
| 1011 | 1072 |
| 1012 } // namespace trace_event_internal | 1073 } // namespace trace_event_internal |
| 1013 | 1074 |
| 1014 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 1075 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |