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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 category, name, TRACE_EVENT_FLAG_COPY) | 254 category, name, TRACE_EVENT_FLAG_COPY) |
255 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ | 255 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ |
256 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 256 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
257 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | 257 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
258 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ | 258 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ |
259 arg2_name, arg2_val) \ | 259 arg2_name, arg2_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 arg2_name, arg2_val) | 262 arg2_name, arg2_val) |
263 | 263 |
264 // Similar to TRACE_EVENT_BEGINx but with a custom |at| timestamp provided. | |
265 // - |id| is used to match the _BEGIN event with the _END event. | |
266 // Events are considered to match if their category, name and id values all | |
267 // match. |id| must either be a pointer or an integer value up to 64 bits. If | |
268 // it's a pointer, the bits will be xored with a hash of the process ID so | |
269 // that the same pointer on two different processes will not collide. | |
270 #define TRACE_EVENT_BEGIN_WITH_ID_TID_AND_TIMESTAMP0(category, \ | |
271 name, id, tid, ts) \ | |
jar (doing other things)
2013/02/14 02:17:54
nit: please use larger names, like thread_id, and
dsinclair
2013/02/14 15:38:47
Done.
| |
272 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
273 TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, tid, ts, \ | |
274 TRACE_EVENT_FLAG_NONE) | |
275 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \ | |
276 category, name, id, tid, ts) \ | |
277 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
278 TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, tid, ts, \ | |
279 TRACE_EVENT_FLAG_COPY) | |
280 | |
264 // Records a single END event for "name" immediately. If the category | 281 // Records a single END event for "name" immediately. If the category |
265 // is not enabled, then this does nothing. | 282 // is not enabled, then this does nothing. |
266 // - category and name strings must have application lifetime (statics or | 283 // - category and name strings must have application lifetime (statics or |
267 // literals). They may not include " chars. | 284 // literals). They may not include " chars. |
268 #define TRACE_EVENT_END0(category, name) \ | 285 #define TRACE_EVENT_END0(category, name) \ |
269 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 286 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
270 category, name, TRACE_EVENT_FLAG_NONE) | 287 category, name, TRACE_EVENT_FLAG_NONE) |
271 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ | 288 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ |
272 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 289 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
273 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | 290 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) |
274 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ | 291 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ |
275 arg2_name, arg2_val) \ | 292 arg2_name, arg2_val) \ |
276 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 293 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
277 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ | 294 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
278 arg2_name, arg2_val) | 295 arg2_name, arg2_val) |
279 #define TRACE_EVENT_COPY_END0(category, name) \ | 296 #define TRACE_EVENT_COPY_END0(category, name) \ |
280 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 297 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
281 category, name, TRACE_EVENT_FLAG_COPY) | 298 category, name, TRACE_EVENT_FLAG_COPY) |
282 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ | 299 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ |
283 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 300 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
284 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | 301 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) |
285 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ | 302 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ |
286 arg2_name, arg2_val) \ | 303 arg2_name, arg2_val) \ |
287 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 304 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
288 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ | 305 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
289 arg2_name, arg2_val) | 306 arg2_name, arg2_val) |
290 | 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_WITH_ID_TID_AND_TIMESTAMP0(category, \ | |
315 name, id, tid, ts) \ | |
316 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
317 TRACE_EVENT_PHASE_ASYNC_END, category, name, id, tid, ts, \ | |
318 TRACE_EVENT_FLAG_NONE) | |
319 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \ | |
320 category, name, id, tid, ts) \ | |
321 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | |
322 TRACE_EVENT_PHASE_ASYNC_END, category, name, id, tid, ts, \ | |
323 TRACE_EVENT_FLAG_COPY) | |
324 | |
291 // Records the value of a counter called "name" immediately. Value | 325 // Records the value of a counter called "name" immediately. Value |
292 // must be representable as a 32 bit integer. | 326 // must be representable as a 32 bit integer. |
293 // - category and name strings must have application lifetime (statics or | 327 // - category and name strings must have application lifetime (statics or |
294 // literals). They may not include " chars. | 328 // literals). They may not include " chars. |
295 #define TRACE_COUNTER1(category, name, value) \ | 329 #define TRACE_COUNTER1(category, name, value) \ |
296 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | 330 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ |
297 category, name, TRACE_EVENT_FLAG_NONE, \ | 331 category, name, TRACE_EVENT_FLAG_NONE, \ |
298 "value", static_cast<int>(value)) | 332 "value", static_cast<int>(value)) |
299 #define TRACE_COPY_COUNTER1(category, name, value) \ | 333 #define TRACE_COPY_COUNTER1(category, name, value) \ |
300 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ | 334 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, \ |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 #define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \ | 567 #define TRACE_EVENT_COPY_FLOW_END1(category, name, id, arg1_name, arg1_val) \ |
534 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | 568 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ |
535 category, name, id, TRACE_EVENT_FLAG_COPY, \ | 569 category, name, id, TRACE_EVENT_FLAG_COPY, \ |
536 arg1_name, arg1_val) | 570 arg1_name, arg1_val) |
537 #define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \ | 571 #define TRACE_EVENT_COPY_FLOW_END2(category, name, id, arg1_name, arg1_val, \ |
538 arg2_name, arg2_val) \ | 572 arg2_name, arg2_val) \ |
539 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ | 573 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FLOW_END, \ |
540 category, name, id, TRACE_EVENT_FLAG_COPY, \ | 574 category, name, id, TRACE_EVENT_FLAG_COPY, \ |
541 arg1_name, arg1_val, arg2_name, arg2_val) | 575 arg1_name, arg1_val, arg2_name, arg2_val) |
542 | 576 |
543 | |
544 // Implementation detail: trace event macros create temporary variables | 577 // Implementation detail: trace event macros create temporary variables |
545 // to keep instrumentation overhead low. These macros give each temporary | 578 // to keep instrumentation overhead low. These macros give each temporary |
546 // variable a unique name based on the line number to prevent name collissions. | 579 // variable a unique name based on the line number to prevent name collissions. |
547 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 580 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
548 trace_event_unique_##a##b | 581 trace_event_unique_##a##b |
549 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 582 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
550 INTERNAL_TRACE_EVENT_UID3(a,b) | 583 INTERNAL_TRACE_EVENT_UID3(a,b) |
551 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 584 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
552 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) | 585 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) |
553 | 586 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 640 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ |
608 trace_event_internal::TraceID trace_event_trace_id( \ | 641 trace_event_internal::TraceID trace_event_trace_id( \ |
609 id, &trace_event_flags); \ | 642 id, &trace_event_flags); \ |
610 trace_event_internal::AddTraceEvent( \ | 643 trace_event_internal::AddTraceEvent( \ |
611 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | 644 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ |
612 name, trace_event_trace_id.data(), trace_event_flags, \ | 645 name, trace_event_trace_id.data(), trace_event_flags, \ |
613 ##__VA_ARGS__); \ | 646 ##__VA_ARGS__); \ |
614 } \ | 647 } \ |
615 } while (0) | 648 } while (0) |
616 | 649 |
650 // Implementation detail: internal macro to create static category and add | |
651 // event if the category is enabled. | |
652 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP(phase, category, \ | |
653 name, id, tid, ts, flags, ...) \ | |
654 do { \ | |
655 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | |
656 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ | |
657 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | |
658 trace_event_internal::TraceID trace_event_trace_id( \ | |
659 id, &trace_event_flags); \ | |
660 trace_event_internal::AddTraceEvent( \ | |
661 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | |
662 name, trace_event_trace_id.data(), tid, ts, \ | |
663 trace_event_flags, ##__VA_ARGS__); \ | |
664 } \ | |
665 } while (0) | |
666 | |
617 // Notes regarding the following definitions: | 667 // Notes regarding the following definitions: |
618 // New values can be added and propagated to third party libraries, but existing | 668 // New values can be added and propagated to third party libraries, but existing |
619 // definitions must never be changed, because third party libraries may use old | 669 // definitions must never be changed, because third party libraries may use old |
620 // definitions. | 670 // definitions. |
621 | 671 |
622 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. | 672 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. |
623 #define TRACE_EVENT_PHASE_BEGIN ('B') | 673 #define TRACE_EVENT_PHASE_BEGIN ('B') |
624 #define TRACE_EVENT_PHASE_END ('E') | 674 #define TRACE_EVENT_PHASE_END ('E') |
625 #define TRACE_EVENT_PHASE_INSTANT ('I') | 675 #define TRACE_EVENT_PHASE_INSTANT ('I') |
626 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') | 676 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 *value = type_value.as_uint; | 843 *value = type_value.as_uint; |
794 } | 844 } |
795 | 845 |
796 // These AddTraceEvent template functions are defined here instead of in the | 846 // These AddTraceEvent template functions are defined here instead of in the |
797 // macro, because the arg_values could be temporary objects, such as | 847 // macro, because the arg_values could be temporary objects, such as |
798 // std::string. In order to store pointers to the internal c_str and pass | 848 // std::string. In order to store pointers to the internal c_str and pass |
799 // through to the tracing API, the arg_values must live throughout | 849 // through to the tracing API, the arg_values must live throughout |
800 // these procedures. | 850 // these procedures. |
801 | 851 |
802 static inline void AddTraceEvent(char phase, | 852 static inline void AddTraceEvent(char phase, |
803 const unsigned char* category_enabled, | 853 const unsigned char* category_enabled, |
804 const char* name, | 854 const char* name, |
805 unsigned long long id, | 855 unsigned long long id, |
806 unsigned char flags) { | 856 int thread_id, |
857 int64 timestamp, | |
858 unsigned char flags) { | |
807 TRACE_EVENT_API_ADD_TRACE_EVENT( | 859 TRACE_EVENT_API_ADD_TRACE_EVENT( |
808 phase, category_enabled, name, id, | 860 phase, category_enabled, name, id, thread_id, timestamp, |
809 kZeroNumArgs, NULL, NULL, NULL, flags); | 861 kZeroNumArgs, NULL, NULL, NULL, flags); |
810 } | 862 } |
811 | 863 |
864 static inline void AddTraceEvent(char phase, | |
865 const unsigned char* category_enabled, | |
866 const char* name, | |
867 unsigned long long id, | |
868 unsigned char flags) { | |
869 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | |
870 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); | |
871 AddTraceEvent(phase, category_enabled, name, id, thread_id, | |
872 now.ToInternalValue(), flags); | |
873 } | |
874 | |
812 template<class ARG1_TYPE> | 875 template<class ARG1_TYPE> |
813 static inline void AddTraceEvent(char phase, | 876 static inline void AddTraceEvent(char phase, |
814 const unsigned char* category_enabled, | 877 const unsigned char* category_enabled, |
815 const char* name, | 878 const char* name, |
816 unsigned long long id, | 879 unsigned long long id, |
817 unsigned char flags, | 880 int thread_id, |
818 const char* arg1_name, | 881 int64 timestamp, |
819 const ARG1_TYPE& arg1_val) { | 882 unsigned char flags, |
883 const char* arg1_name, | |
884 const ARG1_TYPE& arg1_val) { | |
820 const int num_args = 1; | 885 const int num_args = 1; |
821 unsigned char arg_types[1]; | 886 unsigned char arg_types[1]; |
822 unsigned long long arg_values[1]; | 887 unsigned long long arg_values[1]; |
823 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 888 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
824 TRACE_EVENT_API_ADD_TRACE_EVENT( | 889 TRACE_EVENT_API_ADD_TRACE_EVENT( |
825 phase, category_enabled, name, id, | 890 phase, category_enabled, name, id, thread_id, timestamp, |
826 num_args, &arg1_name, arg_types, arg_values, flags); | 891 num_args, &arg1_name, arg_types, arg_values, flags); |
827 } | 892 } |
828 | 893 |
894 template<class ARG1_TYPE> | |
895 static inline void AddTraceEvent(char phase, | |
896 const unsigned char* category_enabled, | |
897 const char* name, | |
898 unsigned long long id, | |
899 unsigned char flags, | |
900 const char* arg1_name, | |
901 const ARG1_TYPE& arg1_val) { | |
902 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | |
903 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); | |
904 AddTraceEvent(phase, category_enabled, name, id, thread_id, | |
905 now.ToInternalValue(), flags, arg1_name, arg1_val); | |
906 } | |
907 | |
829 template<class ARG1_TYPE, class ARG2_TYPE> | 908 template<class ARG1_TYPE, class ARG2_TYPE> |
830 static inline void AddTraceEvent(char phase, | 909 static inline void AddTraceEvent(char phase, |
831 const unsigned char* category_enabled, | 910 const unsigned char* category_enabled, |
832 const char* name, | 911 const char* name, |
833 unsigned long long id, | 912 unsigned long long id, |
834 unsigned char flags, | 913 int thread_id, |
835 const char* arg1_name, | 914 int64 timestamp, |
836 const ARG1_TYPE& arg1_val, | 915 unsigned char flags, |
837 const char* arg2_name, | 916 const char* arg1_name, |
838 const ARG2_TYPE& arg2_val) { | 917 const ARG1_TYPE& arg1_val, |
918 const char* arg2_name, | |
919 const ARG2_TYPE& arg2_val) { | |
839 const int num_args = 2; | 920 const int num_args = 2; |
840 const char* arg_names[2] = { arg1_name, arg2_name }; | 921 const char* arg_names[2] = { arg1_name, arg2_name }; |
841 unsigned char arg_types[2]; | 922 unsigned char arg_types[2]; |
842 unsigned long long arg_values[2]; | 923 unsigned long long arg_values[2]; |
843 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 924 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); |
844 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 925 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); |
845 TRACE_EVENT_API_ADD_TRACE_EVENT( | 926 TRACE_EVENT_API_ADD_TRACE_EVENT( |
846 phase, category_enabled, name, id, | 927 phase, category_enabled, name, id, thread_id, timestamp, |
847 num_args, arg_names, arg_types, arg_values, flags); | 928 num_args, arg_names, arg_types, arg_values, flags); |
848 } | 929 } |
849 | 930 |
931 template<class ARG1_TYPE, class ARG2_TYPE> | |
932 static inline void AddTraceEvent(char phase, | |
933 const unsigned char* category_enabled, | |
934 const char* name, | |
935 unsigned long long id, | |
936 unsigned char flags, | |
937 const char* arg1_name, | |
938 const ARG1_TYPE& arg1_val, | |
939 const char* arg2_name, | |
940 const ARG2_TYPE& arg2_val) { | |
941 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | |
942 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); | |
943 AddTraceEvent(phase, category_enabled, name, id, thread_id, | |
944 now.ToInternalValue(), flags, arg1_name, arg1_val, | |
945 arg2_name, arg2_val); | |
946 } | |
947 | |
850 // Used by TRACE_EVENTx macro. Do not use directly. | 948 // Used by TRACE_EVENTx macro. Do not use directly. |
851 class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { | 949 class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { |
852 public: | 950 public: |
853 // Note: members of data_ intentionally left uninitialized. See Initialize. | 951 // Note: members of data_ intentionally left uninitialized. See Initialize. |
854 TraceEndOnScopeClose() : p_data_(NULL) {} | 952 TraceEndOnScopeClose() : p_data_(NULL) {} |
855 ~TraceEndOnScopeClose() { | 953 ~TraceEndOnScopeClose() { |
856 if (p_data_) | 954 if (p_data_) |
857 AddEventIfEnabled(); | 955 AddEventIfEnabled(); |
858 } | 956 } |
859 | 957 |
860 void Initialize(const unsigned char* category_enabled, | 958 void Initialize(const unsigned char* category_enabled, |
861 const char* name) { | 959 const char* name) { |
862 data_.category_enabled = category_enabled; | 960 data_.category_enabled = category_enabled; |
863 data_.name = name; | 961 data_.name = name; |
864 p_data_ = &data_; | 962 p_data_ = &data_; |
865 } | 963 } |
866 | 964 |
867 | |
868 private: | 965 private: |
869 // Add the end event if the category is still enabled. | 966 // Add the end event if the category is still enabled. |
870 void AddEventIfEnabled() { | 967 void AddEventIfEnabled() { |
871 // Only called when p_data_ is non-null. | 968 // Only called when p_data_ is non-null. |
872 if (*p_data_->category_enabled) { | 969 if (*p_data_->category_enabled) { |
873 TRACE_EVENT_API_ADD_TRACE_EVENT( | 970 TRACE_EVENT_API_ADD_TRACE_EVENT( |
874 TRACE_EVENT_PHASE_END, | 971 TRACE_EVENT_PHASE_END, |
875 p_data_->category_enabled, | 972 p_data_->category_enabled, |
876 p_data_->name, kNoEventId, | 973 p_data_->name, kNoEventId, |
877 kZeroNumArgs, NULL, NULL, NULL, | 974 kZeroNumArgs, NULL, NULL, NULL, |
(...skipping 10 matching lines...) Expand all Loading... | |
888 const unsigned char* category_enabled; | 985 const unsigned char* category_enabled; |
889 const char* name; | 986 const char* name; |
890 }; | 987 }; |
891 Data* p_data_; | 988 Data* p_data_; |
892 Data data_; | 989 Data data_; |
893 }; | 990 }; |
894 | 991 |
895 } // namespace trace_event_internal | 992 } // namespace trace_event_internal |
896 | 993 |
897 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_ | 994 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_ |
OLD | NEW |