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 with a custom |at| timestamp provided. | |
| 269 // - |id| is used to match the _BEGIN event with the _END event. | |
| 270 // Events are considered to match if their category, name and id values all | |
| 271 // match. |id| must either be a pointer or an integer value up to 64 bits. If | |
| 272 // it's a pointer, the bits will be xored with a hash of the process ID so | |
| 273 // that the same pointer on two different processes will not collide. | |
| 274 #define TRACE_EVENT_BEGIN_EXPLICIT0(category, name, tid, id, ts) \ | |
| 275 INTERNAL_TRACE_EVENT_ADD_EXPLICIT(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 276 category, name, tid, ts, id, TRACE_EVENT_FLAG_NONE) | |
| 277 #define TRACE_EVENT_COPY_BEGIN_EXPLICIT0(category, name, tid, id, ts) \ | |
| 278 INTERNAL_TRACE_EVENT_ADD_EXPLICIT(TRACE_EVENT_PHASE_ASYNC_BEGIN, \ | |
| 279 category, name, tid, ts, id, TRACE_EVENT_FLAG_COPY) | |
| 280 | |
| 268 // Records a single END event for "name" immediately. If the category | 281 // Records a single END event for "name" immediately. If the category |
| 269 // is not enabled, then this does nothing. | 282 // is not enabled, then this does nothing. |
| 270 // - category and name strings must have application lifetime (statics or | 283 // - category and name strings must have application lifetime (statics or |
| 271 // literals). They may not include " chars. | 284 // literals). They may not include " chars. |
| 272 #define TRACE_EVENT_END0(category, name) \ | 285 #define TRACE_EVENT_END0(category, name) \ |
| 273 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 286 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 274 category, name, TRACE_EVENT_FLAG_NONE) | 287 category, name, TRACE_EVENT_FLAG_NONE) |
| 275 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ | 288 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ |
| 276 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 289 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 277 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | 290 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) |
| 278 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ | 291 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ |
| 279 arg2_name, arg2_val) \ | 292 arg2_name, arg2_val) \ |
| 280 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 293 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 281 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | 294 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| 282 arg2_name, arg2_val) | 295 arg2_name, arg2_val) |
| 283 #define TRACE_EVENT_COPY_END0(category, name) \ | 296 #define TRACE_EVENT_COPY_END0(category, name) \ |
| 284 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 297 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 285 category, name, TRACE_EVENT_FLAG_COPY) | 298 category, name, TRACE_EVENT_FLAG_COPY) |
| 286 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ | 299 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ |
| 287 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 300 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 288 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | 301 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
| 289 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ | 302 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ |
| 290 arg2_name, arg2_val) \ | 303 arg2_name, arg2_val) \ |
| 291 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 304 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 292 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | 305 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| 293 arg2_name, arg2_val) | 306 arg2_name, arg2_val) |
| 294 | 307 |
| 308 // Similar to TRACE_EVENT_ENDx but with a custom |at| timestamp provided. | |
| 309 // - |id| is used to match the _BEGIN event with the _END event. | |
| 310 // Events are considered to match if their category, name and id values all | |
| 311 // match. |id| must either be a pointer or an integer value up to 64 bits. If | |
| 312 // it's a pointer, the bits will be xored with a hash of the process ID so | |
| 313 // that the same pointer on two different processes will not collide. | |
| 314 #define TRACE_EVENT_END_EXPLICIT0(category, name, tid, id, ts) \ | |
| 315 INTERNAL_TRACE_EVENT_ADD_EXPLICIT(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 316 category, name, tid, ts, id, TRACE_EVENT_FLAG_NONE) | |
| 317 #define TRACE_EVENT_COPY_END_EXPLICIT0(category, name, tid, id, ts) \ | |
| 318 INTERNAL_TRACE_EVENT_ADD_EXPLICIT(TRACE_EVENT_PHASE_ASYNC_END, \ | |
| 319 category, name, tid, ts, id, TRACE_EVENT_FLAG_COPY) | |
| 320 | |
| 295 // Time threshold event: | 321 // Time threshold event: |
| 296 // Only record the event if the duration is greater than the specified | 322 // Only record the event if the duration is greater than the specified |
| 297 // threshold_us (time in microseconds). | 323 // threshold_us (time in microseconds). |
| 298 // Records a pair of begin and end events called "name" for the current | 324 // 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 | 325 // scope, with 0, 1 or 2 associated arguments. If the category is not |
| 300 // enabled, then this does nothing. | 326 // enabled, then this does nothing. |
| 301 // - category and name strings must have application lifetime (statics or | 327 // - category and name strings must have application lifetime (statics or |
| 302 // literals). They may not include " chars. | 328 // literals). They may not include " chars. |
| 303 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ | 329 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ |
| 304 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) | 330 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, | 616 // int num_args, |
| 591 // const char** arg_names, | 617 // const char** arg_names, |
| 592 // const unsigned char* arg_types, | 618 // const unsigned char* arg_types, |
| 593 // const unsigned long long* arg_values, | 619 // const unsigned long long* arg_values, |
| 594 // int threshold_begin_id, | 620 // int threshold_begin_id, |
| 595 // long long threshold, | 621 // long long threshold, |
| 596 // unsigned char flags) | 622 // unsigned char flags) |
| 597 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | 623 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ |
| 598 base::debug::TraceLog::GetInstance()->AddTraceEvent | 624 base::debug::TraceLog::GetInstance()->AddTraceEvent |
| 599 | 625 |
| 626 // Add a trace event to the platform tracing system. Returns thresholdBeginId | |
| 627 // for use in a corresponding end TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT call. | |
| 628 // int TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT( | |
| 629 // char phase, | |
| 630 // const unsigned char* category_enabled, | |
| 631 // const char* name, | |
| 632 // int thread_id, | |
| 633 // int64 timestamp, | |
| 634 // unsigned long long id, | |
| 635 // int num_args, | |
| 636 // const char** arg_names, | |
| 637 // const unsigned char* arg_types, | |
| 638 // const unsigned long long* arg_values, | |
| 639 // int threshold_begin_id, | |
| 640 // long long threshold, | |
| 641 // unsigned char flags) | |
| 642 #define TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT \ | |
|
nduca
2012/12/11 19:40:58
How about always providing the tid? And always pro
dsinclair
2012/12/14 16:08:20
Done.
| |
| 643 base::debug::TraceLog::GetInstance()->AddTraceEventExplicit | |
| 644 | |
| 600 //////////////////////////////////////////////////////////////////////////////// | 645 //////////////////////////////////////////////////////////////////////////////// |
| 601 | 646 |
| 602 // Implementation detail: trace event macros create temporary variables | 647 // Implementation detail: trace event macros create temporary variables |
| 603 // to keep instrumentation overhead low. These macros give each temporary | 648 // to keep instrumentation overhead low. These macros give each temporary |
| 604 // variable a unique name based on the line number to prevent name collissions. | 649 // variable a unique name based on the line number to prevent name collissions. |
| 605 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 650 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
| 606 trace_event_unique_##a##b | 651 trace_event_unique_##a##b |
| 607 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 652 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
| 608 INTERNAL_TRACE_EVENT_UID3(a,b) | 653 INTERNAL_TRACE_EVENT_UID3(a,b) |
| 609 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 654 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 631 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ | 676 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ |
| 632 do { \ | 677 do { \ |
| 633 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 678 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 634 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | 679 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 635 trace_event_internal::AddTraceEvent( \ | 680 trace_event_internal::AddTraceEvent( \ |
| 636 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ | 681 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
| 637 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ | 682 trace_event_internal::kNoEventId, flags, ##__VA_ARGS__); \ |
| 638 } \ | 683 } \ |
| 639 } while (0) | 684 } while (0) |
| 640 | 685 |
| 686 // Implementation detail: internal macro to create static category and add | |
| 687 // event if the category is enabled. | |
| 688 #define INTERNAL_TRACE_EVENT_ADD_EXPLICIT(phase, category, name, tid, \ | |
| 689 ts, id, flags, ...) \ | |
| 690 do { \ | |
| 691 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | |
| 692 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | |
| 693 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
| 694 trace_event_internal::TraceID trace_event_trace_id( \ | |
| 695 id, &trace_event_flags); \ | |
| 696 trace_event_internal::AddTraceEventExplicit( \ | |
| 697 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | |
| 698 name, tid, ts, trace_event_trace_id.data(), \ | |
| 699 trace_event_flags, ##__VA_ARGS__); \ | |
| 700 } \ | |
| 701 } while (0) | |
| 702 | |
| 641 // Implementation detail: internal macro to create static category and add begin | 703 // 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 | 704 // event if the category is enabled. Also adds the end event when the scope |
| 643 // ends. | 705 // ends. |
| 644 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ | 706 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
| 645 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 707 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 646 trace_event_internal::TraceEndOnScopeClose \ | 708 trace_event_internal::TraceEndOnScopeClose \ |
| 647 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 709 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| 648 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | 710 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 649 trace_event_internal::AddTraceEvent( \ | 711 trace_event_internal::AddTraceEvent( \ |
| 650 TRACE_EVENT_PHASE_BEGIN, \ | 712 TRACE_EVENT_PHASE_BEGIN, \ |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 unsigned char arg_types[2]; | 985 unsigned char arg_types[2]; |
| 924 unsigned long long arg_values[2]; | 986 unsigned long long arg_values[2]; |
| 925 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 987 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
| 926 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 988 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
| 927 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 989 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 928 phase, category_enabled, name, id, | 990 phase, category_enabled, name, id, |
| 929 num_args, arg_names, arg_types, arg_values, | 991 num_args, arg_names, arg_types, arg_values, |
| 930 kNoThreshholdBeginId, kNoThresholdValue, flags); | 992 kNoThreshholdBeginId, kNoThresholdValue, flags); |
| 931 } | 993 } |
| 932 | 994 |
| 995 static inline int AddTraceEventExplicit(char phase, | |
| 996 const unsigned char* category_enabled, | |
| 997 const char* name, | |
| 998 int thread_id, | |
| 999 int64 timestamp, | |
| 1000 unsigned long long id, | |
| 1001 unsigned char flags) { | |
| 1002 return TRACE_EVENT_API_ADD_TRACE_EVENT_EXPLICIT( | |
| 1003 phase, category_enabled, name, thread_id, timestamp, id, kZeroNumArgs, | |
| 1004 NULL, NULL, NULL, kNoThreshholdBeginId, kNoThresholdValue, flags); | |
| 1005 } | |
| 1006 | |
| 933 // Used by TRACE_EVENTx macro. Do not use directly. | 1007 // Used by TRACE_EVENTx macro. Do not use directly. |
| 934 class BASE_EXPORT TraceEndOnScopeClose { | 1008 class BASE_EXPORT TraceEndOnScopeClose { |
| 935 public: | 1009 public: |
| 936 // Note: members of data_ intentionally left uninitialized. See Initialize. | 1010 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 937 TraceEndOnScopeClose() : p_data_(NULL) {} | 1011 TraceEndOnScopeClose() : p_data_(NULL) {} |
| 938 ~TraceEndOnScopeClose() { | 1012 ~TraceEndOnScopeClose() { |
| 939 if (p_data_) | 1013 if (p_data_) |
| 940 AddEventIfEnabled(); | 1014 AddEventIfEnabled(); |
| 941 } | 1015 } |
| 942 | 1016 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 992 const char* name; | 1066 const char* name; |
| 993 int threshold_begin_id; | 1067 int threshold_begin_id; |
| 994 }; | 1068 }; |
| 995 Data* p_data_; | 1069 Data* p_data_; |
| 996 Data data_; | 1070 Data data_; |
| 997 }; | 1071 }; |
| 998 | 1072 |
| 999 } // namespace trace_event_internal | 1073 } // namespace trace_event_internal |
| 1000 | 1074 |
| 1001 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 1075 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |