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

Side by Side Diff: base/trace_event/trace_event.h

Issue 869043008: Reland of Move tracing namespace from base::debug to base::trace_event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Fix suppressions Created 5 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
« no previous file with comments | « no previous file | base/trace_event/trace_event_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // 134 //
135 // 135 //
136 // Convertable notes: 136 // Convertable notes:
137 // Converting a large data type to a string can be costly. To help with this, 137 // Converting a large data type to a string can be costly. To help with this,
138 // the trace framework provides an interface ConvertableToTraceFormat. If you 138 // the trace framework provides an interface ConvertableToTraceFormat. If you
139 // inherit from it and implement the AppendAsTraceFormat method the trace 139 // inherit from it and implement the AppendAsTraceFormat method the trace
140 // framework will call back to your object to convert a trace output time. This 140 // framework will call back to your object to convert a trace output time. This
141 // means, if the category for the event is disabled, the conversion will not 141 // means, if the category for the event is disabled, the conversion will not
142 // happen. 142 // happen.
143 // 143 //
144 // class MyData : public base::debug::ConvertableToTraceFormat { 144 // class MyData : public base::trace_event::ConvertableToTraceFormat {
145 // public: 145 // public:
146 // MyData() {} 146 // MyData() {}
147 // virtual void AppendAsTraceFormat(std::string* out) const override { 147 // virtual void AppendAsTraceFormat(std::string* out) const override {
148 // out->append("{\"foo\":1}"); 148 // out->append("{\"foo\":1}");
149 // } 149 // }
150 // private: 150 // private:
151 // virtual ~MyData() {} 151 // virtual ~MyData() {}
152 // DISALLOW_COPY_AND_ASSIGN(MyData); 152 // DISALLOW_COPY_AND_ASSIGN(MyData);
153 // }; 153 // };
154 // 154 //
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, \ 788 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, \
789 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE,\ 789 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE,\
790 "snapshot", snapshot) 790 "snapshot", snapshot)
791 791
792 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \ 792 #define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
793 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \ 793 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_DELETE_OBJECT, \
794 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE) 794 category_group, name, TRACE_ID_DONT_MANGLE(id), TRACE_EVENT_FLAG_NONE)
795 795
796 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ 796 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
797 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ 797 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
798 (base::debug::TraceLog::ENABLED_FOR_RECORDING | \ 798 (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \
799 base::debug::TraceLog::ENABLED_FOR_EVENT_CALLBACK)) 799 base::trace_event::TraceLog::ENABLED_FOR_EVENT_CALLBACK))
800 800
801 // Macro to efficiently determine if a given category group is enabled. 801 // Macro to efficiently determine if a given category group is enabled.
802 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \ 802 #define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret) \
803 do { \ 803 do { \
804 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 804 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
805 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 805 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
806 *ret = true; \ 806 *ret = true; \
807 } else { \ 807 } else { \
808 *ret = false; \ 808 *ret = false; \
809 } \ 809 } \
(...skipping 22 matching lines...) Expand all
832 // long-lived literal strings should be given as the category group. The 832 // long-lived literal strings should be given as the category group. The
833 // returned pointer can be held permanently in a local static for example. If 833 // returned pointer can be held permanently in a local static for example. If
834 // the unsigned char is non-zero, tracing is enabled. If tracing is enabled, 834 // the unsigned char is non-zero, tracing is enabled. If tracing is enabled,
835 // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled 835 // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled
836 // between the load of the tracing state and the call to 836 // between the load of the tracing state and the call to
837 // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out 837 // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out
838 // for best performance when tracing is disabled. 838 // for best performance when tracing is disabled.
839 // const unsigned char* 839 // const unsigned char*
840 // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group) 840 // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
841 #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \ 841 #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
842 base::debug::TraceLog::GetCategoryGroupEnabled 842 base::trace_event::TraceLog::GetCategoryGroupEnabled
843 843
844 // Get the number of times traces have been recorded. This is used to implement 844 // Get the number of times traces have been recorded. This is used to implement
845 // the TRACE_EVENT_IS_NEW_TRACE facility. 845 // the TRACE_EVENT_IS_NEW_TRACE facility.
846 // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED() 846 // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED()
847 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \ 847 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \
848 base::debug::TraceLog::GetInstance()->GetNumTracesRecorded 848 base::trace_event::TraceLog::GetInstance()->GetNumTracesRecorded
849 849
850 // Add a trace event to the platform tracing system. 850 // Add a trace event to the platform tracing system.
851 // base::debug::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT( 851 // base::trace_event::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT(
852 // char phase, 852 // char phase,
853 // const unsigned char* category_group_enabled, 853 // const unsigned char* category_group_enabled,
854 // const char* name, 854 // const char* name,
855 // unsigned long long id, 855 // unsigned long long id,
856 // int num_args, 856 // int num_args,
857 // const char** arg_names, 857 // const char** arg_names,
858 // const unsigned char* arg_types, 858 // const unsigned char* arg_types,
859 // const unsigned long long* arg_values, 859 // const unsigned long long* arg_values,
860 // unsigned char flags) 860 // unsigned char flags)
861 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ 861 #define TRACE_EVENT_API_ADD_TRACE_EVENT \
862 base::debug::TraceLog::GetInstance()->AddTraceEvent 862 base::trace_event::TraceLog::GetInstance()->AddTraceEvent
863 863
864 // Add a trace event to the platform tracing system. 864 // Add a trace event to the platform tracing system.
865 // base::debug::TraceEventHandle TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP( 865 // base::trace_event::TraceEventHandle
866 // TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_TIMESTAMP(
866 // char phase, 867 // char phase,
867 // const unsigned char* category_group_enabled, 868 // const unsigned char* category_group_enabled,
868 // const char* name, 869 // const char* name,
869 // unsigned long long id, 870 // unsigned long long id,
870 // int thread_id, 871 // int thread_id,
871 // const TimeTicks& timestamp, 872 // const TimeTicks& timestamp,
872 // int num_args, 873 // int num_args,
873 // const char** arg_names, 874 // const char** arg_names,
874 // const unsigned char* arg_types, 875 // const unsigned char* arg_types,
875 // const unsigned long long* arg_values, 876 // const unsigned long long* arg_values,
876 // unsigned char flags) 877 // unsigned char flags)
877 #define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP \ 878 #define TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP \
878 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp 879 base::trace_event::TraceLog::GetInstance() \
880 ->AddTraceEventWithThreadIdAndTimestamp
879 881
880 // Set the duration field of a COMPLETE trace event. 882 // Set the duration field of a COMPLETE trace event.
881 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( 883 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
882 // const unsigned char* category_group_enabled, 884 // const unsigned char* category_group_enabled,
883 // const char* name, 885 // const char* name,
884 // base::debug::TraceEventHandle id) 886 // base::trace_event::TraceEventHandle id)
885 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ 887 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
886 base::debug::TraceLog::GetInstance()->UpdateTraceEventDuration 888 base::trace_event::TraceLog::GetInstance()->UpdateTraceEventDuration
887 889
888 // Defines atomic operations used internally by the tracing system. 890 // Defines atomic operations used internally by the tracing system.
889 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord 891 #define TRACE_EVENT_API_ATOMIC_WORD base::subtle::AtomicWord
890 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var)) 892 #define TRACE_EVENT_API_ATOMIC_LOAD(var) base::subtle::NoBarrier_Load(&(var))
891 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \ 893 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
892 base::subtle::NoBarrier_Store(&(var), (value)) 894 base::subtle::NoBarrier_Store(&(var), (value))
893 895
894 // Defines visibility for classes in trace_event.h 896 // Defines visibility for classes in trace_event.h
895 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT 897 #define TRACE_EVENT_API_CLASS_EXPORT BASE_EXPORT
896 898
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 } \ 951 } \
950 } while (0) 952 } while (0)
951 953
952 // Implementation detail: internal macro to create static category and add begin 954 // Implementation detail: internal macro to create static category and add begin
953 // event if the category is enabled. Also adds the end event when the scope 955 // event if the category is enabled. Also adds the end event when the scope
954 // ends. 956 // ends.
955 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ 957 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
956 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 958 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
957 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 959 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
958 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 960 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
959 base::debug::TraceEventHandle h = trace_event_internal::AddTraceEvent( \ 961 base::trace_event::TraceEventHandle h = \
960 TRACE_EVENT_PHASE_COMPLETE, \ 962 trace_event_internal::AddTraceEvent( \
961 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ 963 TRACE_EVENT_PHASE_COMPLETE, \
962 name, trace_event_internal::kNoEventId, \ 964 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
963 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 965 trace_event_internal::kNoEventId, TRACE_EVENT_FLAG_NONE, \
966 ##__VA_ARGS__); \
964 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ 967 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
965 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ 968 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
966 } 969 }
967 970
968 // Implementation detail: internal macro to create static category and add 971 // Implementation detail: internal macro to create static category and add
969 // event if the category is enabled. 972 // event if the category is enabled.
970 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 973 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
971 flags, ...) \ 974 flags, ...) \
972 do { \ 975 do { \
973 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 976 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 *type = TRACE_VALUE_TYPE_INT; 1249 *type = TRACE_VALUE_TYPE_INT;
1247 *value = arg.ToInternalValue(); 1250 *value = arg.ToInternalValue();
1248 } 1251 }
1249 1252
1250 // These AddTraceEvent and AddTraceEventWithThreadIdAndTimestamp template 1253 // These AddTraceEvent and AddTraceEventWithThreadIdAndTimestamp template
1251 // functions are defined here instead of in the macro, because the arg_values 1254 // functions are defined here instead of in the macro, because the arg_values
1252 // could be temporary objects, such as std::string. In order to store 1255 // could be temporary objects, such as std::string. In order to store
1253 // pointers to the internal c_str and pass through to the tracing API, 1256 // pointers to the internal c_str and pass through to the tracing API,
1254 // the arg_values must live throughout these procedures. 1257 // the arg_values must live throughout these procedures.
1255 1258
1256 static inline base::debug::TraceEventHandle 1259 static inline base::trace_event::TraceEventHandle
1257 AddTraceEventWithThreadIdAndTimestamp( 1260 AddTraceEventWithThreadIdAndTimestamp(
1258 char phase, 1261 char phase,
1259 const unsigned char* category_group_enabled, 1262 const unsigned char* category_group_enabled,
1260 const char* name, 1263 const char* name,
1261 unsigned long long id, 1264 unsigned long long id,
1262 int thread_id, 1265 int thread_id,
1263 const base::TimeTicks& timestamp, 1266 const base::TimeTicks& timestamp,
1264 unsigned char flags, 1267 unsigned char flags,
1265 const char* arg1_name, 1268 const char* arg1_name,
1266 const scoped_refptr<base::debug::ConvertableToTraceFormat>& arg1_val) { 1269 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
1270 arg1_val) {
1267 const int num_args = 1; 1271 const int num_args = 1;
1268 unsigned char arg_types[1] = { TRACE_VALUE_TYPE_CONVERTABLE }; 1272 unsigned char arg_types[1] = { TRACE_VALUE_TYPE_CONVERTABLE };
1269 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1273 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1270 phase, category_group_enabled, name, id, thread_id, timestamp, 1274 phase, category_group_enabled, name, id, thread_id, timestamp,
1271 num_args, &arg1_name, arg_types, NULL, &arg1_val, flags); 1275 num_args, &arg1_name, arg_types, NULL, &arg1_val, flags);
1272 } 1276 }
1273 1277
1274 template<class ARG1_TYPE> 1278 template<class ARG1_TYPE>
1275 static inline base::debug::TraceEventHandle 1279 static inline base::trace_event::TraceEventHandle
1276 AddTraceEventWithThreadIdAndTimestamp( 1280 AddTraceEventWithThreadIdAndTimestamp(
1277 char phase, 1281 char phase,
1278 const unsigned char* category_group_enabled, 1282 const unsigned char* category_group_enabled,
1279 const char* name, 1283 const char* name,
1280 unsigned long long id, 1284 unsigned long long id,
1281 int thread_id, 1285 int thread_id,
1282 const base::TimeTicks& timestamp, 1286 const base::TimeTicks& timestamp,
1283 unsigned char flags, 1287 unsigned char flags,
1284 const char* arg1_name, 1288 const char* arg1_name,
1285 const ARG1_TYPE& arg1_val, 1289 const ARG1_TYPE& arg1_val,
1286 const char* arg2_name, 1290 const char* arg2_name,
1287 const scoped_refptr<base::debug::ConvertableToTraceFormat>& arg2_val) { 1291 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
1292 arg2_val) {
1288 const int num_args = 2; 1293 const int num_args = 2;
1289 const char* arg_names[2] = { arg1_name, arg2_name }; 1294 const char* arg_names[2] = { arg1_name, arg2_name };
1290 1295
1291 unsigned char arg_types[2]; 1296 unsigned char arg_types[2];
1292 unsigned long long arg_values[2]; 1297 unsigned long long arg_values[2];
1293 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 1298 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
1294 arg_types[1] = TRACE_VALUE_TYPE_CONVERTABLE; 1299 arg_types[1] = TRACE_VALUE_TYPE_CONVERTABLE;
1295 1300
1296 scoped_refptr<base::debug::ConvertableToTraceFormat> convertable_values[2]; 1301 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1302 convertable_values[2];
1297 convertable_values[1] = arg2_val; 1303 convertable_values[1] = arg2_val;
1298 1304
1299 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1305 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1300 phase, category_group_enabled, name, id, thread_id, timestamp, 1306 phase, category_group_enabled, name, id, thread_id, timestamp,
1301 num_args, arg_names, arg_types, arg_values, convertable_values, flags); 1307 num_args, arg_names, arg_types, arg_values, convertable_values, flags);
1302 } 1308 }
1303 1309
1304 template<class ARG2_TYPE> 1310 template<class ARG2_TYPE>
1305 static inline base::debug::TraceEventHandle 1311 static inline base::trace_event::TraceEventHandle
1306 AddTraceEventWithThreadIdAndTimestamp( 1312 AddTraceEventWithThreadIdAndTimestamp(
1307 char phase, 1313 char phase,
1308 const unsigned char* category_group_enabled, 1314 const unsigned char* category_group_enabled,
1309 const char* name, 1315 const char* name,
1310 unsigned long long id, 1316 unsigned long long id,
1311 int thread_id, 1317 int thread_id,
1312 const base::TimeTicks& timestamp, 1318 const base::TimeTicks& timestamp,
1313 unsigned char flags, 1319 unsigned char flags,
1314 const char* arg1_name, 1320 const char* arg1_name,
1315 const scoped_refptr<base::debug::ConvertableToTraceFormat>& arg1_val, 1321 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val,
1316 const char* arg2_name, 1322 const char* arg2_name,
1317 const ARG2_TYPE& arg2_val) { 1323 const ARG2_TYPE& arg2_val) {
1318 const int num_args = 2; 1324 const int num_args = 2;
1319 const char* arg_names[2] = { arg1_name, arg2_name }; 1325 const char* arg_names[2] = { arg1_name, arg2_name };
1320 1326
1321 unsigned char arg_types[2]; 1327 unsigned char arg_types[2];
1322 unsigned long long arg_values[2]; 1328 unsigned long long arg_values[2];
1323 arg_types[0] = TRACE_VALUE_TYPE_CONVERTABLE; 1329 arg_types[0] = TRACE_VALUE_TYPE_CONVERTABLE;
1324 arg_values[0] = 0; 1330 arg_values[0] = 0;
1325 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); 1331 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
1326 1332
1327 scoped_refptr<base::debug::ConvertableToTraceFormat> convertable_values[2]; 1333 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1334 convertable_values[2];
1328 convertable_values[0] = arg1_val; 1335 convertable_values[0] = arg1_val;
1329 1336
1330 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1337 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1331 phase, category_group_enabled, name, id, thread_id, timestamp, 1338 phase, category_group_enabled, name, id, thread_id, timestamp,
1332 num_args, arg_names, arg_types, arg_values, convertable_values, flags); 1339 num_args, arg_names, arg_types, arg_values, convertable_values, flags);
1333 } 1340 }
1334 1341
1335 static inline base::debug::TraceEventHandle 1342 static inline base::trace_event::TraceEventHandle
1336 AddTraceEventWithThreadIdAndTimestamp( 1343 AddTraceEventWithThreadIdAndTimestamp(
1337 char phase, 1344 char phase,
1338 const unsigned char* category_group_enabled, 1345 const unsigned char* category_group_enabled,
1339 const char* name, 1346 const char* name,
1340 unsigned long long id, 1347 unsigned long long id,
1341 int thread_id, 1348 int thread_id,
1342 const base::TimeTicks& timestamp, 1349 const base::TimeTicks& timestamp,
1343 unsigned char flags, 1350 unsigned char flags,
1344 const char* arg1_name, 1351 const char* arg1_name,
1345 const scoped_refptr<base::debug::ConvertableToTraceFormat>& arg1_val, 1352 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>& arg1_val,
1346 const char* arg2_name, 1353 const char* arg2_name,
1347 const scoped_refptr<base::debug::ConvertableToTraceFormat>& arg2_val) { 1354 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>&
1355 arg2_val) {
1348 const int num_args = 2; 1356 const int num_args = 2;
1349 const char* arg_names[2] = { arg1_name, arg2_name }; 1357 const char* arg_names[2] = { arg1_name, arg2_name };
1350 unsigned char arg_types[2] = 1358 unsigned char arg_types[2] =
1351 { TRACE_VALUE_TYPE_CONVERTABLE, TRACE_VALUE_TYPE_CONVERTABLE }; 1359 { TRACE_VALUE_TYPE_CONVERTABLE, TRACE_VALUE_TYPE_CONVERTABLE };
1352 scoped_refptr<base::debug::ConvertableToTraceFormat> convertable_values[2] = 1360 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1353 { arg1_val, arg2_val }; 1361 convertable_values[2] = {arg1_val, arg2_val};
1354 1362
1355 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1363 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1356 phase, category_group_enabled, name, id, thread_id, timestamp, 1364 phase, category_group_enabled, name, id, thread_id, timestamp,
1357 num_args, arg_names, arg_types, NULL, convertable_values, flags); 1365 num_args, arg_names, arg_types, NULL, convertable_values, flags);
1358 } 1366 }
1359 1367
1360 static inline base::debug::TraceEventHandle 1368 static inline base::trace_event::TraceEventHandle
1361 AddTraceEventWithThreadIdAndTimestamp( 1369 AddTraceEventWithThreadIdAndTimestamp(
1362 char phase, 1370 char phase,
1363 const unsigned char* category_group_enabled, 1371 const unsigned char* category_group_enabled,
1364 const char* name, 1372 const char* name,
1365 unsigned long long id, 1373 unsigned long long id,
1366 int thread_id, 1374 int thread_id,
1367 const base::TimeTicks& timestamp, 1375 const base::TimeTicks& timestamp,
1368 unsigned char flags) { 1376 unsigned char flags) {
1369 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1377 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1370 phase, category_group_enabled, name, id, thread_id, timestamp, 1378 phase, category_group_enabled, name, id, thread_id, timestamp,
1371 kZeroNumArgs, NULL, NULL, NULL, NULL, flags); 1379 kZeroNumArgs, NULL, NULL, NULL, NULL, flags);
1372 } 1380 }
1373 1381
1374 static inline base::debug::TraceEventHandle AddTraceEvent( 1382 static inline base::trace_event::TraceEventHandle AddTraceEvent(
1375 char phase, 1383 char phase,
1376 const unsigned char* category_group_enabled, 1384 const unsigned char* category_group_enabled,
1377 const char* name, 1385 const char* name,
1378 unsigned long long id, 1386 unsigned long long id,
1379 unsigned char flags) { 1387 unsigned char flags) {
1380 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1388 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1381 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); 1389 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime();
1382 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 1390 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
1383 name, id, thread_id, now, flags); 1391 name, id, thread_id, now, flags);
1384 } 1392 }
1385 1393
1386 template<class ARG1_TYPE> 1394 template<class ARG1_TYPE>
1387 static inline base::debug::TraceEventHandle 1395 static inline base::trace_event::TraceEventHandle
1388 AddTraceEventWithThreadIdAndTimestamp( 1396 AddTraceEventWithThreadIdAndTimestamp(
1389 char phase, 1397 char phase,
1390 const unsigned char* category_group_enabled, 1398 const unsigned char* category_group_enabled,
1391 const char* name, 1399 const char* name,
1392 unsigned long long id, 1400 unsigned long long id,
1393 int thread_id, 1401 int thread_id,
1394 const base::TimeTicks& timestamp, 1402 const base::TimeTicks& timestamp,
1395 unsigned char flags, 1403 unsigned char flags,
1396 const char* arg1_name, 1404 const char* arg1_name,
1397 const ARG1_TYPE& arg1_val) { 1405 const ARG1_TYPE& arg1_val) {
1398 const int num_args = 1; 1406 const int num_args = 1;
1399 unsigned char arg_types[1]; 1407 unsigned char arg_types[1];
1400 unsigned long long arg_values[1]; 1408 unsigned long long arg_values[1];
1401 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 1409 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
1402 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1410 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1403 phase, category_group_enabled, name, id, thread_id, timestamp, 1411 phase, category_group_enabled, name, id, thread_id, timestamp,
1404 num_args, &arg1_name, arg_types, arg_values, NULL, flags); 1412 num_args, &arg1_name, arg_types, arg_values, NULL, flags);
1405 } 1413 }
1406 1414
1407 template<class ARG1_TYPE> 1415 template<class ARG1_TYPE>
1408 static inline base::debug::TraceEventHandle AddTraceEvent( 1416 static inline base::trace_event::TraceEventHandle AddTraceEvent(
1409 char phase, 1417 char phase,
1410 const unsigned char* category_group_enabled, 1418 const unsigned char* category_group_enabled,
1411 const char* name, 1419 const char* name,
1412 unsigned long long id, 1420 unsigned long long id,
1413 unsigned char flags, 1421 unsigned char flags,
1414 const char* arg1_name, 1422 const char* arg1_name,
1415 const ARG1_TYPE& arg1_val) { 1423 const ARG1_TYPE& arg1_val) {
1416 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1424 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1417 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime(); 1425 base::TimeTicks now = base::TimeTicks::NowFromSystemTraceTime();
1418 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 1426 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
1419 name, id, thread_id, now, flags, 1427 name, id, thread_id, now, flags,
1420 arg1_name, arg1_val); 1428 arg1_name, arg1_val);
1421 } 1429 }
1422 1430
1423 template<class ARG1_TYPE, class ARG2_TYPE> 1431 template<class ARG1_TYPE, class ARG2_TYPE>
1424 static inline base::debug::TraceEventHandle 1432 static inline base::trace_event::TraceEventHandle
1425 AddTraceEventWithThreadIdAndTimestamp( 1433 AddTraceEventWithThreadIdAndTimestamp(
1426 char phase, 1434 char phase,
1427 const unsigned char* category_group_enabled, 1435 const unsigned char* category_group_enabled,
1428 const char* name, 1436 const char* name,
1429 unsigned long long id, 1437 unsigned long long id,
1430 int thread_id, 1438 int thread_id,
1431 const base::TimeTicks& timestamp, 1439 const base::TimeTicks& timestamp,
1432 unsigned char flags, 1440 unsigned char flags,
1433 const char* arg1_name, 1441 const char* arg1_name,
1434 const ARG1_TYPE& arg1_val, 1442 const ARG1_TYPE& arg1_val,
1435 const char* arg2_name, 1443 const char* arg2_name,
1436 const ARG2_TYPE& arg2_val) { 1444 const ARG2_TYPE& arg2_val) {
1437 const int num_args = 2; 1445 const int num_args = 2;
1438 const char* arg_names[2] = { arg1_name, arg2_name }; 1446 const char* arg_names[2] = { arg1_name, arg2_name };
1439 unsigned char arg_types[2]; 1447 unsigned char arg_types[2];
1440 unsigned long long arg_values[2]; 1448 unsigned long long arg_values[2];
1441 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 1449 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
1442 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); 1450 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
1443 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1451 return TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1444 phase, category_group_enabled, name, id, thread_id, timestamp, 1452 phase, category_group_enabled, name, id, thread_id, timestamp,
1445 num_args, arg_names, arg_types, arg_values, NULL, flags); 1453 num_args, arg_names, arg_types, arg_values, NULL, flags);
1446 } 1454 }
1447 1455
1448 template<class ARG1_TYPE, class ARG2_TYPE> 1456 template<class ARG1_TYPE, class ARG2_TYPE>
1449 static inline base::debug::TraceEventHandle AddTraceEvent( 1457 static inline base::trace_event::TraceEventHandle AddTraceEvent(
1450 char phase, 1458 char phase,
1451 const unsigned char* category_group_enabled, 1459 const unsigned char* category_group_enabled,
1452 const char* name, 1460 const char* name,
1453 unsigned long long id, 1461 unsigned long long id,
1454 unsigned char flags, 1462 unsigned char flags,
1455 const char* arg1_name, 1463 const char* arg1_name,
1456 const ARG1_TYPE& arg1_val, 1464 const ARG1_TYPE& arg1_val,
1457 const char* arg2_name, 1465 const char* arg2_name,
1458 const ARG2_TYPE& arg2_val) { 1466 const ARG2_TYPE& arg2_val) {
1459 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1467 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
(...skipping 11 matching lines...) Expand all
1471 ScopedTracer() : p_data_(NULL) {} 1479 ScopedTracer() : p_data_(NULL) {}
1472 1480
1473 ~ScopedTracer() { 1481 ~ScopedTracer() {
1474 if (p_data_ && *data_.category_group_enabled) 1482 if (p_data_ && *data_.category_group_enabled)
1475 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( 1483 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
1476 data_.category_group_enabled, data_.name, data_.event_handle); 1484 data_.category_group_enabled, data_.name, data_.event_handle);
1477 } 1485 }
1478 1486
1479 void Initialize(const unsigned char* category_group_enabled, 1487 void Initialize(const unsigned char* category_group_enabled,
1480 const char* name, 1488 const char* name,
1481 base::debug::TraceEventHandle event_handle) { 1489 base::trace_event::TraceEventHandle event_handle) {
1482 data_.category_group_enabled = category_group_enabled; 1490 data_.category_group_enabled = category_group_enabled;
1483 data_.name = name; 1491 data_.name = name;
1484 data_.event_handle = event_handle; 1492 data_.event_handle = event_handle;
1485 p_data_ = &data_; 1493 p_data_ = &data_;
1486 } 1494 }
1487 1495
1488 private: 1496 private:
1489 // This Data struct workaround is to avoid initializing all the members 1497 // This Data struct workaround is to avoid initializing all the members
1490 // in Data during construction of this object, since this object is always 1498 // in Data during construction of this object, since this object is always
1491 // constructed, even when tracing is disabled. If the members of Data were 1499 // constructed, even when tracing is disabled. If the members of Data were
1492 // members of this class instead, compiler warnings occur about potential 1500 // members of this class instead, compiler warnings occur about potential
1493 // uninitialized accesses. 1501 // uninitialized accesses.
1494 struct Data { 1502 struct Data {
1495 const unsigned char* category_group_enabled; 1503 const unsigned char* category_group_enabled;
1496 const char* name; 1504 const char* name;
1497 base::debug::TraceEventHandle event_handle; 1505 base::trace_event::TraceEventHandle event_handle;
1498 }; 1506 };
1499 Data* p_data_; 1507 Data* p_data_;
1500 Data data_; 1508 Data data_;
1501 }; 1509 };
1502 1510
1503 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly. 1511 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
1504 class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient { 1512 class TRACE_EVENT_API_CLASS_EXPORT ScopedTraceBinaryEfficient {
1505 public: 1513 public:
1506 ScopedTraceBinaryEfficient(const char* category_group, const char* name); 1514 ScopedTraceBinaryEfficient(const char* category_group, const char* name);
1507 ~ScopedTraceBinaryEfficient(); 1515 ~ScopedTraceBinaryEfficient();
1508 1516
1509 private: 1517 private:
1510 const unsigned char* category_group_enabled_; 1518 const unsigned char* category_group_enabled_;
1511 const char* name_; 1519 const char* name_;
1512 base::debug::TraceEventHandle event_handle_; 1520 base::trace_event::TraceEventHandle event_handle_;
1513 }; 1521 };
1514 1522
1515 // This macro generates less code then TRACE_EVENT0 but is also 1523 // This macro generates less code then TRACE_EVENT0 but is also
1516 // slower to execute when tracing is off. It should generally only be 1524 // slower to execute when tracing is off. It should generally only be
1517 // used with code that is seldom executed or conditionally executed 1525 // used with code that is seldom executed or conditionally executed
1518 // when debugging. 1526 // when debugging.
1519 // For now the category_group must be "gpu". 1527 // For now the category_group must be "gpu".
1520 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \ 1528 #define TRACE_EVENT_BINARY_EFFICIENT0(category_group, name) \
1521 trace_event_internal::ScopedTraceBinaryEfficient \ 1529 trace_event_internal::ScopedTraceBinaryEfficient \
1522 INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name); 1530 INTERNAL_TRACE_EVENT_UID(scoped_trace)(category_group, name);
(...skipping 25 matching lines...) Expand all
1548 const_cast<char*>(category_and_name))); 1556 const_cast<char*>(category_and_name)));
1549 } 1557 }
1550 1558
1551 private: 1559 private:
1552 const char* previous_state_; 1560 const char* previous_state_;
1553 }; 1561 };
1554 1562
1555 } // namespace trace_event_internal 1563 } // namespace trace_event_internal
1556 1564
1557 namespace base { 1565 namespace base {
1558 namespace debug { 1566 namespace trace_event {
1559 1567
1560 template<typename IDType> class TraceScopedTrackableObject { 1568 template<typename IDType> class TraceScopedTrackableObject {
1561 public: 1569 public:
1562 TraceScopedTrackableObject(const char* category_group, const char* name, 1570 TraceScopedTrackableObject(const char* category_group, const char* name,
1563 IDType id) 1571 IDType id)
1564 : category_group_(category_group), 1572 : category_group_(category_group),
1565 name_(name), 1573 name_(name),
1566 id_(id) { 1574 id_(id) {
1567 TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group_, name_, id_); 1575 TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group_, name_, id_);
1568 } 1576 }
1569 1577
1570 template <typename ArgType> void snapshot(ArgType snapshot) { 1578 template <typename ArgType> void snapshot(ArgType snapshot) {
1571 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group_, name_, id_, snapshot); 1579 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group_, name_, id_, snapshot);
1572 } 1580 }
1573 1581
1574 ~TraceScopedTrackableObject() { 1582 ~TraceScopedTrackableObject() {
1575 TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group_, name_, id_); 1583 TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group_, name_, id_);
1576 } 1584 }
1577 1585
1578 private: 1586 private:
1579 const char* category_group_; 1587 const char* category_group_;
1580 const char* name_; 1588 const char* name_;
1581 IDType id_; 1589 IDType id_;
1582 1590
1583 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 1591 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
1584 }; 1592 };
1585 1593
1586 } // namespace debug 1594 } // namespace trace_event
1587 } // namespace base 1595 } // namespace base
1596
1597 // TODO(ssid): remove these aliases after the tracing clients are moved to the
1598 // new trace_event namespace. See crbug.com/451032. ETA: March 2015.
1599 namespace base {
1600 namespace debug {
1601 using base::trace_event::TraceScopedTrackableObject;
1602 } // namespace debug
1603 } // namespace base
1588 1604
1589 #endif /* BASE_TRACE_EVENT_TRACE_EVENT_H_ */ 1605 #endif /* BASE_TRACE_EVENT_TRACE_EVENT_H_ */
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_event_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698