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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 TRACE_EVENT_FLAG_SCOPE_OFFSET | (TRACE_EVENT_FLAG_SCOPE_OFFSET << 1))) | 724 TRACE_EVENT_FLAG_SCOPE_OFFSET | (TRACE_EVENT_FLAG_SCOPE_OFFSET << 1))) |
725 | 725 |
726 // Type values for identifying types in the TraceValue union. | 726 // Type values for identifying types in the TraceValue union. |
727 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1)) | 727 #define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1)) |
728 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2)) | 728 #define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2)) |
729 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3)) | 729 #define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3)) |
730 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4)) | 730 #define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4)) |
731 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) | 731 #define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5)) |
732 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6)) | 732 #define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6)) |
733 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) | 733 #define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7)) |
734 #define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8)) | |
734 | 735 |
735 // Enum reflecting the scope of an INSTANT event. Must fit within | 736 // Enum reflecting the scope of an INSTANT event. Must fit within |
736 // TRACE_EVENT_FLAG_SCOPE_MASK. | 737 // TRACE_EVENT_FLAG_SCOPE_MASK. |
737 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) | 738 #define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3)) |
738 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) | 739 #define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3)) |
739 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) | 740 #define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3)) |
740 | 741 |
741 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') | 742 #define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g') |
742 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') | 743 #define TRACE_EVENT_SCOPE_NAME_PROCESS ('p') |
743 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') | 744 #define TRACE_EVENT_SCOPE_NAME_THREAD ('t') |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 private: | 832 private: |
832 const char* str_; | 833 const char* str_; |
833 }; | 834 }; |
834 | 835 |
835 // Define SetTraceValue for each allowed type. It stores the type and | 836 // Define SetTraceValue for each allowed type. It stores the type and |
836 // value in the return arguments. This allows this API to avoid declaring any | 837 // value in the return arguments. This allows this API to avoid declaring any |
837 // structures so that it is portable to third_party libraries. | 838 // structures so that it is portable to third_party libraries. |
838 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ | 839 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ |
839 union_member, \ | 840 union_member, \ |
840 value_type_id) \ | 841 value_type_id) \ |
841 static inline void SetTraceValue(actual_type arg, \ | 842 static inline void SetTraceValue( \ |
842 unsigned char* type, \ | 843 actual_type arg, \ |
843 unsigned long long* value) { \ | 844 unsigned char* type, \ |
845 unsigned long long* value, \ | |
846 scoped_ptr<base::debug::ConvertableToJSON>* convertable_value) { \ | |
844 TraceValueUnion type_value; \ | 847 TraceValueUnion type_value; \ |
845 type_value.union_member = arg; \ | 848 type_value.union_member = arg; \ |
846 *type = value_type_id; \ | 849 *type = value_type_id; \ |
847 *value = type_value.as_uint; \ | 850 *value = type_value.as_uint; \ |
848 } | 851 } |
849 // Simpler form for int types that can be safely casted. | 852 // Simpler form for int types that can be safely casted. |
850 #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ | 853 #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, \ |
851 value_type_id) \ | 854 value_type_id) \ |
852 static inline void SetTraceValue(actual_type arg, \ | 855 static inline void SetTraceValue( \ |
853 unsigned char* type, \ | 856 actual_type arg, \ |
854 unsigned long long* value) { \ | 857 unsigned char* type, \ |
858 unsigned long long* value, \ | |
859 scoped_ptr<base::debug::ConvertableToJSON>* convertable_value) { \ | |
855 *type = value_type_id; \ | 860 *type = value_type_id; \ |
856 *value = static_cast<unsigned long long>(arg); \ | 861 *value = static_cast<unsigned long long>(arg); \ |
857 } | 862 } |
858 | 863 |
859 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) | 864 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) |
860 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) | 865 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT) |
861 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) | 866 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) |
862 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) | 867 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) |
863 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) | 868 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) |
864 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) | 869 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT) |
865 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT) | 870 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long, TRACE_VALUE_TYPE_INT) |
866 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) | 871 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT) |
867 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) | 872 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT) |
868 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) | 873 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT) |
869 INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) | 874 INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) |
870 INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) | 875 INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) |
871 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, | 876 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, |
872 TRACE_VALUE_TYPE_POINTER) | 877 TRACE_VALUE_TYPE_POINTER) |
873 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, | 878 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, |
874 TRACE_VALUE_TYPE_STRING) | 879 TRACE_VALUE_TYPE_STRING) |
875 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, | 880 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, |
876 TRACE_VALUE_TYPE_COPY_STRING) | 881 TRACE_VALUE_TYPE_COPY_STRING) |
877 | 882 |
878 #undef INTERNAL_DECLARE_SET_TRACE_VALUE | 883 #undef INTERNAL_DECLARE_SET_TRACE_VALUE |
879 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT | 884 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT |
880 | 885 |
881 // std::string version of SetTraceValue so that trace arguments can be strings. | 886 // std::string version of SetTraceValue so that trace arguments can be strings. |
882 static inline void SetTraceValue(const std::string& arg, | 887 static inline void SetTraceValue( |
883 unsigned char* type, | 888 const std::string& arg, |
884 unsigned long long* value) { | 889 unsigned char* type, |
890 unsigned long long* value, | |
891 scoped_ptr<base::debug::ConvertableToJSON>* convertable_value) { | |
885 TraceValueUnion type_value; | 892 TraceValueUnion type_value; |
886 type_value.as_string = arg.c_str(); | 893 type_value.as_string = arg.c_str(); |
887 *type = TRACE_VALUE_TYPE_COPY_STRING; | 894 *type = TRACE_VALUE_TYPE_COPY_STRING; |
888 *value = type_value.as_uint; | 895 *value = type_value.as_uint; |
889 } | 896 } |
890 | 897 |
898 static inline void SetTraceValue( | |
899 base::debug::ConvertableToJSON* arg, | |
dsinclair
2013/04/09 22:37:45
This has to be scoped_ptr<base::debug::Convertable
dsinclair
2013/04/10 01:09:31
Done.
| |
900 unsigned char* type, | |
901 unsigned long long* value, | |
902 scoped_ptr<base::debug::ConvertableToJSON>* convertable_value) { | |
903 *type = TRACE_VALUE_TYPE_CONVERTABLE; | |
904 convertable_value->reset(arg); | |
905 } | |
906 | |
891 // These AddTraceEvent and AddTraceEventWithThreadIdAndTimestamp template | 907 // These AddTraceEvent and AddTraceEventWithThreadIdAndTimestamp template |
892 // functions are defined here instead of in the macro, because the arg_values | 908 // functions are defined here instead of in the macro, because the arg_values |
893 // could be temporary objects, such as std::string. In order to store | 909 // could be temporary objects, such as std::string. In order to store |
894 // pointers to the internal c_str and pass through to the tracing API, | 910 // pointers to the internal c_str and pass through to the tracing API, |
895 // the arg_values must live throughout these procedures. | 911 // the arg_values must live throughout these procedures. |
896 | 912 |
897 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase, | 913 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase, |
898 const unsigned char* category_enabled, | 914 const unsigned char* category_enabled, |
899 const char* name, | 915 const char* name, |
900 unsigned long long id, | 916 unsigned long long id, |
901 int thread_id, | 917 int thread_id, |
902 const base::TimeTicks& timestamp, | 918 const base::TimeTicks& timestamp, |
903 unsigned char flags) { | 919 unsigned char flags) { |
904 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 920 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
905 phase, category_enabled, name, id, thread_id, timestamp, | 921 phase, category_enabled, name, id, thread_id, timestamp, |
906 kZeroNumArgs, NULL, NULL, NULL, flags); | 922 kZeroNumArgs, NULL, NULL, NULL, NULL, flags); |
907 } | 923 } |
908 | 924 |
909 static inline void AddTraceEvent(char phase, | 925 static inline void AddTraceEvent(char phase, |
910 const unsigned char* category_enabled, | 926 const unsigned char* category_enabled, |
911 const char* name, | 927 const char* name, |
912 unsigned long long id, | 928 unsigned long long id, |
913 unsigned char flags) { | 929 unsigned char flags) { |
914 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | 930 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
915 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); | 931 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); |
916 AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id, | 932 AddTraceEventWithThreadIdAndTimestamp(phase, category_enabled, name, id, |
917 thread_id, now, flags); | 933 thread_id, now, flags); |
918 } | 934 } |
919 | 935 |
920 template<class ARG1_TYPE> | 936 template<class ARG1_TYPE> |
921 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase, | 937 static inline void AddTraceEventWithThreadIdAndTimestamp(char phase, |
922 const unsigned char* category_enabled, | 938 const unsigned char* category_enabled, |
923 const char* name, | 939 const char* name, |
924 unsigned long long id, | 940 unsigned long long id, |
925 int thread_id, | 941 int thread_id, |
926 const base::TimeTicks& timestamp, | 942 const base::TimeTicks& timestamp, |
927 unsigned char flags, | 943 unsigned char flags, |
928 const char* arg1_name, | 944 const char* arg1_name, |
929 const ARG1_TYPE& arg1_val) { | 945 const ARG1_TYPE& arg1_val) { |
930 const int num_args = 1; | 946 const int num_args = 1; |
931 unsigned char arg_types[1]; | 947 unsigned char arg_types[1]; |
932 unsigned long long arg_values[1]; | 948 unsigned long long arg_values[1]; |
933 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 949 scoped_ptr<base::debug::ConvertableToJSON> convertable_values[1]; |
950 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0], | |
951 &convertable_values[0]); | |
934 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 952 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
935 phase, category_enabled, name, id, thread_id, timestamp, | 953 phase, category_enabled, name, id, thread_id, timestamp, |
936 num_args, &arg1_name, arg_types, arg_values, flags); | 954 num_args, &arg1_name, arg_types, arg_values, convertable_values, flags); |
937 } | 955 } |
938 | 956 |
939 template<class ARG1_TYPE> | 957 template<class ARG1_TYPE> |
940 static inline void AddTraceEvent(char phase, | 958 static inline void AddTraceEvent(char phase, |
941 const unsigned char* category_enabled, | 959 const unsigned char* category_enabled, |
942 const char* name, | 960 const char* name, |
943 unsigned long long id, | 961 unsigned long long id, |
944 unsigned char flags, | 962 unsigned char flags, |
945 const char* arg1_name, | 963 const char* arg1_name, |
946 const ARG1_TYPE& arg1_val) { | 964 const ARG1_TYPE& arg1_val) { |
(...skipping 13 matching lines...) Expand all Loading... | |
960 const base::TimeTicks& timestamp, | 978 const base::TimeTicks& timestamp, |
961 unsigned char flags, | 979 unsigned char flags, |
962 const char* arg1_name, | 980 const char* arg1_name, |
963 const ARG1_TYPE& arg1_val, | 981 const ARG1_TYPE& arg1_val, |
964 const char* arg2_name, | 982 const char* arg2_name, |
965 const ARG2_TYPE& arg2_val) { | 983 const ARG2_TYPE& arg2_val) { |
966 const int num_args = 2; | 984 const int num_args = 2; |
967 const char* arg_names[2] = { arg1_name, arg2_name }; | 985 const char* arg_names[2] = { arg1_name, arg2_name }; |
968 unsigned char arg_types[2]; | 986 unsigned char arg_types[2]; |
969 unsigned long long arg_values[2]; | 987 unsigned long long arg_values[2]; |
970 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 988 scoped_ptr<base::debug::ConvertableToJSON> convertable_values[2]; |
971 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 989 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0], |
990 &convertable_values[0]); | |
991 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1], | |
992 &convertable_values[1]); | |
972 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 993 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
973 phase, category_enabled, name, id, thread_id, timestamp, | 994 phase, category_enabled, name, id, thread_id, timestamp, |
974 num_args, arg_names, arg_types, arg_values, flags); | 995 num_args, arg_names, arg_types, arg_values, convertable_values, flags); |
975 } | 996 } |
976 | 997 |
977 template<class ARG1_TYPE, class ARG2_TYPE> | 998 template<class ARG1_TYPE, class ARG2_TYPE> |
978 static inline void AddTraceEvent(char phase, | 999 static inline void AddTraceEvent(char phase, |
979 const unsigned char* category_enabled, | 1000 const unsigned char* category_enabled, |
980 const char* name, | 1001 const char* name, |
981 unsigned long long id, | 1002 unsigned long long id, |
982 unsigned char flags, | 1003 unsigned char flags, |
983 const char* arg1_name, | 1004 const char* arg1_name, |
984 const ARG1_TYPE& arg1_val, | 1005 const ARG1_TYPE& arg1_val, |
(...skipping 25 matching lines...) Expand all Loading... | |
1010 | 1031 |
1011 private: | 1032 private: |
1012 // Add the end event if the category is still enabled. | 1033 // Add the end event if the category is still enabled. |
1013 void AddEventIfEnabled() { | 1034 void AddEventIfEnabled() { |
1014 // Only called when p_data_ is non-null. | 1035 // Only called when p_data_ is non-null. |
1015 if (*p_data_->category_enabled) { | 1036 if (*p_data_->category_enabled) { |
1016 TRACE_EVENT_API_ADD_TRACE_EVENT( | 1037 TRACE_EVENT_API_ADD_TRACE_EVENT( |
1017 TRACE_EVENT_PHASE_END, | 1038 TRACE_EVENT_PHASE_END, |
1018 p_data_->category_enabled, | 1039 p_data_->category_enabled, |
1019 p_data_->name, kNoEventId, | 1040 p_data_->name, kNoEventId, |
1020 kZeroNumArgs, NULL, NULL, NULL, | 1041 kZeroNumArgs, NULL, NULL, NULL, NULL, |
1021 TRACE_EVENT_FLAG_NONE); | 1042 TRACE_EVENT_FLAG_NONE); |
1022 } | 1043 } |
1023 } | 1044 } |
1024 | 1045 |
1025 // This Data struct workaround is to avoid initializing all the members | 1046 // This Data struct workaround is to avoid initializing all the members |
1026 // in Data during construction of this object, since this object is always | 1047 // in Data during construction of this object, since this object is always |
1027 // constructed, even when tracing is disabled. If the members of Data were | 1048 // constructed, even when tracing is disabled. If the members of Data were |
1028 // members of this class instead, compiler warnings occur about potential | 1049 // members of this class instead, compiler warnings occur about potential |
1029 // uninitialized accesses. | 1050 // uninitialized accesses. |
1030 struct Data { | 1051 struct Data { |
(...skipping 26 matching lines...) Expand all Loading... | |
1057 // This macro generates less code then TRACE_EVENT0 but is also | 1078 // This macro generates less code then TRACE_EVENT0 but is also |
1058 // slower to execute when tracing is off. It should generally only be | 1079 // slower to execute when tracing is off. It should generally only be |
1059 // used with code that is seldom executed or conditionally executed | 1080 // used with code that is seldom executed or conditionally executed |
1060 // when debugging. | 1081 // when debugging. |
1061 #define TRACE_EVENT_BINARY_EFFICIENT0(category, name) \ | 1082 #define TRACE_EVENT_BINARY_EFFICIENT0(category, name) \ |
1062 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category, name) | 1083 INTERNAL_TRACE_EVENT_BINARY_EFFICIENT_ADD_SCOPED(category, name) |
1063 | 1084 |
1064 } // namespace trace_event_internal | 1085 } // namespace trace_event_internal |
1065 | 1086 |
1066 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_ | 1087 #endif // BASE_DEBUG_TRACE_EVENT_INTERNAL_H_ |
OLD | NEW |