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_EVENT_COPY_BEGIN_EXPLICIT0(category, name, id, at) \ | |
|
nduca
2012/12/04 05:09:38
at->ts?
we're not using a custom |thread_name| an
dsinclair
2012/12/04 15:02:38
Done
| |
| 271 INTERNAL_TRACE_EVENT_ADD_EXPLICIT(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 272 category, name, at, id, TRACE_EVENT_FLAG_COPY) | |
| 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_EVENT_COPY_END_EXPLICIT0(category, name, id, at) \ | |
| 304 INTERNAL_TRACE_EVENT_ADD_EXPLICIT(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 305 category, name, at, id, TRACE_EVENT_FLAG_COPY) | |
| 306 | |
| 295 // Time threshold event: | 307 // Time threshold event: |
| 296 // Only record the event if the duration is greater than the specified | 308 // Only record the event if the duration is greater than the specified |
| 297 // threshold_us (time in microseconds). | 309 // threshold_us (time in microseconds). |
| 298 // Records a pair of begin and end events called "name" for the current | 310 // 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 | 311 // scope, with 0, 1 or 2 associated arguments. If the category is not |
| 300 // enabled, then this does nothing. | 312 // enabled, then this does nothing. |
| 301 // - category and name strings must have application lifetime (statics or | 313 // - category and name strings must have application lifetime (statics or |
| 302 // literals). They may not include " chars. | 314 // literals). They may not include " chars. |
| 303 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ | 315 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ |
| 304 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) | 316 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 // int num_args, | 602 // int num_args, |
| 591 // const char** arg_names, | 603 // const char** arg_names, |
| 592 // const unsigned char* arg_types, | 604 // const unsigned char* arg_types, |
| 593 // const unsigned long long* arg_values, | 605 // const unsigned long long* arg_values, |
| 594 // int threshold_begin_id, | 606 // int threshold_begin_id, |
| 595 // long long threshold, | 607 // long long threshold, |
| 596 // unsigned char flags) | 608 // unsigned char flags) |
| 597 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | 609 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ |
| 598 base::debug::TraceLog::GetInstance()->AddTraceEvent | 610 base::debug::TraceLog::GetInstance()->AddTraceEvent |
| 599 | 611 |
| 612 // Add a trace event to the platform tracing system. Returns thresholdBeginId | |
| 613 // for use in a corresponding end TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT call. | |
| 614 // int TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT( | |
| 615 // char phase, | |
| 616 // const unsigned char* category_enabled, | |
| 617 // const char* name, | |
| 618 // int64 timestamp, | |
| 619 // unsigned long long id, | |
| 620 // int num_args, | |
| 621 // const char** arg_names, | |
| 622 // const unsigned char* arg_types, | |
| 623 // const unsigned long long* arg_values, | |
| 624 // int threshold_begin_id, | |
| 625 // long long threshold, | |
| 626 // unsigned char flags) | |
| 627 #define TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT \ | |
|
nduca
2012/12/04 05:09:38
what requires this one?
dsinclair
2012/12/04 15:02:38
It's used on line 992 in AddTraceEventExplicit().
| |
| 628 base::debug::TraceLog::GetInstance()->AddTraceEventExplicit | |
| 629 | |
| 600 //////////////////////////////////////////////////////////////////////////////// | 630 //////////////////////////////////////////////////////////////////////////////// |
| 601 | 631 |
| 602 // Implementation detail: trace event macros create temporary variables | 632 // Implementation detail: trace event macros create temporary variables |
| 603 // to keep instrumentation overhead low. These macros give each temporary | 633 // to keep instrumentation overhead low. These macros give each temporary |
| 604 // variable a unique name based on the line number to prevent name collissions. | 634 // variable a unique name based on the line number to prevent name collissions. |
| 605 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 635 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
| 606 trace_event_unique_##a##b | 636 trace_event_unique_##a##b |
| 607 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 637 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
| 608 INTERNAL_TRACE_EVENT_UID3(a,b) | 638 INTERNAL_TRACE_EVENT_UID3(a,b) |
| 609 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 639 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 631 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ | 661 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ |
| 632 do { \ | 662 do { \ |
| 633 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 663 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 634 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | 664 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 635 trace_event_internal::AddTraceEvent( \ | 665 trace_event_internal::AddTraceEvent( \ |
| 636 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ | 666 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
| 637 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ | 667 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ |
| 638 } \ | 668 } \ |
| 639 } while (0) | 669 } while (0) |
| 640 | 670 |
| 671 // Implementation detail: internal macro to create static category and add | |
| 672 // event if the category is enabled. | |
| 673 #define INTERNAL_TRACE_EVENT_ADD_EXPLICIT(phase, category, name, \ | |
| 674 at, id, flags, ...) \ | |
| 675 do { \ | |
| 676 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | |
| 677 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | |
| 678 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
| 679 trace_event_internal::TraceID trace_event_trace_id( \ | |
| 680 id, &trace_event_flags); \ | |
| 681 trace_event_internal::AddTraceEventExplicit( \ | |
| 682 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | |
| 683 name, at, trace_event_trace_id.data(), \ | |
| 684 trace_event_flags, ##__VA_ARGS__); \ | |
| 685 } \ | |
| 686 } while (0) | |
| 687 | |
| 641 // Implementation detail: internal macro to create static category and add begin | 688 // Implementation detail: internal macro to create static category and add begin |
| 642 // event if the category is enabled. Also adds the end event when the scope | 689 // event if the category is enabled. Also adds the end event when the scope |
| 643 // ends. | 690 // ends. |
| 644 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ | 691 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
| 645 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 692 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 646 trace_event_internal::TraceEndOnScopeClose \ | 693 trace_event_internal::TraceEndOnScopeClose \ |
| 647 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 694 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| 648 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | 695 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 649 trace_event_internal::AddTraceEvent( \ | 696 trace_event_internal::AddTraceEvent( \ |
| 650 TRACE_EVENT_PHASE_BEGIN, \ | 697 TRACE_EVENT_PHASE_BEGIN, \ |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 unsigned char arg_types[2]; | 970 unsigned char arg_types[2]; |
| 924 unsigned long long arg_values[2]; | 971 unsigned long long arg_values[2]; |
| 925 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 972 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
| 926 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 973 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
| 927 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 974 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 928 phase, category_enabled, name, id, | 975 phase, category_enabled, name, id, |
| 929 num_args, arg_names, arg_types, arg_values, | 976 num_args, arg_names, arg_types, arg_values, |
| 930 kNoThreshholdBeginId, kNoThresholdValue, flags); | 977 kNoThreshholdBeginId, kNoThresholdValue, flags); |
| 931 } | 978 } |
| 932 | 979 |
| 980 static inline int AddTraceEventExplicit(char phase, | |
| 981 const unsigned char* category_enabled, | |
| 982 const char* name, | |
| 983 int64 timestamp, | |
| 984 unsigned long long id, | |
| 985 unsigned char flags) { | |
| 986 return TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT( | |
| 987 phase, category_enabled, name, timestamp, id, kZeroNumArgs, | |
| 988 NULL, NULL, NULL, kNoThreshholdBeginId, kNoThresholdValue, flags); | |
| 989 } | |
| 990 | |
| 933 // Used by TRACE_EVENTx macro. Do not use directly. | 991 // Used by TRACE_EVENTx macro. Do not use directly. |
| 934 class BASE_EXPORT TraceEndOnScopeClose { | 992 class BASE_EXPORT TraceEndOnScopeClose { |
| 935 public: | 993 public: |
| 936 // Note: members of data_ intentionally left uninitialized. See Initialize. | 994 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 937 TraceEndOnScopeClose() : p_data_(NULL) {} | 995 TraceEndOnScopeClose() : p_data_(NULL) {} |
| 938 ~TraceEndOnScopeClose() { | 996 ~TraceEndOnScopeClose() { |
| 939 if (p_data_) | 997 if (p_data_) |
| 940 AddEventIfEnabled(); | 998 AddEventIfEnabled(); |
| 941 } | 999 } |
| 942 | 1000 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 const char* name; | 1050 const char* name; |
| 993 int threshold_begin_id; | 1051 int threshold_begin_id; |
| 994 }; | 1052 }; |
| 995 Data* p_data_; | 1053 Data* p_data_; |
| 996 Data data_; | 1054 Data data_; |
| 997 }; | 1055 }; |
| 998 | 1056 |
| 999 } // namespace trace_event_internal | 1057 } // namespace trace_event_internal |
| 1000 | 1058 |
| 1001 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 1059 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |