Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Trace events are for tracking application performance and resource usage. | 5 // Trace events are for tracking application performance and resource usage. |
| 6 // Macros are provided to track: | 6 // Macros are provided to track: |
| 7 // Begin and end of function calls | 7 // Begin and end of function calls |
| 8 // Counters | 8 // Counters |
| 9 // | 9 // |
| 10 // Events are issued against categories. Whereas LOG's | 10 // Events are issued against categories. Whereas LOG's |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 #include <vector> | 153 #include <vector> |
| 154 | 154 |
| 155 #include "base/callback.h" | 155 #include "base/callback.h" |
| 156 #include "base/hash_tables.h" | 156 #include "base/hash_tables.h" |
| 157 #include "base/memory/ref_counted_memory.h" | 157 #include "base/memory/ref_counted_memory.h" |
| 158 #include "base/string_util.h" | 158 #include "base/string_util.h" |
| 159 #include "base/synchronization/lock.h" | 159 #include "base/synchronization/lock.h" |
| 160 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 160 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 161 #include "base/timer.h" | 161 #include "base/timer.h" |
| 162 | 162 |
| 163 //////////////////////////////////////////////////////////////////////////////// | |
| 164 /// Customize these defines to call through to platform tracing APIs. | |
|
nduca
2012/01/11 21:49:11
You know, I'm starting to think we should make tra
jbates
2012/01/11 22:44:35
I think this sounds good, but this is a step-2 fee
jbates
2012/01/11 23:52:44
Removed TRACE_EVENT_NAMESPACE.
| |
| 165 | |
| 166 #define TRACE_EVENT_NAMESPACE base::debug | |
|
jar (doing other things)
2012/01/12 00:15:36
What does this macro help you with?
jbates
2012/01/12 00:52:20
Done. (removed)
| |
| 167 | |
| 168 // volatile bool* | |
| 169 // TRACE_EVENT_API_GET_CATEGORY_ENABLED(const char* category_name) | |
| 170 #define TRACE_EVENT_API_GET_CATEGORY_ENABLED \ | |
| 171 TRACE_EVENT_NAMESPACE::TraceLog::GetCategoryEnabled | |
| 172 | |
| 173 // Returns the threshold_begin_id used by TRACE_IF_LONGER_THAN macros. | |
| 174 // int TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 175 // char phase, | |
| 176 // const volatile bool* category_enabled, | |
| 177 // const char* name, | |
| 178 // uint64 id, | |
| 179 // int num_args, | |
| 180 // const char** arg_names, | |
| 181 // const uint8* arg_types, | |
| 182 // const uint64* arg_values, | |
| 183 // int threshold_begin_id, | |
| 184 // int64 threshold, | |
| 185 // uint8 flags) | |
| 186 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | |
| 187 TRACE_EVENT_NAMESPACE::TraceLog::GetInstance()->AddTraceEvent | |
| 188 | |
| 189 // void TRACE_EVENT_API_ADD_COUNTER_EVENT( | |
| 190 // const volatile bool* category_enabled, | |
| 191 // const char* name, | |
| 192 // uint64 id, | |
| 193 // const char* arg1_name, int32 arg1_val, | |
| 194 // const char* arg2_name, int32 arg2_val, | |
| 195 // uint8 flags) | |
| 196 #define TRACE_EVENT_API_ADD_COUNTER_EVENT \ | |
| 197 TRACE_EVENT_NAMESPACE::TraceLog::GetInstance()->AddCounterEvent | |
| 198 | |
| 199 // Mangle |pointer| with a process ID hash so that if |pointer| occurs on more | |
| 200 // than one process, it will not collide in the trace data. | |
| 201 // uint64 TRACE_EVENT_API_GET_ID_FROM_POINTER(void* pointer) | |
| 202 #define TRACE_EVENT_API_GET_ID_FROM_POINTER \ | |
| 203 TRACE_EVENT_NAMESPACE::TraceLog::GetInstance()->GetInterProcessID | |
| 204 | |
| 205 //////////////////////////////////////////////////////////////////////////////// | |
| 206 | |
| 163 // By default, const char* argument values are assumed to have long-lived scope | 207 // By default, const char* argument values are assumed to have long-lived scope |
| 164 // and will not be copied. Use this macro to force a const char* to be copied. | 208 // and will not be copied. Use this macro to force a const char* to be copied. |
| 165 #define TRACE_STR_COPY(str) base::debug::TraceValue::StringWithCopy(str) | 209 #define TRACE_STR_COPY(str) \ |
| 210 TRACE_EVENT_NAMESPACE::internal::TraceStringWithCopy(str) | |
| 166 | 211 |
| 167 // Older style trace macros with explicit id and extra data | 212 // Older style trace macros with explicit id and extra data |
| 168 // Only these macros result in publishing data to ETW as currently implemented. | 213 // Only these macros result in publishing data to ETW as currently implemented. |
| 169 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ | 214 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ |
| 170 base::debug::TraceLog::AddTraceEventEtw( \ | 215 base::debug::TraceLog::AddTraceEventEtw( \ |
| 171 TRACE_EVENT_PHASE_BEGIN, \ | 216 TRACE_EVENT_PHASE_BEGIN, \ |
| 172 name, reinterpret_cast<const void*>(id), extra) | 217 name, reinterpret_cast<const void*>(id), extra) |
| 173 | 218 |
| 174 #define TRACE_EVENT_END_ETW(name, id, extra) \ | 219 #define TRACE_EVENT_END_ETW(name, id, extra) \ |
| 175 base::debug::TraceLog::AddTraceEventEtw( \ | 220 base::debug::TraceLog::AddTraceEventEtw( \ |
| 176 TRACE_EVENT_PHASE_END, \ | 221 TRACE_EVENT_PHASE_END, \ |
| 177 name, reinterpret_cast<const void*>(id), extra) | 222 name, reinterpret_cast<const void*>(id), extra) |
| 178 | 223 |
| 179 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ | 224 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ |
| 180 base::debug::TraceLog::AddTraceEventEtw( \ | 225 base::debug::TraceLog::AddTraceEventEtw( \ |
| 181 TRACE_EVENT_PHASE_INSTANT, \ | 226 TRACE_EVENT_PHASE_INSTANT, \ |
| 182 name, reinterpret_cast<const void*>(id), extra) | 227 name, reinterpret_cast<const void*>(id), extra) |
| 183 | 228 |
| 184 // Records a pair of begin and end events called "name" for the current | 229 // Records a pair of begin and end events called "name" for the current |
| 185 // scope, with 0, 1 or 2 associated arguments. If the category is not | 230 // scope, with 0, 1 or 2 associated arguments. If the category is not |
| 186 // enabled, then this does nothing. | 231 // enabled, then this does nothing. |
| 187 // - category and name strings must have application lifetime (statics or | 232 // - category and name strings must have application lifetime (statics or |
| 188 // literals). They may not include " chars. | 233 // literals). They may not include " chars. |
| 189 #define TRACE_EVENT0(category, name) \ | 234 #define TRACE_EVENT0(category, name) \ |
| 190 TRACE_EVENT1(category, name, NULL, 0) | 235 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name) |
| 191 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ | 236 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ |
| 192 TRACE_EVENT2(category, name, arg1_name, arg1_val, NULL, 0) | 237 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val) |
| 193 #define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | 238 #define TRACE_EVENT2(category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
| 194 INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | 239 INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, arg1_name, arg1_val, \ |
| 195 category, name, arg1_name, arg1_val, arg2_name, arg2_val) | 240 arg2_name, arg2_val) |
| 196 | 241 |
| 197 // Same as TRACE_EVENT except that they are not included in official builds. | 242 // Same as TRACE_EVENT except that they are not included in official builds. |
| 198 #ifdef OFFICIAL_BUILD | 243 #ifdef OFFICIAL_BUILD |
| 199 #define UNSHIPPED_TRACE_EVENT0(category, name) (void)0 | 244 #define UNSHIPPED_TRACE_EVENT0(category, name) (void)0 |
| 200 #define UNSHIPPED_TRACE_EVENT1(category, name, arg1_name, arg1_val) (void)0 | 245 #define UNSHIPPED_TRACE_EVENT1(category, name, arg1_name, arg1_val) (void)0 |
| 201 #define UNSHIPPED_TRACE_EVENT2(category, name, arg1_name, arg1_val, \ | 246 #define UNSHIPPED_TRACE_EVENT2(category, name, arg1_name, arg1_val, \ |
| 202 arg2_name, arg2_val) (void)0 | 247 arg2_name, arg2_val) (void)0 |
| 203 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category, name) (void)0 | 248 #define UNSHIPPED_TRACE_EVENT_INSTANT0(category, name) (void)0 |
| 204 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ | 249 #define UNSHIPPED_TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ |
| 205 (void)0 | 250 (void)0 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 222 TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ | 267 TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ |
| 223 arg2_name, arg2_val) | 268 arg2_name, arg2_val) |
| 224 #endif | 269 #endif |
| 225 | 270 |
| 226 // Records a single event called "name" immediately, with 0, 1 or 2 | 271 // Records a single event called "name" immediately, with 0, 1 or 2 |
| 227 // associated arguments. If the category is not enabled, then this | 272 // associated arguments. If the category is not enabled, then this |
| 228 // does nothing. | 273 // does nothing. |
| 229 // - category and name strings must have application lifetime (statics or | 274 // - category and name strings must have application lifetime (statics or |
| 230 // literals). They may not include " chars. | 275 // literals). They may not include " chars. |
| 231 #define TRACE_EVENT_INSTANT0(category, name) \ | 276 #define TRACE_EVENT_INSTANT0(category, name) \ |
| 232 TRACE_EVENT_INSTANT1(category, name, NULL, 0) | 277 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 278 category, name, TRACE_EVENT_FLAG_NONE) | |
| 233 #define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ | 279 #define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ |
| 234 TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) | 280 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 281 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 235 #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ | 282 #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ |
| 236 arg2_name, arg2_val) \ | 283 arg2_name, arg2_val) \ |
| 237 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | 284 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 238 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ | 285 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| 239 TRACE_EVENT_FLAG_NONE) | 286 arg2_name, arg2_val) |
| 240 #define TRACE_EVENT_COPY_INSTANT0(category, name) \ | 287 #define TRACE_EVENT_COPY_INSTANT0(category, name) \ |
| 241 TRACE_EVENT_COPY_INSTANT1(category, name, NULL, 0) | 288 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 289 category, name, TRACE_EVENT_FLAG_COPY) | |
| 242 #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ | 290 #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ |
| 243 TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) | 291 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 292 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
| 244 #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ | 293 #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ |
| 245 arg2_name, arg2_val) \ | 294 arg2_name, arg2_val) \ |
| 246 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ | 295 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
| 247 category, name, \ | 296 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| 248 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 297 arg2_name, arg2_val) |
| 249 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
| 250 TRACE_EVENT_FLAG_COPY) | |
| 251 | 298 |
| 252 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 | 299 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
| 253 // associated arguments. If the category is not enabled, then this | 300 // associated arguments. If the category is not enabled, then this |
| 254 // does nothing. | 301 // does nothing. |
| 255 // - category and name strings must have application lifetime (statics or | 302 // - category and name strings must have application lifetime (statics or |
| 256 // literals). They may not include " chars. | 303 // literals). They may not include " chars. |
| 257 #define TRACE_EVENT_BEGIN0(category, name) \ | 304 #define TRACE_EVENT_BEGIN0(category, name) \ |
| 258 TRACE_EVENT_BEGIN1(category, name, NULL, 0) | 305 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 306 category, name, TRACE_EVENT_FLAG_NONE) | |
| 259 #define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) \ | 307 #define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) \ |
| 260 TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) | 308 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 309 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 261 #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ | 310 #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ |
| 262 arg2_name, arg2_val) \ | 311 arg2_name, arg2_val) \ |
| 263 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 312 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 264 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ | 313 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| 265 TRACE_EVENT_FLAG_NONE) | 314 arg2_name, arg2_val) |
| 266 #define TRACE_EVENT_COPY_BEGIN0(category, name) \ | 315 #define TRACE_EVENT_COPY_BEGIN0(category, name) \ |
| 267 TRACE_EVENT_COPY_BEGIN1(category, name, NULL, 0) | 316 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 317 category, name, TRACE_EVENT_FLAG_COPY) | |
| 268 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ | 318 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ |
| 269 TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) | 319 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 320 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
| 270 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ | 321 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ |
| 271 arg2_name, arg2_val) \ | 322 arg2_name, arg2_val) \ |
| 272 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ | 323 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
| 273 category, name, \ | 324 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| 274 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 325 arg2_name, arg2_val) |
| 275 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
| 276 TRACE_EVENT_FLAG_COPY) | |
| 277 | 326 |
| 278 // Records a single END event for "name" immediately. If the category | 327 // Records a single END event for "name" immediately. If the category |
| 279 // is not enabled, then this does nothing. | 328 // is not enabled, then this does nothing. |
| 280 // - category and name strings must have application lifetime (statics or | 329 // - category and name strings must have application lifetime (statics or |
| 281 // literals). They may not include " chars. | 330 // literals). They may not include " chars. |
| 282 #define TRACE_EVENT_END0(category, name) \ | 331 #define TRACE_EVENT_END0(category, name) \ |
| 283 TRACE_EVENT_END1(category, name, NULL, 0) | 332 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 333 category, name, TRACE_EVENT_FLAG_NONE) | |
| 284 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ | 334 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ |
| 285 TRACE_EVENT_END2(category, name, arg1_name, arg1_val, NULL, 0) | 335 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 336 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val) | |
| 286 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ | 337 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ |
| 287 arg2_name, arg2_val) \ | 338 arg2_name, arg2_val) \ |
| 288 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 339 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 289 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ | 340 category, name, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, \ |
| 290 TRACE_EVENT_FLAG_NONE) | 341 arg2_name, arg2_val) |
| 291 #define TRACE_EVENT_COPY_END0(category, name) \ | 342 #define TRACE_EVENT_COPY_END0(category, name) \ |
| 292 TRACE_EVENT_COPY_END1(category, name, NULL, 0) | 343 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 344 category, name, TRACE_EVENT_FLAG_COPY) | |
| 293 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ | 345 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ |
| 294 TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, NULL, 0) | 346 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 347 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val) | |
| 295 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ | 348 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ |
| 296 arg2_name, arg2_val) \ | 349 arg2_name, arg2_val) \ |
| 297 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ | 350 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
| 298 category, name, \ | 351 category, name, TRACE_EVENT_FLAG_COPY, arg1_name, arg1_val, \ |
| 299 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 352 arg2_name, arg2_val) |
| 300 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
| 301 TRACE_EVENT_FLAG_COPY) | |
| 302 | 353 |
| 303 // Time threshold event: | 354 // Time threshold event: |
| 304 // Only record the event if the duration is greater than the specified | 355 // Only record the event if the duration is greater than the specified |
| 305 // threshold_us (time in microseconds). | 356 // threshold_us (time in microseconds). |
| 306 // Records a pair of begin and end events called "name" for the current | 357 // Records a pair of begin and end events called "name" for the current |
| 307 // scope, with 0, 1 or 2 associated arguments. If the category is not | 358 // scope, with 0, 1 or 2 associated arguments. If the category is not |
| 308 // enabled, then this does nothing. | 359 // enabled, then this does nothing. |
| 309 // - category and name strings must have application lifetime (statics or | 360 // - category and name strings must have application lifetime (statics or |
| 310 // literals). They may not include " chars. | 361 // literals). They may not include " chars. |
| 311 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ | 362 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ |
| 312 TRACE_EVENT_IF_LONGER_THAN1(threshold_us, category, name, NULL, 0) | 363 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, category, name) |
| 313 #define TRACE_EVENT_IF_LONGER_THAN1( \ | 364 #define TRACE_EVENT_IF_LONGER_THAN1( \ |
| 314 threshold_us, category, name, arg1_name, arg1_val) \ | 365 threshold_us, category, name, arg1_name, arg1_val) \ |
| 315 TRACE_EVENT_IF_LONGER_THAN2(threshold_us, category, name, \ | 366 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN( \ |
| 316 arg1_name, arg1_val, NULL, 0) | 367 threshold_us, category, name, arg1_name, arg1_val) |
| 317 #define TRACE_EVENT_IF_LONGER_THAN2( \ | 368 #define TRACE_EVENT_IF_LONGER_THAN2( \ |
| 318 threshold_us, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | 369 threshold_us, category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
| 319 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold_us, \ | 370 INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN( \ |
| 320 category, name, arg1_name, arg1_val, arg2_name, arg2_val) | 371 threshold_us, category, name, arg1_name, arg1_val, arg2_name, arg2_val) |
| 321 | 372 |
| 322 // Records the value of a counter called "name" immediately. Value | 373 // Records the value of a counter called "name" immediately. Value |
| 323 // must be representable as a 32 bit integer. | 374 // must be representable as a 32 bit integer. |
| 324 // - category and name strings must have application lifetime (statics or | 375 // - category and name strings must have application lifetime (statics or |
| 325 // literals). They may not include " chars. | 376 // literals). They may not include " chars. |
| 326 #define TRACE_COUNTER1(category, name, value) \ | 377 #define TRACE_COUNTER1(category, name, value) \ |
| 327 TRACE_COUNTER2(category, name, "value", value, NULL, 0) | 378 TRACE_COUNTER2(category, name, "value", value, NULL, 0) |
| 328 #define TRACE_COPY_COUNTER1(category, name, value) \ | 379 #define TRACE_COPY_COUNTER1(category, name, value) \ |
| 329 TRACE_COPY_COUNTER2(category, name, "value", value, NULL, 0) | 380 TRACE_COPY_COUNTER2(category, name, "value", value, NULL, 0) |
| 330 | 381 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 // Records a single START event called "name" immediately, with 0, 1 or 2 | 436 // Records a single START event called "name" immediately, with 0, 1 or 2 |
| 386 // associated arguments. If the category is not enabled, then this | 437 // associated arguments. If the category is not enabled, then this |
| 387 // does nothing. | 438 // does nothing. |
| 388 // - category and name strings must have application lifetime (statics or | 439 // - category and name strings must have application lifetime (statics or |
| 389 // literals). They may not include " chars. | 440 // literals). They may not include " chars. |
| 390 // - |id| is used to match the START event with the FINISH event. It must either | 441 // - |id| is used to match the START event with the FINISH event. It must either |
| 391 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits | 442 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits |
| 392 // will be xored with a hash of the process ID so that the same pointer on | 443 // will be xored with a hash of the process ID so that the same pointer on |
| 393 // two different processes will not collide. | 444 // two different processes will not collide. |
| 394 #define TRACE_EVENT_START0(category, name, id) \ | 445 #define TRACE_EVENT_START0(category, name, id) \ |
| 395 TRACE_EVENT_START1(category, name, id, NULL, 0) | 446 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| 447 category, name, id, TRACE_EVENT_FLAG_HAS_ID) | |
| 396 #define TRACE_EVENT_START1(category, name, id, arg1_name, arg1_val) \ | 448 #define TRACE_EVENT_START1(category, name, id, arg1_name, arg1_val) \ |
| 397 TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, NULL, 0) | 449 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| 450 category, name, id, TRACE_EVENT_FLAG_HAS_ID, arg1_name, arg1_val) | |
| 398 #define TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, \ | 451 #define TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, \ |
| 399 arg2_name, arg2_val) \ | 452 arg2_name, arg2_val) \ |
| 400 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ | 453 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| 401 category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ | 454 category, name, id, TRACE_EVENT_FLAG_HAS_ID, \ |
| 402 TRACE_EVENT_FLAG_HAS_ID) | 455 arg1_name, arg1_val, arg2_name, arg2_val) |
| 403 #define TRACE_EVENT_COPY_START0(category, name, id) \ | 456 #define TRACE_EVENT_COPY_START0(category, name, id) \ |
| 404 TRACE_EVENT_COPY_START1(category, name, id, NULL, 0) | 457 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| 458 category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) | |
| 405 #define TRACE_EVENT_COPY_START1(category, name, id, arg1_name, arg1_val) \ | 459 #define TRACE_EVENT_COPY_START1(category, name, id, arg1_name, arg1_val) \ |
| 406 TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, NULL, 0) | 460 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| 461 category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ | |
| 462 arg1_name, arg1_val) | |
| 407 #define TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, \ | 463 #define TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, \ |
| 408 arg2_name, arg2_val) \ | 464 arg2_name, arg2_val) \ |
| 409 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ | 465 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ |
| 410 category, name, id, \ | 466 category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ |
| 411 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 467 arg1_name, arg1_val, arg2_name, arg2_val) |
| 412 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
| 413 TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) | |
| 414 | 468 |
| 415 // Records a single FINISH event for "name" immediately. If the category | 469 // Records a single FINISH event for "name" immediately. If the category |
| 416 // is not enabled, then this does nothing. | 470 // is not enabled, then this does nothing. |
| 417 #define TRACE_EVENT_FINISH0(category, name, id) \ | 471 #define TRACE_EVENT_FINISH0(category, name, id) \ |
| 418 TRACE_EVENT_FINISH1(category, name, id, NULL, 0) | 472 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| 473 category, name, id, TRACE_EVENT_FLAG_HAS_ID) | |
| 419 #define TRACE_EVENT_FINISH1(category, name, id, arg1_name, arg1_val) \ | 474 #define TRACE_EVENT_FINISH1(category, name, id, arg1_name, arg1_val) \ |
| 420 TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) | 475 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| 476 category, name, id, TRACE_EVENT_FLAG_HAS_ID, arg1_name, arg1_val) | |
| 421 #define TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, \ | 477 #define TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, \ |
| 422 arg2_name, arg2_val) \ | 478 arg2_name, arg2_val) \ |
| 423 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ | 479 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| 424 category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ | 480 category, name, id, TRACE_EVENT_FLAG_HAS_ID, \ |
| 425 TRACE_EVENT_FLAG_HAS_ID) | 481 arg1_name, arg1_val, arg2_name, arg2_val) |
| 426 #define TRACE_EVENT_COPY_FINISH0(category, name, id) \ | 482 #define TRACE_EVENT_COPY_FINISH0(category, name, id) \ |
| 427 TRACE_EVENT_COPY_FINISH1(category, name, id, NULL, 0) | 483 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| 484 category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) | |
| 428 #define TRACE_EVENT_COPY_FINISH1(category, name, id, arg1_name, arg1_val) \ | 485 #define TRACE_EVENT_COPY_FINISH1(category, name, id, arg1_name, arg1_val) \ |
| 429 TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) | 486 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| 487 category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ | |
| 488 arg1_name, arg1_val) | |
| 430 #define TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, \ | 489 #define TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, \ |
| 431 arg2_name, arg2_val) \ | 490 arg2_name, arg2_val) \ |
| 432 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ | 491 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ |
| 433 category, name, id, \ | 492 category, name, id, TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY, \ |
| 434 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 493 arg1_name, arg1_val, arg2_name, arg2_val) |
| 435 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
| 436 TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) | |
| 437 | 494 |
| 438 | 495 |
| 439 // Implementation detail: trace event macros create temporary variables | 496 // Implementation detail: trace event macros create temporary variables |
| 440 // to keep instrumentation overhead low. These macros give each temporary | 497 // to keep instrumentation overhead low. These macros give each temporary |
| 441 // variable a unique name based on the line number to prevent name collissions. | 498 // variable a unique name based on the line number to prevent name collissions. |
| 442 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 499 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
| 443 trace_event_unique_##a##b | 500 trace_event_unique_##a##b |
| 444 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 501 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
| 445 INTERNAL_TRACE_EVENT_UID3(a,b) | 502 INTERNAL_TRACE_EVENT_UID3(a,b) |
| 446 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 503 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
| 447 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) | 504 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) |
| 448 | 505 |
| 449 // Implementation detail: internal macro to create static category. | 506 // Implementation detail: internal macro to create static category. |
| 450 // - ANNOTATE_BENIGN_RACE, see Thread Safety above. | 507 // - ANNOTATE_BENIGN_RACE, see Thread Safety above. |
| 451 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ | 508 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ |
| 452 static const base::debug::TraceCategory* \ | 509 static const volatile bool* \ |
|
jar (doing other things)
2012/01/12 00:15:36
What does the use of volatile do for you? (for mo
jbates
2012/01/12 00:52:20
It's useful in this case, because it tells the com
jar (doing other things)
2012/01/12 02:20:03
I don't think volatile has such ordering semantics
joth
2012/01/12 16:14:46
Not a normative reference, but very informative:
h
| |
| 453 INTERNAL_TRACE_EVENT_UID(catstatic) = NULL; \ | 510 INTERNAL_TRACE_EVENT_UID(catstatic) = NULL; \ |
| 454 ANNOTATE_BENIGN_RACE(&INTERNAL_TRACE_EVENT_UID(catstatic), \ | 511 ANNOTATE_BENIGN_RACE(&INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| 455 "trace_event category"); \ | 512 "trace_event category"); \ |
| 456 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) \ | 513 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) \ |
| 457 INTERNAL_TRACE_EVENT_UID(catstatic) = \ | 514 INTERNAL_TRACE_EVENT_UID(catstatic) = \ |
| 458 base::debug::TraceLog::GetCategory(category); | 515 TRACE_EVENT_API_GET_CATEGORY_ENABLED(category); |
| 459 | 516 |
| 460 // Implementation detail: internal macro to create static category and add | 517 // Implementation detail: internal macro to create static category and add |
| 461 // event if the category is enabled. | 518 // event if the category is enabled. |
| 462 #define INTERNAL_TRACE_EVENT_ADD( \ | 519 #define INTERNAL_TRACE_EVENT_ADD(phase, category, name, flags, ...) \ |
|
jar (doing other things)
2012/01/12 00:15:36
Is ellipsis (vararg) defined for the preprocessor?
jbates
2012/01/12 00:52:20
It's used in base/logging.h so I'm hoping I can us
jar (doing other things)
2012/01/12 02:20:03
Interesting. OK. Thanks for the example. It is
| |
| 463 phase, category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ | |
| 464 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 520 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 465 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 521 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 466 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 522 TRACE_EVENT_NAMESPACE::internal::AddTraceEvent( \ |
| 467 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | 523 phase, INTERNAL_TRACE_EVENT_UID(catstatic), name, 0, flags, \ |
| 468 name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ | 524 ##__VA_ARGS__); \ |
|
jar (doing other things)
2012/01/12 00:15:36
... and you're also using the ## gcc compatibility
jbates
2012/01/12 00:52:20
I just stole this from base/logging.h, which did n
| |
| 469 } | 525 } |
| 470 | 526 |
| 471 // Implementation detail: internal macro to create static category and | 527 // Implementation detail: internal macro to create static category and |
| 472 // add the counter event if it is enabled. | 528 // add the counter event if it is enabled. |
| 473 #define INTERNAL_TRACE_EVENT_ADD_COUNTER( \ | 529 #define INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
| 474 category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ | 530 category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ |
| 475 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 531 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 476 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 532 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 477 base::debug::TraceLog::GetInstance()->AddCounterEvent( \ | 533 TRACE_EVENT_API_ADD_COUNTER_EVENT( \ |
| 478 INTERNAL_TRACE_EVENT_UID(catstatic), \ | 534 INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| 479 name, id, arg1_name, arg1_val, arg2_name, arg2_val, flags); \ | 535 name, TRACE_EVENT_NAMESPACE::TraceID(id).data(), \ |
| 536 arg1_name, arg1_val, arg2_name, arg2_val, flags); \ | |
| 480 } | 537 } |
| 481 | 538 |
| 482 // Implementation detail: internal macro to create static category and add begin | 539 // Implementation detail: internal macro to create static category and add begin |
| 483 // event if the category is enabled. Also adds the end event when the scope | 540 // event if the category is enabled. Also adds the end event when the scope |
| 484 // ends. | 541 // ends. |
| 485 #define INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | 542 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category, name, ...) \ |
| 486 category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | |
| 487 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 543 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 488 base::debug::internal::TraceEndOnScopeClose \ | 544 TRACE_EVENT_NAMESPACE::internal::TraceEndOnScopeClose \ |
| 489 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 545 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| 490 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 546 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 491 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 547 TRACE_EVENT_NAMESPACE::internal::AddTraceEvent( \ |
| 492 TRACE_EVENT_PHASE_BEGIN, \ | 548 TRACE_EVENT_PHASE_BEGIN, \ |
| 493 INTERNAL_TRACE_EVENT_UID(catstatic), \ | 549 INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| 494 name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ | 550 name, 0, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ |
| 495 TRACE_EVENT_FLAG_NONE); \ | |
| 496 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ | 551 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ |
| 497 INTERNAL_TRACE_EVENT_UID(catstatic), name); \ | 552 INTERNAL_TRACE_EVENT_UID(catstatic), name); \ |
| 498 } | 553 } |
| 499 | 554 |
| 500 // Implementation detail: internal macro to create static category and add begin | 555 // Implementation detail: internal macro to create static category and add begin |
| 501 // event if the category is enabled. Also adds the end event when the scope | 556 // event if the category is enabled. Also adds the end event when the scope |
| 502 // ends. If the elapsed time is < threshold time, the begin/end pair is erased. | 557 // ends. If the elapsed time is < threshold time, the begin/end pair is erased. |
| 503 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \ | 558 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \ |
| 504 category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | 559 category, name, ...) \ |
| 505 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 560 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 506 base::debug::internal::TraceEndOnScopeCloseThreshold \ | 561 TRACE_EVENT_NAMESPACE::internal::TraceEndOnScopeCloseThreshold \ |
| 507 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 562 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
| 508 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 563 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 509 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ | 564 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ |
| 510 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 565 TRACE_EVENT_NAMESPACE::internal::AddTraceEvent( \ |
| 511 TRACE_EVENT_PHASE_BEGIN, \ | 566 TRACE_EVENT_PHASE_BEGIN, \ |
| 512 INTERNAL_TRACE_EVENT_UID(catstatic), \ | 567 INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| 513 name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ | 568 name, 0, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ |
| 514 TRACE_EVENT_FLAG_NONE); \ | |
| 515 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ | 569 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ |
| 516 INTERNAL_TRACE_EVENT_UID(catstatic), name, \ | 570 INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
| 517 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ | 571 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ |
| 518 } | 572 } |
| 519 | 573 |
| 520 // Implementation detail: internal macro to create static category and add | 574 // Implementation detail: internal macro to create static category and add |
| 521 // event if the category is enabled. | 575 // event if the category is enabled. |
| 522 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, \ | 576 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, flags, \ |
| 523 arg1_name, arg1_val, arg2_name, arg2_val, flags) \ | 577 ...) \ |
| 524 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 578 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
| 525 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 579 if (*INTERNAL_TRACE_EVENT_UID(catstatic)) { \ |
| 526 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 580 TRACE_EVENT_NAMESPACE::internal::AddTraceEvent( \ |
| 527 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | 581 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ |
| 528 name, id, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ | 582 name, TRACE_EVENT_NAMESPACE::TraceID(id).data(), flags, \ |
| 583 ##__VA_ARGS__); \ | |
| 529 } | 584 } |
| 530 | 585 |
| 531 template <typename Type> | 586 template <typename Type> |
| 532 struct StaticMemorySingletonTraits; | 587 struct StaticMemorySingletonTraits; |
| 533 | 588 |
| 534 namespace base { | 589 namespace base { |
| 535 | 590 |
| 536 class RefCountedString; | 591 class RefCountedString; |
| 537 | 592 |
| 538 namespace debug { | 593 namespace debug { |
| 539 | 594 |
| 540 // Categories allow enabling/disabling of streams of trace events | 595 const int kTraceMaxNumArgs = 2; |
| 541 struct TraceCategory { | |
| 542 const char* name; | |
| 543 volatile bool enabled; | |
| 544 }; | |
| 545 | |
| 546 const size_t kTraceMaxNumArgs = 2; | |
| 547 | 596 |
| 548 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. | 597 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. |
| 549 typedef char TraceEventPhase; | 598 // New types can be added, but existing values must never change. |
|
nduca
2012/01/11 21:49:11
Might want to clarify them 'must never change'. I
jbates
2012/01/11 22:44:35
I guess I don't see any reason to discuss changing
jbates
2012/01/11 23:52:44
Done. Ignore my previous comment, I was confused a
| |
| 550 #define TRACE_EVENT_PHASE_BEGIN (base::debug::TraceEventPhase('B')) | 599 #define TRACE_EVENT_PHASE_BEGIN ('B') |
| 551 #define TRACE_EVENT_PHASE_END (base::debug::TraceEventPhase('E')) | 600 #define TRACE_EVENT_PHASE_END ('E') |
| 552 #define TRACE_EVENT_PHASE_INSTANT (base::debug::TraceEventPhase('I')) | 601 #define TRACE_EVENT_PHASE_INSTANT ('I') |
| 553 #define TRACE_EVENT_PHASE_START (base::debug::TraceEventPhase('S')) | 602 #define TRACE_EVENT_PHASE_START ('S') |
| 554 #define TRACE_EVENT_PHASE_FINISH (base::debug::TraceEventPhase('F')) | 603 #define TRACE_EVENT_PHASE_FINISH ('F') |
| 555 #define TRACE_EVENT_PHASE_METADATA (base::debug::TraceEventPhase('M')) | 604 #define TRACE_EVENT_PHASE_METADATA ('M') |
| 556 #define TRACE_EVENT_PHASE_COUNTER (base::debug::TraceEventPhase('C')) | 605 #define TRACE_EVENT_PHASE_COUNTER ('C') |
| 557 | 606 |
| 558 typedef uint8 TraceEventFlags; | 607 // New types can be added, but existing values must never change. |
| 559 #define TRACE_EVENT_FLAG_NONE (base::debug::TraceEventFlags(0)) | 608 #define TRACE_EVENT_FLAG_NONE (uint8(0)) |
| 560 #define TRACE_EVENT_FLAG_COPY (base::debug::TraceEventFlags(1<<0)) | 609 #define TRACE_EVENT_FLAG_COPY (uint8(1<<0)) |
| 561 #define TRACE_EVENT_FLAG_HAS_ID (base::debug::TraceEventFlags(1<<1)) | 610 #define TRACE_EVENT_FLAG_HAS_ID (uint8(1<<1)) |
| 562 | 611 |
| 563 // Simple union of values. This is much lighter weight than base::Value, which | 612 // Type values for identifying types in the TraceValue union. |
| 564 // requires dynamic allocation and a vtable. To keep the trace runtime overhead | 613 // New types can be added, but existing values must never change. |
| 565 // low, we want constant size storage here. | 614 #define TRACE_VALUE_TYPE_BOOL (uint8(1)) |
| 566 class BASE_EXPORT TraceValue { | 615 #define TRACE_VALUE_TYPE_UINT (uint8(2)) |
| 567 public: | 616 #define TRACE_VALUE_TYPE_INT (uint8(3)) |
| 568 enum Type { | 617 #define TRACE_VALUE_TYPE_DOUBLE (uint8(4)) |
| 569 TRACE_TYPE_UNDEFINED, | 618 #define TRACE_VALUE_TYPE_POINTER (uint8(5)) |
| 570 TRACE_TYPE_BOOL, | 619 #define TRACE_VALUE_TYPE_STRING (uint8(6)) |
| 571 TRACE_TYPE_UINT, | 620 #define TRACE_VALUE_TYPE_COPY_STRING (uint8(7)) |
| 572 TRACE_TYPE_INT, | |
| 573 TRACE_TYPE_DOUBLE, | |
| 574 TRACE_TYPE_POINTER, | |
| 575 TRACE_TYPE_STRING, | |
| 576 TRACE_TYPE_STATIC_STRING | |
| 577 }; | |
| 578 | |
| 579 TraceValue() : type_(TRACE_TYPE_UNDEFINED) { | |
| 580 value_.as_uint = 0ull; | |
| 581 } | |
| 582 TraceValue(bool rhs) : type_(TRACE_TYPE_BOOL) { | |
| 583 value_.as_bool = rhs; | |
| 584 } | |
| 585 TraceValue(uint64 rhs) : type_(TRACE_TYPE_UINT) { | |
| 586 value_.as_uint = rhs; | |
| 587 } | |
| 588 TraceValue(uint32 rhs) : type_(TRACE_TYPE_UINT) { | |
| 589 value_.as_uint = rhs; | |
| 590 } | |
| 591 TraceValue(uint16 rhs) : type_(TRACE_TYPE_UINT) { | |
| 592 value_.as_uint = rhs; | |
| 593 } | |
| 594 TraceValue(uint8 rhs) : type_(TRACE_TYPE_UINT) { | |
| 595 value_.as_uint = rhs; | |
| 596 } | |
| 597 TraceValue(int64 rhs) : type_(TRACE_TYPE_INT) { | |
| 598 value_.as_int = rhs; | |
| 599 } | |
| 600 TraceValue(int32 rhs) : type_(TRACE_TYPE_INT) { | |
| 601 value_.as_int = rhs; | |
| 602 } | |
| 603 TraceValue(int16 rhs) : type_(TRACE_TYPE_INT) { | |
| 604 value_.as_int = rhs; | |
| 605 } | |
| 606 TraceValue(int8 rhs) : type_(TRACE_TYPE_INT) { | |
| 607 value_.as_int = rhs; | |
| 608 } | |
| 609 TraceValue(double rhs) : type_(TRACE_TYPE_DOUBLE) { | |
| 610 value_.as_double = rhs; | |
| 611 } | |
| 612 TraceValue(const void* rhs) : type_(TRACE_TYPE_POINTER) { | |
| 613 value_.as_pointer = rhs; | |
| 614 } | |
| 615 TraceValue(const std::string& rhs) : type_(TRACE_TYPE_STRING) { | |
| 616 value_.as_string = rhs.c_str(); | |
| 617 } | |
| 618 TraceValue(const char* rhs) : type_(TRACE_TYPE_STATIC_STRING) { | |
| 619 value_.as_string = rhs; | |
| 620 } | |
| 621 | |
| 622 static TraceValue StringWithCopy(const char* rhs) { | |
| 623 TraceValue value(rhs); | |
| 624 if (rhs) | |
| 625 value.type_ = TRACE_TYPE_STRING; | |
| 626 return value; | |
| 627 } | |
| 628 | |
| 629 static TraceValue ForceCopy(const TraceValue& rhs) { | |
| 630 TraceValue value(rhs); | |
| 631 if (value.type_ == TRACE_TYPE_STATIC_STRING && value.as_string()) | |
| 632 value.type_ = TRACE_TYPE_STRING; | |
| 633 return value; | |
| 634 } | |
| 635 | |
| 636 bool is_string() const { | |
| 637 return type_ == TRACE_TYPE_STRING || type_ == TRACE_TYPE_STATIC_STRING; | |
| 638 } | |
| 639 | |
| 640 void AppendAsJSON(std::string* out) const; | |
| 641 | |
| 642 Type type() const { | |
| 643 return type_; | |
| 644 } | |
| 645 uint64 as_uint() const { | |
| 646 DCHECK_EQ(TRACE_TYPE_UINT, type_); | |
| 647 return value_.as_uint; | |
| 648 } | |
| 649 bool as_bool() const { | |
| 650 DCHECK_EQ(TRACE_TYPE_BOOL, type_); | |
| 651 return value_.as_bool; | |
| 652 } | |
| 653 int64 as_int() const { | |
| 654 DCHECK_EQ(TRACE_TYPE_INT, type_); | |
| 655 return value_.as_int; | |
| 656 } | |
| 657 double as_double() const { | |
| 658 DCHECK_EQ(TRACE_TYPE_DOUBLE, type_); | |
| 659 return value_.as_double; | |
| 660 } | |
| 661 const void* as_pointer() const { | |
| 662 DCHECK_EQ(TRACE_TYPE_POINTER, type_); | |
| 663 return value_.as_pointer; | |
| 664 } | |
| 665 const char* as_string() const { | |
| 666 DCHECK(is_string()); | |
| 667 return value_.as_string; | |
| 668 } | |
| 669 const char** as_assignable_string() { | |
| 670 DCHECK_EQ(TRACE_TYPE_STRING, type_); | |
| 671 return &value_.as_string; | |
| 672 } | |
| 673 | |
| 674 private: | |
| 675 union Value { | |
| 676 bool as_bool; | |
| 677 uint64 as_uint; | |
| 678 int64 as_int; | |
| 679 double as_double; | |
| 680 const void* as_pointer; | |
| 681 const char* as_string; | |
| 682 }; | |
| 683 | |
| 684 Type type_; | |
| 685 Value value_; | |
| 686 }; | |
| 687 | 621 |
| 688 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 622 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
| 689 // are mangled with the Process ID so that they are unlikely to collide when the | 623 // are mangled with the Process ID so that they are unlikely to collide when the |
| 690 // same pointer is used on different processes. | 624 // same pointer is used on different processes. |
| 691 class BASE_EXPORT TraceID { | 625 class BASE_EXPORT TraceID { |
| 692 public: | 626 public: |
| 693 TraceID() : data_(0u) {} | 627 TraceID() : data_(0u) {} |
| 694 TraceID(void* rhs); | 628 TraceID(void* rhs); |
| 695 TraceID(unsigned long long rhs) : data_(static_cast<uint64>(rhs)) {} | 629 TraceID(unsigned long long rhs) : data_(static_cast<uint64>(rhs)) {} |
| 696 TraceID(unsigned long rhs) : data_(static_cast<uint64>(rhs)) {} | 630 TraceID(unsigned long rhs) : data_(static_cast<uint64>(rhs)) {} |
| 697 TraceID(unsigned int rhs) : data_(static_cast<uint64>(rhs)) {} | 631 TraceID(unsigned int rhs) : data_(static_cast<uint64>(rhs)) {} |
| 698 TraceID(long long rhs) : data_(static_cast<uint64>(rhs)) {} | 632 TraceID(long long rhs) : data_(static_cast<uint64>(rhs)) {} |
| 699 TraceID(long rhs) : data_(static_cast<uint64>(rhs)) {} | 633 TraceID(long rhs) : data_(static_cast<uint64>(rhs)) {} |
| 700 TraceID(int rhs) : data_(static_cast<uint64>(rhs)) {} | 634 TraceID(int rhs) : data_(static_cast<uint64>(rhs)) {} |
| 701 | 635 |
| 702 uint64 data() const { return data_; } | 636 uint64 data() const { return data_; } |
| 703 | 637 |
| 704 private: | 638 private: |
| 705 uint64 data_; | 639 uint64 data_; |
| 706 }; | 640 }; |
| 707 | 641 |
| 708 // Output records are "Events" and can be obtained via the | 642 // Output records are "Events" and can be obtained via the |
| 709 // OutputCallback whenever the tracing system decides to flush. This | 643 // OutputCallback whenever the tracing system decides to flush. This |
| 710 // can happen at any time, on any thread, or you can programatically | 644 // can happen at any time, on any thread, or you can programatically |
| 711 // force it to happen. | 645 // force it to happen. |
| 712 class BASE_EXPORT TraceEvent { | 646 class BASE_EXPORT TraceEvent { |
| 713 public: | 647 public: |
| 648 union TraceValue { | |
| 649 bool as_bool; | |
| 650 uint64 as_uint; | |
| 651 int64 as_int; | |
| 652 double as_double; | |
| 653 const void* as_pointer; | |
| 654 const char* as_string; | |
|
nduca
2012/01/11 21:49:11
No clue what goog style says, so I'll assume as_x
jbates
2012/01/11 22:44:35
The TraceValue union was defined this way already,
| |
| 655 }; | |
| 656 | |
| 714 TraceEvent(); | 657 TraceEvent(); |
| 715 TraceEvent(int thread_id, | 658 TraceEvent(int thread_id, |
| 716 TimeTicks timestamp, | 659 TimeTicks timestamp, |
| 717 TraceEventPhase phase, | 660 char phase, |
| 718 const TraceCategory* category, | 661 const volatile bool* category_enabled, |
|
joth
2012/01/12 16:14:46
I think you can achieve your goal by just putting
jbates
2012/01/12 19:41:29
Just getting rid of volatile completely, as it doe
| |
| 719 const char* name, | 662 const char* name, |
| 720 TraceID id, | 663 uint64 id, |
| 721 const char* arg1_name, const TraceValue& arg1_val, | 664 int num_args, |
| 722 const char* arg2_name, const TraceValue& arg2_val, | 665 const char** arg_names, |
| 723 TraceEventFlags flags); | 666 const uint8* arg_types, |
| 667 const uint64* arg_values, | |
| 668 uint8 flags); | |
| 724 ~TraceEvent(); | 669 ~TraceEvent(); |
| 725 | 670 |
| 726 static char GetPhaseChar(TraceEventPhase phase) { | |
| 727 return static_cast<char>(phase); | |
| 728 } | |
| 729 | |
| 730 static TraceEventPhase GetPhase(const char* phase) { | |
| 731 return static_cast<TraceEventPhase>(*phase); | |
| 732 } | |
| 733 | |
| 734 // Serialize event data to JSON | 671 // Serialize event data to JSON |
| 735 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, | 672 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
| 736 size_t start, | 673 size_t start, |
| 737 size_t count, | 674 size_t count, |
| 738 std::string* out); | 675 std::string* out); |
| 739 void AppendAsJSON(std::string* out) const; | 676 void AppendAsJSON(std::string* out) const; |
| 740 | 677 |
| 741 TimeTicks timestamp() const { return timestamp_; } | 678 TimeTicks timestamp() const { return timestamp_; } |
| 742 | 679 |
| 743 // Exposed for unittesting: | 680 // Exposed for unittesting: |
| 744 | 681 |
| 745 const base::RefCountedString* parameter_copy_storage() const { | 682 const base::RefCountedString* parameter_copy_storage() const { |
| 746 return parameter_copy_storage_.get(); | 683 return parameter_copy_storage_.get(); |
| 747 } | 684 } |
| 748 | 685 |
| 749 const char* name() const { return name_; } | 686 const char* name() const { return name_; } |
| 750 | 687 |
| 751 private: | 688 private: |
| 752 // Note: these are ordered by size (largest first) for optimal packing. | 689 // Note: these are ordered by size (largest first) for optimal packing. |
| 690 // 64-bit types: | |
|
nduca
2012/01/11 21:49:11
not sure we need these comments, but if you feel t
jbates
2012/01/11 22:44:35
Does seem redundant with the first comment -- will
jbates
2012/01/11 23:52:44
Done.
| |
| 753 TimeTicks timestamp_; | 691 TimeTicks timestamp_; |
| 754 // id_ can be used to store phase-specific data. | 692 // id_ can be used to store phase-specific data. |
| 755 TraceID id_; | 693 uint64 id_; |
| 756 TraceValue arg_values_[kTraceMaxNumArgs]; | 694 TraceValue arg_values_[kTraceMaxNumArgs]; |
| 695 // Pointers: | |
| 757 const char* arg_names_[kTraceMaxNumArgs]; | 696 const char* arg_names_[kTraceMaxNumArgs]; |
| 758 const TraceCategory* category_; | 697 const volatile bool* category_enabled_; |
| 759 const char* name_; | 698 const char* name_; |
| 760 scoped_refptr<base::RefCountedString> parameter_copy_storage_; | 699 scoped_refptr<base::RefCountedString> parameter_copy_storage_; |
| 700 // Ints: | |
| 761 int thread_id_; | 701 int thread_id_; |
| 762 TraceEventPhase phase_; | 702 // Bytes: |
| 763 TraceEventFlags flags_; | 703 char phase_; |
| 704 uint8 flags_; | |
| 705 uint8 arg_types_[kTraceMaxNumArgs]; | |
| 764 }; | 706 }; |
| 765 | 707 |
| 766 | 708 |
| 767 // TraceResultBuffer collects and converts trace fragments returned by TraceLog | 709 // TraceResultBuffer collects and converts trace fragments returned by TraceLog |
| 768 // to JSON output. | 710 // to JSON output. |
| 769 class BASE_EXPORT TraceResultBuffer { | 711 class BASE_EXPORT TraceResultBuffer { |
| 770 public: | 712 public: |
| 771 typedef base::Callback<void(const std::string&)> OutputCallback; | 713 typedef base::Callback<void(const std::string&)> OutputCallback; |
| 772 | 714 |
| 773 // If you don't need to stream JSON chunks out efficiently, and just want to | 715 // If you don't need to stream JSON chunks out efficiently, and just want to |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 // The trace buffer does not flush dynamically, so when it fills up, | 805 // The trace buffer does not flush dynamically, so when it fills up, |
| 864 // subsequent trace events will be dropped. This callback is generated when | 806 // subsequent trace events will be dropped. This callback is generated when |
| 865 // the trace buffer is full. The callback must be thread safe. | 807 // the trace buffer is full. The callback must be thread safe. |
| 866 typedef base::Callback<void(void)> BufferFullCallback; | 808 typedef base::Callback<void(void)> BufferFullCallback; |
| 867 void SetBufferFullCallback(const BufferFullCallback& cb); | 809 void SetBufferFullCallback(const BufferFullCallback& cb); |
| 868 | 810 |
| 869 // Flushes all logged data to the callback. | 811 // Flushes all logged data to the callback. |
| 870 void Flush(); | 812 void Flush(); |
| 871 | 813 |
| 872 // Called by TRACE_EVENT* macros, don't call this directly. | 814 // Called by TRACE_EVENT* macros, don't call this directly. |
| 873 static const TraceCategory* GetCategory(const char* name); | 815 static const volatile bool* GetCategoryEnabled(const char* name); |
| 816 static const char* GetCategoryName(const volatile bool* category_enabled); | |
| 874 | 817 |
| 875 // Called by TRACE_EVENT* macros, don't call this directly. | 818 // Called by TRACE_EVENT* macros, don't call this directly. |
| 876 // Returns the index in the internal vector of the event if it was added, or | 819 // Returns the index in the internal vector of the event if it was added, or |
| 877 // -1 if the event was not added. | 820 // -1 if the event was not added. |
| 878 // On end events, the return value of the begin event can be specified along | 821 // On end events, the return value of the begin event can be specified along |
| 879 // with a threshold in microseconds. If the elapsed time between begin and end | 822 // with a threshold in microseconds. If the elapsed time between begin and end |
| 880 // is less than the threshold, the begin/end event pair is dropped. | 823 // is less than the threshold, the begin/end event pair is dropped. |
| 881 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied | 824 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied |
| 882 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. | 825 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. |
| 883 int AddTraceEvent(TraceEventPhase phase, | 826 int AddTraceEvent(char phase, |
| 884 const TraceCategory* category, | 827 const volatile bool* category_enabled, |
| 885 const char* name, | 828 const char* name, |
| 886 TraceID id, | 829 uint64 id, |
| 887 const char* arg1_name, TraceValue arg1_val, | 830 int num_args, |
| 888 const char* arg2_name, TraceValue arg2_val, | 831 const char** arg_names, |
| 832 const uint8* arg_types, | |
| 833 const uint64* arg_values, | |
| 889 int threshold_begin_id, | 834 int threshold_begin_id, |
| 890 int64 threshold, | 835 int64 threshold, |
| 891 TraceEventFlags flags); | 836 uint8 flags); |
| 892 static void AddTraceEventEtw(TraceEventPhase phase, | 837 static void AddTraceEventEtw(char phase, |
| 893 const char* name, | 838 const char* name, |
| 894 const void* id, | 839 const void* id, |
| 895 const char* extra); | 840 const char* extra); |
| 896 static void AddTraceEventEtw(TraceEventPhase phase, | 841 static void AddTraceEventEtw(char phase, |
| 897 const char* name, | 842 const char* name, |
| 898 const void* id, | 843 const void* id, |
| 899 const std::string& extra); | 844 const std::string& extra); |
| 900 | 845 |
| 901 // A wrapper around AddTraceEvent used by TRACE_COUNTERx macros | 846 // A wrapper around AddTraceEvent used by TRACE_COUNTERx macros |
| 902 // that allows only integer values for the counters. | 847 // that allows only integer values for the counters. |
| 903 int AddCounterEvent(const TraceCategory* category, | 848 void AddCounterEvent(const volatile bool* category_enabled, |
| 904 const char* name, | 849 const char* name, |
| 905 TraceID id, | 850 uint64 id, |
| 906 const char* arg1_name, int32 arg1_val, | 851 const char* arg1_name, int32 arg1_val, |
| 907 const char* arg2_name, int32 arg2_val, | 852 const char* arg2_name, int32 arg2_val, |
| 908 TraceEventFlags flags); | 853 uint8 flags); |
| 909 | 854 |
| 910 // Mangle |id| with a hash based on the process ID so that if |id| occurs on | 855 // Mangle |ptr| with a hash based on the process ID so that if |ptr| occurs on |
| 911 // more than one process, it will not collide. | 856 // more than one process, it will not collide. |
| 912 uint64 GetIntraProcessID(uint64 id) const { return id ^ process_id_hash_; } | 857 uint64 GetInterProcessID(void* ptr) const { |
| 858 return static_cast<uint64>(reinterpret_cast<uintptr_t>(ptr)) ^ | |
| 859 process_id_hash_; | |
| 860 } | |
| 913 | 861 |
| 914 int process_id() const { return process_id_; } | 862 int process_id() const { return process_id_; } |
| 915 | 863 |
| 916 // Exposed for unittesting: | 864 // Exposed for unittesting: |
| 917 | 865 |
| 918 // Allows deleting our singleton instance. | 866 // Allows deleting our singleton instance. |
| 919 static void DeleteForTesting(); | 867 static void DeleteForTesting(); |
| 920 | 868 |
| 921 // Allows resurrecting our singleton instance post-AtExit processing. | 869 // Allows resurrecting our singleton instance post-AtExit processing. |
| 922 static void Resurrect(); | 870 static void Resurrect(); |
| 923 | 871 |
| 924 // Allow tests to inspect TraceEvents. | 872 // Allow tests to inspect TraceEvents. |
| 925 size_t GetEventsSize() const { return logged_events_.size(); } | 873 size_t GetEventsSize() const { return logged_events_.size(); } |
| 926 const TraceEvent& GetEventAt(size_t index) const { | 874 const TraceEvent& GetEventAt(size_t index) const { |
| 927 DCHECK(index < logged_events_.size()); | 875 DCHECK(index < logged_events_.size()); |
| 928 return logged_events_[index]; | 876 return logged_events_[index]; |
| 929 } | 877 } |
| 930 | 878 |
| 931 void SetProcessID(int process_id); | 879 void SetProcessID(int process_id); |
| 932 | 880 |
| 933 private: | 881 private: |
| 934 // This allows constructor and destructor to be private and usable only | 882 // This allows constructor and destructor to be private and usable only |
| 935 // by the Singleton class. | 883 // by the Singleton class. |
| 936 friend struct StaticMemorySingletonTraits<TraceLog>; | 884 friend struct StaticMemorySingletonTraits<TraceLog>; |
| 937 | 885 |
| 938 TraceLog(); | 886 TraceLog(); |
| 939 ~TraceLog(); | 887 ~TraceLog(); |
| 940 const TraceCategory* GetCategoryInternal(const char* name); | 888 const volatile bool* GetCategoryEnabledInternal(const char* name); |
| 941 void AddThreadNameMetadataEvents(); | 889 void AddThreadNameMetadataEvents(); |
| 942 void AddClockSyncMetadataEvents(); | 890 void AddClockSyncMetadataEvents(); |
| 943 | 891 |
| 944 // TODO(nduca): switch to per-thread trace buffers to reduce thread | 892 // TODO(nduca): switch to per-thread trace buffers to reduce thread |
| 945 // synchronization. | 893 // synchronization. |
| 946 Lock lock_; | 894 Lock lock_; |
| 947 bool enabled_; | 895 bool enabled_; |
| 948 OutputCallback output_callback_; | 896 OutputCallback output_callback_; |
| 949 BufferFullCallback buffer_full_callback_; | 897 BufferFullCallback buffer_full_callback_; |
| 950 std::vector<TraceEvent> logged_events_; | 898 std::vector<TraceEvent> logged_events_; |
| 951 std::vector<std::string> included_categories_; | 899 std::vector<std::string> included_categories_; |
| 952 std::vector<std::string> excluded_categories_; | 900 std::vector<std::string> excluded_categories_; |
| 953 | 901 |
| 954 base::hash_map<int, std::string> thread_names_; | 902 base::hash_map<int, std::string> thread_names_; |
| 955 | 903 |
| 956 // XORed with TraceID to make it unlikely to collide with other processes. | 904 // XORed with TraceID to make it unlikely to collide with other processes. |
| 957 uint64 process_id_hash_; | 905 uint64 process_id_hash_; |
| 958 | 906 |
| 959 int process_id_; | 907 int process_id_; |
| 960 | 908 |
| 961 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 909 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 962 }; | 910 }; |
| 963 | 911 |
| 964 namespace internal { | 912 namespace internal { |
| 965 | 913 |
| 914 // Simple union to store various types as uint64. | |
| 915 union TraceValueUnion { | |
| 916 bool as_bool; | |
| 917 uint64 as_uint; | |
| 918 int64 as_int; | |
| 919 double as_double; | |
| 920 const void* as_pointer; | |
| 921 const char* as_string; | |
| 922 }; | |
| 923 | |
| 924 // Simple container for const char* that should be copied instead of retained. | |
| 925 class TraceStringWithCopy { | |
| 926 public: | |
| 927 explicit TraceStringWithCopy(const char* str) : str_(str) {} | |
| 928 operator const char* () const { return str_; } | |
| 929 private: | |
| 930 const char* str_; | |
| 931 }; | |
| 932 | |
| 933 // Define SetTraceValue for each allowed type. It stores the type and | |
| 934 // value in the return arguments. This allows this API to avoid declaring any | |
| 935 // structures so that it is portable to third_party libraries. | |
| 936 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, \ | |
|
jar (doing other things)
2012/01/12 02:20:03
I'm not a template master at all... but couldn't t
jbates
2012/01/12 19:41:29
In this case we need full control over the support
| |
| 937 union_member, \ | |
| 938 value_type_id) \ | |
| 939 static inline void SetTraceValue(actual_type arg, \ | |
| 940 uint8* type, \ | |
| 941 uint64* value) { \ | |
| 942 TraceValueUnion type_value; \ | |
| 943 type_value.union_member = arg; \ | |
| 944 *type = value_type_id; \ | |
| 945 *value = type_value.as_uint; \ | |
| 946 } | |
| 947 | |
| 948 INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL) | |
| 949 INTERNAL_DECLARE_SET_TRACE_VALUE(uint64, as_uint, TRACE_VALUE_TYPE_UINT) | |
| 950 INTERNAL_DECLARE_SET_TRACE_VALUE(uint32, as_uint, TRACE_VALUE_TYPE_UINT) | |
| 951 INTERNAL_DECLARE_SET_TRACE_VALUE(uint16, as_uint, TRACE_VALUE_TYPE_UINT) | |
| 952 INTERNAL_DECLARE_SET_TRACE_VALUE(uint8, as_uint, TRACE_VALUE_TYPE_UINT) | |
| 953 INTERNAL_DECLARE_SET_TRACE_VALUE(int64, as_int, TRACE_VALUE_TYPE_INT) | |
| 954 INTERNAL_DECLARE_SET_TRACE_VALUE(int32, as_int, TRACE_VALUE_TYPE_INT) | |
| 955 INTERNAL_DECLARE_SET_TRACE_VALUE(int16, as_int, TRACE_VALUE_TYPE_INT) | |
| 956 INTERNAL_DECLARE_SET_TRACE_VALUE(int8, as_int, TRACE_VALUE_TYPE_INT) | |
| 957 INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE) | |
| 958 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, | |
| 959 TRACE_VALUE_TYPE_POINTER) | |
| 960 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, | |
| 961 TRACE_VALUE_TYPE_STRING) | |
| 962 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, | |
| 963 TRACE_VALUE_TYPE_COPY_STRING) | |
| 964 | |
|
jar (doing other things)
2012/01/12 02:20:03
I you really want to use a macro... you may as wel
jbates
2012/01/12 19:41:29
Done.
| |
| 965 // std::string version of SetTraceValue so that trace arguments can be strings. | |
| 966 static inline void SetTraceValue(const std::string& arg, | |
| 967 uint8* type, | |
| 968 uint64* value) { | |
| 969 TraceValueUnion type_value; | |
| 970 type_value.as_string = arg.c_str(); | |
| 971 *type = TRACE_VALUE_TYPE_COPY_STRING; | |
| 972 *value = type_value.as_uint; | |
| 973 } | |
| 974 | |
| 975 // These AddTraceEvent template functions are defined here instead of in the | |
| 976 // macro, because the arg_values could be temporary objects, such as | |
| 977 // std::string. In order to store pointers to the internal c_str and pass | |
| 978 // through to the tracing API, the arg_values must live throughout | |
| 979 // these procedures. | |
| 980 | |
| 981 static inline int AddTraceEvent(char phase, | |
| 982 const volatile bool* category_enabled, | |
| 983 const char* name, | |
| 984 uint64 id, | |
| 985 uint8 flags) { | |
| 986 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 987 phase, category_enabled, name, id, | |
| 988 0, NULL, NULL, NULL, | |
| 989 -1, 0, flags); | |
| 990 } | |
| 991 | |
| 992 template<class ARG1_TYPE> | |
| 993 static inline int AddTraceEvent(char phase, | |
| 994 const volatile bool* category_enabled, | |
| 995 const char* name, | |
| 996 uint64 id, | |
| 997 uint8 flags, | |
| 998 const char* arg1_name, | |
| 999 const ARG1_TYPE& arg1_val) { | |
| 1000 const int num_args = 1; | |
| 1001 uint8 arg_types[1]; | |
| 1002 uint64 arg_values[1]; | |
| 1003 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | |
| 1004 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 1005 phase, category_enabled, name, id, | |
| 1006 num_args, &arg1_name, arg_types, arg_values, | |
| 1007 -1, 0, flags); | |
| 1008 } | |
| 1009 | |
| 1010 template<class ARG1_TYPE, class ARG2_TYPE> | |
| 1011 static inline int AddTraceEvent(char phase, | |
| 1012 const volatile bool* category_enabled, | |
| 1013 const char* name, | |
| 1014 uint64 id, | |
| 1015 uint8 flags, | |
| 1016 const char* arg1_name, | |
| 1017 const ARG1_TYPE& arg1_val, | |
| 1018 const char* arg2_name, | |
| 1019 const ARG2_TYPE& arg2_val) { | |
| 1020 const int num_args = 2; | |
| 1021 const char* arg_names[2] = { arg1_name, arg2_name }; | |
| 1022 uint8 arg_types[2]; | |
| 1023 uint64 arg_values[2]; | |
| 1024 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | |
| 1025 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | |
| 1026 return TRACE_EVENT_API_ADD_TRACE_EVENT( | |
| 1027 phase, category_enabled, name, id, | |
| 1028 num_args, arg_names, arg_types, arg_values, | |
| 1029 -1, 0, flags); | |
| 1030 } | |
| 1031 | |
| 966 // Used by TRACE_EVENTx macro. Do not use directly. | 1032 // Used by TRACE_EVENTx macro. Do not use directly. |
| 967 class BASE_EXPORT TraceEndOnScopeClose { | 1033 class BASE_EXPORT TraceEndOnScopeClose { |
| 968 public: | 1034 public: |
| 969 // Note: members of data_ intentionally left uninitialized. See Initialize. | 1035 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 970 TraceEndOnScopeClose() : p_data_(NULL) {} | 1036 TraceEndOnScopeClose() : p_data_(NULL) {} |
| 971 ~TraceEndOnScopeClose() { | 1037 ~TraceEndOnScopeClose() { |
| 972 if (p_data_) | 1038 if (p_data_) |
| 973 AddEventIfEnabled(); | 1039 AddEventIfEnabled(); |
| 974 } | 1040 } |
| 975 | 1041 |
| 976 void Initialize(const TraceCategory* category, | 1042 void Initialize(const volatile bool* category_enabled, |
| 977 const char* name); | 1043 const char* name); |
| 978 | 1044 |
| 979 private: | 1045 private: |
| 980 // Add the end event if the category is still enabled. | 1046 // Add the end event if the category is still enabled. |
| 981 void AddEventIfEnabled(); | 1047 void AddEventIfEnabled(); |
| 982 | 1048 |
| 983 // This Data struct workaround is to avoid initializing all the members | 1049 // This Data struct workaround is to avoid initializing all the members |
| 984 // in Data during construction of this object, since this object is always | 1050 // in Data during construction of this object, since this object is always |
| 985 // constructed, even when tracing is disabled. If the members of Data were | 1051 // constructed, even when tracing is disabled. If the members of Data were |
| 986 // members of this class instead, compiler warnings occur about potential | 1052 // members of this class instead, compiler warnings occur about potential |
| 987 // uninitialized accesses. | 1053 // uninitialized accesses. |
| 988 struct Data { | 1054 struct Data { |
| 989 const TraceCategory* category; | 1055 const volatile bool* category_enabled; |
| 990 const char* name; | 1056 const char* name; |
| 991 }; | 1057 }; |
| 992 Data* p_data_; | 1058 Data* p_data_; |
| 993 Data data_; | 1059 Data data_; |
| 994 }; | 1060 }; |
| 995 | 1061 |
| 996 // Used by TRACE_EVENTx macro. Do not use directly. | 1062 // Used by TRACE_EVENTx macro. Do not use directly. |
| 997 class BASE_EXPORT TraceEndOnScopeCloseThreshold { | 1063 class BASE_EXPORT TraceEndOnScopeCloseThreshold { |
| 998 public: | 1064 public: |
| 999 // Note: members of data_ intentionally left uninitialized. See Initialize. | 1065 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 1000 TraceEndOnScopeCloseThreshold() : p_data_(NULL) {} | 1066 TraceEndOnScopeCloseThreshold() : p_data_(NULL) {} |
| 1001 ~TraceEndOnScopeCloseThreshold() { | 1067 ~TraceEndOnScopeCloseThreshold() { |
| 1002 if (p_data_) | 1068 if (p_data_) |
| 1003 AddEventIfEnabled(); | 1069 AddEventIfEnabled(); |
| 1004 } | 1070 } |
| 1005 | 1071 |
| 1006 // Called by macros only when tracing is enabled at the point when the begin | 1072 // Called by macros only when tracing is enabled at the point when the begin |
| 1007 // event is added. | 1073 // event is added. |
| 1008 void Initialize(const TraceCategory* category, | 1074 void Initialize(const volatile bool* category_enabled, |
| 1009 const char* name, | 1075 const char* name, |
| 1010 int threshold_begin_id, | 1076 int threshold_begin_id, |
| 1011 int64 threshold); | 1077 int64 threshold); |
| 1012 | 1078 |
| 1013 private: | 1079 private: |
| 1014 // Add the end event if the category is still enabled. | 1080 // Add the end event if the category is still enabled. |
| 1015 void AddEventIfEnabled(); | 1081 void AddEventIfEnabled(); |
| 1016 | 1082 |
| 1017 // This Data struct workaround is to avoid initializing all the members | 1083 // This Data struct workaround is to avoid initializing all the members |
| 1018 // in Data during construction of this object, since this object is always | 1084 // in Data during construction of this object, since this object is always |
| 1019 // constructed, even when tracing is disabled. If the members of Data were | 1085 // constructed, even when tracing is disabled. If the members of Data were |
| 1020 // members of this class instead, compiler warnings occur about potential | 1086 // members of this class instead, compiler warnings occur about potential |
| 1021 // uninitialized accesses. | 1087 // uninitialized accesses. |
| 1022 struct Data { | 1088 struct Data { |
| 1023 int64 threshold; | 1089 int64 threshold; |
| 1024 const TraceCategory* category; | 1090 const volatile bool* category_enabled; |
| 1025 const char* name; | 1091 const char* name; |
| 1026 int threshold_begin_id; | 1092 int threshold_begin_id; |
| 1027 }; | 1093 }; |
| 1028 Data* p_data_; | 1094 Data* p_data_; |
| 1029 Data data_; | 1095 Data data_; |
| 1030 }; | 1096 }; |
| 1031 | 1097 |
| 1032 } // namespace internal | 1098 } // namespace internal |
| 1033 | 1099 |
| 1034 } // namespace debug | 1100 } // namespace debug |
| 1035 } // namespace base | 1101 } // namespace base |
| 1036 | 1102 |
| 1037 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 1103 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |