Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: base/debug/trace_event_internal.h

Issue 11366109: Adding raw tracing to trace framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style fixes. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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, thread_id, timestamp) \
272 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
273 TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, thread_id, \
274 timestamp, TRACE_EVENT_FLAG_NONE)
275 #define TRACE_EVENT_COPY_BEGIN_WITH_ID_TID_AND_TIMESTAMP0( \
276 category, name, id, thread_id, timestamp) \
277 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
278 TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, thread_id, \
279 timestamp, 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, thread_id, timestamp) \
316 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
317 TRACE_EVENT_PHASE_ASYNC_END, category, name, id, thread_id, timestamp, \
318 TRACE_EVENT_FLAG_NONE)
319 #define TRACE_EVENT_COPY_END_WITH_ID_TID_AND_TIMESTAMP0( \
320 category, name, id, thread_id, timestamp) \
321 INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
322 TRACE_EVENT_PHASE_ASYNC_END, category, name, id, thread_id, timestamp, \
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
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
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, thread_id, timestamp, 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::AddTraceEventWithThreadIdAndTimestamp( \
661 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \
662 name, trace_event_trace_id.data(), \
663 thread_id, TimeTicks::FromInternalValue(timestamp), \
664 trace_event_flags, ##__VA_ARGS__); \
665 } \
666 } while (0)
667
617 // Notes regarding the following definitions: 668 // Notes regarding the following definitions:
618 // New values can be added and propagated to third party libraries, but existing 669 // 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 670 // definitions must never be changed, because third party libraries may use old
620 // definitions. 671 // definitions.
621 672
622 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. 673 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair.
623 #define TRACE_EVENT_PHASE_BEGIN ('B') 674 #define TRACE_EVENT_PHASE_BEGIN ('B')
624 #define TRACE_EVENT_PHASE_END ('E') 675 #define TRACE_EVENT_PHASE_END ('E')
625 #define TRACE_EVENT_PHASE_INSTANT ('I') 676 #define TRACE_EVENT_PHASE_INSTANT ('I')
626 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S') 677 #define TRACE_EVENT_PHASE_ASYNC_BEGIN ('S')
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // std::string version of SetTraceValue so that trace arguments can be strings. 837 // std::string version of SetTraceValue so that trace arguments can be strings.
787 static inline void SetTraceValue(const std::string& arg, 838 static inline void SetTraceValue(const std::string& arg,
788 unsigned char* type, 839 unsigned char* type,
789 unsigned long long* value) { 840 unsigned long long* value) {
790 TraceValueUnion type_value; 841 TraceValueUnion type_value;
791 type_value.as_string = arg.c_str(); 842 type_value.as_string = arg.c_str();
792 *type = TRACE_VALUE_TYPE_COPY_STRING; 843 *type = TRACE_VALUE_TYPE_COPY_STRING;
793 *value = type_value.as_uint; 844 *value = type_value.as_uint;
794 } 845 }
795 846
796 // These AddTraceEvent template functions are defined here instead of in the 847 // These AddTraceEvent and AddTraceEventWithThreadIdAndTimestamp template
797 // macro, because the arg_values could be temporary objects, such as 848 // functions are defined here instead of in the macro, because the arg_values
798 // std::string. In order to store pointers to the internal c_str and pass 849 // could be temporary objects, such as std::string. In order to store
799 // through to the tracing API, the arg_values must live throughout 850 // pointers to the internal c_str and pass through to the tracing API,
800 // these procedures. 851 // the arg_values must live throughout these procedures.
852
853 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase,
854 const unsigned char* category_enabled,
855 const char* name,
856 unsigned long long id,
857 int thread_id,
858 const base::TimeTicks& timestamp,
859 unsigned char flags) {
860 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
861 phase, category_enabled, name, id, thread_id, timestamp,
862 kZeroNumArgs, NULL, NULL, NULL, flags);
863 }
801 864
802 static inline void AddTraceEvent(char phase, 865 static inline void AddTraceEvent(char phase,
803 const unsigned char* category_enabled, 866 const unsigned char* category_enabled,
804 const char* name, 867 const char* name,
805 unsigned long long id, 868 unsigned long long id,
806 unsigned char flags) { 869 unsigned char flags) {
807 TRACE_EVENT_API_ADD_TRACE_EVENT( 870 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
808 phase, category_enabled, name, id, 871 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime();
809 kZeroNumArgs, NULL, NULL, NULL, flags); 872 AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id,
873 thread_id, now, flags);
874 }
875
876 template<class ARG1_TYPE>
877 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase,
878 const unsigned char* category_enabled,
879 const char* name,
880 unsigned long long id,
881 int thread_id,
882 const base::TimeTicks& timestamp,
883 unsigned char flags,
884 const char* arg1_name,
885 const ARG1_TYPE& arg1_val) {
886 const int num_args = 1;
887 unsigned char arg_types[1];
888 unsigned long long arg_values[1];
889 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
890 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
891 phase, category_enabled, name, id, thread_id, timestamp,
892 num_args, &arg1_name, arg_types, arg_values, flags);
810 } 893 }
811 894
812 template<class ARG1_TYPE> 895 template<class ARG1_TYPE>
813 static inline void AddTraceEvent(char phase, 896 static inline void AddTraceEvent(char phase,
814 const unsigned char* category_enabled, 897 const unsigned char* category_enabled,
815 const char* name, 898 const char* name,
816 unsigned long long id, 899 unsigned long long id,
817 unsigned char flags, 900 unsigned char flags,
818 const char* arg1_name, 901 const char* arg1_name,
819 const ARG1_TYPE& arg1_val) { 902 const ARG1_TYPE& arg1_val) {
820 const int num_args = 1; 903 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
821 unsigned char arg_types[1]; 904 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime();
822 unsigned long long arg_values[1]; 905 AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id,
906 thread_id, now, flags, arg1_name,
907 arg1_val);
908 }
909
910 template<class ARG1_TYPE, class ARG2_TYPE>
911 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase,
912 const unsigned char* category_enabled,
913 const char* name,
914 unsigned long long id,
915 int thread_id,
916 const base::TimeTicks& timestamp,
917 unsigned char flags,
918 const char* arg1_name,
919 const ARG1_TYPE& arg1_val,
920 const char* arg2_name,
921 const ARG2_TYPE& arg2_val) {
922 const int num_args = 2;
923 const char* arg_names[2] = { arg1_name, arg2_name };
924 unsigned char arg_types[2];
925 unsigned long long arg_values[2];
823 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 926 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
824 TRACE_EVENT_API_ADD_TRACE_EVENT( 927 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
825 phase, category_enabled, name, id, 928 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
826 num_args, &arg1_name, arg_types, arg_values, flags); 929 phase, category_enabled, name, id, thread_id, timestamp,
930 num_args, arg_names, arg_types, arg_values, flags);
827 } 931 }
828 932
829 template<class ARG1_TYPE, class ARG2_TYPE> 933 template<class ARG1_TYPE, class ARG2_TYPE>
830 static inline void AddTraceEvent(char phase, 934 static inline void AddTraceEvent(char phase,
831 const unsigned char* category_enabled, 935 const unsigned char* category_enabled,
832 const char* name, 936 const char* name,
833 unsigned long long id, 937 unsigned long long id,
834 unsigned char flags, 938 unsigned char flags,
835 const char* arg1_name, 939 const char* arg1_name,
836 const ARG1_TYPE& arg1_val, 940 const ARG1_TYPE& arg1_val,
837 const char* arg2_name, 941 const char* arg2_name,
838 const ARG2_TYPE& arg2_val) { 942 const ARG2_TYPE& arg2_val) {
839 const int num_args = 2; 943 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
840 const char* arg_names[2] = { arg1_name, arg2_name }; 944 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime();
841 unsigned char arg_types[2]; 945 AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id,
842 unsigned long long arg_values[2]; 946 thread_id, now, flags, arg1_name,
843 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 947 arg1_val, arg2_name, arg2_val);
844 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
845 TRACE_EVENT_API_ADD_TRACE_EVENT(
846 phase, category_enabled, name, id,
847 num_args, arg_names, arg_types, arg_values, flags);
848 } 948 }
849 949
850 // Used by TRACE_EVENTx macro. Do not use directly. 950 // Used by TRACE_EVENTx macro. Do not use directly.
851 class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose { 951 class TRACE_EVENT_API_CLASS_EXPORT TraceEndOnScopeClose {
852 public: 952 public:
853 // Note: members of data_ intentionally left uninitialized. See Initialize. 953 // Note: members of data_ intentionally left uninitialized. See Initialize.
854 TraceEndOnScopeClose() : p_data_(NULL) {} 954 TraceEndOnScopeClose() : p_data_(NULL) {}
855 ~TraceEndOnScopeClose() { 955 ~TraceEndOnScopeClose() {
856 if (p_data_) 956 if (p_data_)
857 AddEventIfEnabled(); 957 AddEventIfEnabled();
858 } 958 }
859 959
860 void Initialize(const unsigned char* category_enabled, 960 void Initialize(const unsigned char* category_enabled,
861 const char* name) { 961 const char* name) {
862 data_.category_enabled = category_enabled; 962 data_.category_enabled = category_enabled;
863 data_.name = name; 963 data_.name = name;
864 p_data_ = &data_; 964 p_data_ = &data_;
865 } 965 }
866 966
867
868 private: 967 private:
869 // Add the end event if the category is still enabled. 968 // Add the end event if the category is still enabled.
870 void AddEventIfEnabled() { 969 void AddEventIfEnabled() {
871 // Only called when p_data_ is non-null. 970 // Only called when p_data_ is non-null.
872 if (*p_data_->category_enabled) { 971 if (*p_data_->category_enabled) {
873 TRACE_EVENT_API_ADD_TRACE_EVENT( 972 TRACE_EVENT_API_ADD_TRACE_EVENT(
874 TRACE_EVENT_PHASE_END, 973 TRACE_EVENT_PHASE_END,
875 p_data_->category_enabled, 974 p_data_->category_enabled,
876 p_data_->name, kNoEventId, 975 p_data_->name, kNoEventId,
877 kZeroNumArgs, NULL, NULL, NULL, 976 kZeroNumArgs, NULL, NULL, NULL,
(...skipping 10 matching lines...) Expand all
888 const unsigned char* category_enabled; 987 const unsigned char* category_enabled;
889 const char* name; 988 const char* name;
890 }; 989 };
891 Data* p_data_; 990 Data* p_data_;
892 Data data_; 991 Data data_;
893 }; 992 };
894 993
895 } // namespace trace_event_internal 994 } // namespace trace_event_internal
896 995
897 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_ 996 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698