OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_ |
6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ | 6 #define BASE_TRACE_EVENT_TRACE_EVENT_H_ |
7 | 7 |
8 // This header file defines implementation details of how the trace macros in | 8 // This header file defines implementation details of how the trace macros in |
9 // trace_event_common.h collect and store trace events. Anything not | 9 // trace_event_common.h collect and store trace events. Anything not |
10 // implementation-specific should go in trace_event_common.h instead of here. | 10 // implementation-specific should go in trace_event_common.h instead of here. |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/trace_event/heap_profiler.h" | 21 #include "base/trace_event/heap_profiler.h" |
22 #include "base/trace_event/trace_event_system_stats_monitor.h" | 22 #include "base/trace_event/trace_event_system_stats_monitor.h" |
23 #include "base/trace_event/trace_log.h" | 23 #include "base/trace_event/trace_log.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 | 25 |
26 // By default, const char* argument values are assumed to have long-lived scope | 26 // By default, const char* argument values are assumed to have long-lived scope |
27 // and will not be copied. Use this macro to force a const char* to be copied. | 27 // and will not be copied. Use this macro to force a const char* to be copied. |
28 #define TRACE_STR_COPY(str) \ | 28 #define TRACE_STR_COPY(str) \ |
29 trace_event_internal::TraceStringWithCopy(str) | 29 trace_event_internal::TraceStringWithCopy(str) |
30 | 30 |
31 // By default, uint64_t ID argument values are not mangled with the Process ID | 31 // DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, |
32 // in TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. | 32 // instead. By default, uint64_t ID argument values are not mangled with the |
33 // Process ID in TRACE_EVENT_ASYNC macros. Use this macro to force Process ID | |
34 // mangling. | |
33 #define TRACE_ID_MANGLE(id) \ | 35 #define TRACE_ID_MANGLE(id) \ |
34 trace_event_internal::TraceID::ForceMangle(id) | 36 trace_event_internal::TraceID::ForceMangle(id) |
35 | 37 |
36 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC | 38 // DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, |
37 // macros. Use this macro to prevent Process ID mangling. | 39 // instead. By default, pointers are mangled with the Process ID in |
40 // TRACE_EVENT_ASYNC macros. Use this macro to prevent Process ID mangling. | |
38 #define TRACE_ID_DONT_MANGLE(id) \ | 41 #define TRACE_ID_DONT_MANGLE(id) \ |
39 trace_event_internal::TraceID::DontMangle(id) | 42 trace_event_internal::TraceID::DontMangle(id) |
40 | 43 |
41 // By default, trace IDs are eventually converted to a single 64-bit number. Use | 44 // By default, trace IDs are eventually converted to a single 64-bit number. Use |
42 // this macro to add a scope string. | 45 // this macro to add a scope string. |
43 #define TRACE_ID_WITH_SCOPE(scope, id) \ | 46 #define TRACE_ID_WITH_SCOPE(scope, id) \ |
44 trace_event_internal::TraceID::WithScope(scope, id) | 47 trace_event_internal::TraceID::WithScope(scope, id) |
45 | 48 |
49 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id) | |
50 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id) | |
51 | |
46 // Sets the current sample state to the given category and name (both must be | 52 // Sets the current sample state to the given category and name (both must be |
47 // constant strings). These states are intended for a sampling profiler. | 53 // constant strings). These states are intended for a sampling profiler. |
48 // Implementation note: we store category and name together because we don't | 54 // Implementation note: we store category and name together because we don't |
49 // want the inconsistency/expense of storing two pointers. | 55 // want the inconsistency/expense of storing two pointers. |
50 // |thread_bucket| is [0..2] and is used to statically isolate samples in one | 56 // |thread_bucket| is [0..2] and is used to statically isolate samples in one |
51 // thread from others. | 57 // thread from others. |
52 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ | 58 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET( \ |
53 bucket_number, category, name) \ | 59 bucket_number, category, name) \ |
54 trace_event_internal:: \ | 60 trace_event_internal:: \ |
55 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) | 61 TraceEventSamplingStateScope<bucket_number>::Set(category "\0" name) |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 trace_event_internal::AddTraceEvent( \ | 277 trace_event_internal::AddTraceEvent( \ |
272 TRACE_EVENT_PHASE_COMPLETE, \ | 278 TRACE_EVENT_PHASE_COMPLETE, \ |
273 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 279 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
274 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ | 280 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
275 TRACE_EVENT_FLAG_NONE, trace_event_internal::kNoId, \ | 281 TRACE_EVENT_FLAG_NONE, trace_event_internal::kNoId, \ |
276 ##__VA_ARGS__); \ | 282 ##__VA_ARGS__); \ |
277 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ | 283 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ |
278 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ | 284 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ |
279 } | 285 } |
280 | 286 |
281 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \ | 287 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \ |
282 category_group, name, bind_id, flow_flags, ...) \ | 288 category_group, name, bind_id, flow_flags, ...) \ |
283 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 289 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
284 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ | 290 trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ |
285 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 291 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
286 unsigned int trace_event_flags = flow_flags; \ | 292 trace_event_internal::TraceID trace_event_bind_id((bind_id)); \ |
287 trace_event_internal::TraceID trace_event_bind_id(bind_id, \ | 293 unsigned int trace_event_flags = flow_flags; \ |
288 &trace_event_flags); \ | 294 trace_event_bind_id.update_flags(&trace_event_flags); \ |
289 base::trace_event::TraceEventHandle h = \ | 295 base::trace_event::TraceEventHandle h = \ |
290 trace_event_internal::AddTraceEvent( \ | 296 trace_event_internal::AddTraceEvent( \ |
291 TRACE_EVENT_PHASE_COMPLETE, \ | 297 TRACE_EVENT_PHASE_COMPLETE, \ |
292 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 298 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
293 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ | 299 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
294 trace_event_flags, trace_event_bind_id.raw_id(), ##__VA_ARGS__); \ | 300 trace_event_flags, trace_event_bind_id.raw_id(), ##__VA_ARGS__); \ |
295 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ | 301 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ |
296 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ | 302 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ |
297 } | 303 } |
298 | 304 |
299 // Implementation detail: internal macro to create static category and add | 305 // Implementation detail: internal macro to create static category and add |
300 // event if the category is enabled. | 306 // event if the category is enabled. |
301 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ | 307 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ |
302 flags, ...) \ | 308 flags, ...) \ |
303 do { \ | 309 do { \ |
304 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 310 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
305 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 311 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
306 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 312 trace_event_internal::TraceID trace_event_trace_id((id)); \ |
307 trace_event_internal::TraceID trace_event_trace_id( \ | 313 unsigned int trace_event_flags = flags; \ |
308 id, &trace_event_flags); \ | 314 trace_event_trace_id.update_flags(&trace_event_flags); \ |
309 trace_event_internal::AddTraceEvent( \ | 315 trace_event_internal::AddTraceEvent( \ |
310 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 316 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
311 name, trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ | 317 name, trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
312 trace_event_flags, trace_event_internal::kNoId, ##__VA_ARGS__); \ | 318 trace_event_flags, trace_event_internal::kNoId, ##__VA_ARGS__); \ |
313 } \ | 319 } \ |
314 } while (0) | 320 } while (0) |
315 | 321 |
316 // Implementation detail: internal macro to create static category and add | 322 // Implementation detail: internal macro to create static category and add |
317 // event if the category is enabled. | 323 // event if the category is enabled. |
318 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \ | 324 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \ |
319 timestamp, flags, ...) \ | 325 timestamp, flags, ...) \ |
320 do { \ | 326 do { \ |
321 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 327 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
322 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 328 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
323 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 329 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
324 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 330 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
325 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ | 331 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
326 TRACE_EVENT_API_CURRENT_THREAD_ID, \ | 332 TRACE_EVENT_API_CURRENT_THREAD_ID, \ |
327 base::TimeTicks::FromInternalValue(timestamp), \ | 333 base::TimeTicks::FromInternalValue(timestamp), \ |
328 flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 334 flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
329 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 335 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
330 } \ | 336 } \ |
331 } while (0) | 337 } while (0) |
332 | 338 |
333 // Implementation detail: internal macro to create static category and add | 339 // Implementation detail: internal macro to create static category and add |
334 // event if the category is enabled. | 340 // event if the category is enabled. |
335 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | 341 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ |
336 phase, category_group, name, id, thread_id, timestamp, flags, ...) \ | 342 phase, category_group, name, id, thread_id, timestamp, flags, ...) \ |
337 do { \ | 343 do { \ |
338 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 344 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
339 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 345 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
340 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 346 trace_event_internal::TraceID trace_event_trace_id((id)); \ |
341 trace_event_internal::TraceID trace_event_trace_id(id, \ | 347 unsigned int trace_event_flags = flags; \ |
342 &trace_event_flags); \ | 348 trace_event_trace_id.update_flags(&trace_event_flags); \ |
343 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 349 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
344 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 350 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
345 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ | 351 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
346 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ | 352 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ |
347 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 353 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
348 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 354 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
349 } \ | 355 } \ |
350 } while (0) | 356 } while (0) |
351 | 357 |
352 // The trace ID and bind ID will never be mangled by this macro. | 358 // This macro ignores whether the bind_id is local, global, or mangled. |
353 #define INTERNAL_TRACE_EVENT_ADD_BIND_IDS(category_group, name, id, bind_id, \ | 359 #define INTERNAL_TRACE_EVENT_ADD_BIND_IDS(category_group, name, id, bind_id, \ |
354 ...) \ | 360 ...) \ |
355 do { \ | 361 do { \ |
356 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 362 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
357 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 363 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
358 trace_event_internal::TraceID::DontMangle source_id(id); \ | 364 trace_event_internal::TraceID source_id((id)); \ |
359 trace_event_internal::TraceID::DontMangle target_id(bind_id); \ | 365 unsigned int source_flags = TRACE_EVENT_FLAG_NONE; \ |
366 source_id.update_flags(&source_flags); \ | |
367 trace_event_internal::TraceID target_id((bind_id)); \ | |
368 unsigned int target_flags = TRACE_EVENT_FLAG_NONE; \ | |
369 target_id.update_flags(&target_flags); \ | |
360 if (target_id.scope() == trace_event_internal::kGlobalScope) { \ | 370 if (target_id.scope() == trace_event_internal::kGlobalScope) { \ |
361 trace_event_internal::AddTraceEvent( \ | 371 trace_event_internal::AddTraceEvent( \ |
362 TRACE_EVENT_PHASE_BIND_IDS, \ | 372 TRACE_EVENT_PHASE_BIND_IDS, \ |
363 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 373 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
364 name, source_id.scope(), source_id.raw_id(), \ | 374 name, source_id.scope(), source_id.raw_id(), \ |
365 TRACE_EVENT_FLAG_HAS_ID, target_id.raw_id(), ##__VA_ARGS__); \ | 375 source_flags, target_id.raw_id(), ##__VA_ARGS__); \ |
366 } else { \ | 376 } else { \ |
367 trace_event_internal::AddTraceEvent( \ | 377 trace_event_internal::AddTraceEvent( \ |
368 TRACE_EVENT_PHASE_BIND_IDS, \ | 378 TRACE_EVENT_PHASE_BIND_IDS, \ |
369 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 379 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
370 name, source_id.scope(), source_id.raw_id(), \ | 380 name, source_id.scope(), source_id.raw_id(), \ |
371 TRACE_EVENT_FLAG_HAS_ID, target_id.raw_id(), \ | 381 source_flags, target_id.raw_id(), \ |
372 "bind_scope", target_id.scope(), ##__VA_ARGS__); \ | 382 "bind_scope", target_id.scope(), ##__VA_ARGS__); \ |
373 } \ | 383 } \ |
374 } \ | 384 } \ |
375 } while (0) | 385 } while (0) |
376 | 386 |
377 // Implementation detail: internal macro to create static category and add | 387 // Implementation detail: internal macro to create static category and add |
378 // metadata event if the category is enabled. | 388 // metadata event if the category is enabled. |
379 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ | 389 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ |
380 do { \ | 390 do { \ |
381 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 391 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
(...skipping 17 matching lines...) Expand all Loading... | |
399 } \ | 409 } \ |
400 \ | 410 \ |
401 private: \ | 411 private: \ |
402 uint64_t cid_; \ | 412 uint64_t cid_; \ |
403 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ | 413 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ |
404 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 414 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
405 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 415 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
406 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 416 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
407 }; \ | 417 }; \ |
408 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 418 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
409 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); | 419 INTERNAL_TRACE_EVENT_UID(scoped_context)(context); |
410 | 420 |
411 // Implementation detail: internal macro to trace a task execution with the | 421 // Implementation detail: internal macro to trace a task execution with the |
412 // location where it was posted from. | 422 // location where it was posted from. |
413 #define INTERNAL_TRACE_TASK_EXECUTION(run_function, task) \ | 423 #define INTERNAL_TRACE_TASK_EXECUTION(run_function, task) \ |
414 TRACE_EVENT2("toplevel", run_function, "src_file", \ | 424 TRACE_EVENT2("toplevel", run_function, "src_file", \ |
415 (task).posted_from.file_name(), "src_func", \ | 425 (task).posted_from.file_name(), "src_func", \ |
416 (task).posted_from.function_name()); \ | 426 (task).posted_from.function_name()); \ |
417 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION INTERNAL_TRACE_EVENT_UID( \ | 427 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION INTERNAL_TRACE_EVENT_UID( \ |
418 task_event)((task).posted_from.file_name()); | 428 task_event)((task).posted_from.file_name()); |
419 | 429 |
420 namespace trace_event_internal { | 430 namespace trace_event_internal { |
421 | 431 |
422 // Specify these values when the corresponding argument of AddTraceEvent is not | 432 // Specify these values when the corresponding argument of AddTraceEvent is not |
423 // used. | 433 // used. |
424 const int kZeroNumArgs = 0; | 434 const int kZeroNumArgs = 0; |
425 const std::nullptr_t kGlobalScope = nullptr; | 435 const std::nullptr_t kGlobalScope = nullptr; |
426 const unsigned long long kNoId = 0; | 436 const unsigned long long kNoId = 0; |
427 | 437 |
428 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 438 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers |
429 // are by default mangled with the Process ID so that they are unlikely to | 439 // are by default mangled with the Process ID so that they are unlikely to |
430 // collide when the same pointer is used on different processes. | 440 // collide when the same pointer is used on different processes. |
431 class TraceID { | 441 class TraceID { |
432 public: | 442 public: |
443 // Can be combined with WithScope. | |
444 class LocalId { | |
445 public: | |
446 explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {} | |
447 unsigned long long raw_id() const { return raw_id_; } | |
448 private: | |
449 unsigned long long raw_id_; | |
450 }; | |
451 | |
452 // Can be combined with WithScope. | |
453 class GlobalId { | |
454 public: | |
455 explicit GlobalId(unsigned long long raw_id) : raw_id_(raw_id) {} | |
456 unsigned long long raw_id() const { return raw_id_; } | |
457 private: | |
458 unsigned long long raw_id_; | |
459 }; | |
460 | |
433 class WithScope { | 461 class WithScope { |
434 public: | 462 public: |
435 WithScope(const char* scope, unsigned long long raw_id) | 463 WithScope(const char* scope, unsigned long long raw_id) |
436 : scope_(scope), raw_id_(raw_id) {} | 464 : scope_(scope), raw_id_(raw_id) {} |
465 WithScope(const char* scope, LocalId local_id) | |
466 : scope_(scope), raw_id_(local_id.raw_id()) { | |
467 flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; | |
468 } | |
469 WithScope(const char* scope, GlobalId global_id) | |
470 : scope_(scope), raw_id_(global_id.raw_id()) { | |
471 flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; | |
472 } | |
437 unsigned long long raw_id() const { return raw_id_; } | 473 unsigned long long raw_id() const { return raw_id_; } |
438 const char* scope() const { return scope_; } | 474 const char* scope() const { return scope_; } |
475 unsigned int flags() const { return flags_; } | |
439 private: | 476 private: |
440 const char* scope_ = nullptr; | 477 const char* scope_ = nullptr; |
441 unsigned long long raw_id_; | 478 unsigned long long raw_id_; |
479 unsigned int flags_ = TRACE_EVENT_FLAG_HAS_ID; | |
442 }; | 480 }; |
443 | 481 |
482 // DEPRECATED: consider using LocalId or GlobalId, instead. | |
444 class DontMangle { | 483 class DontMangle { |
445 public: | 484 public: |
446 explicit DontMangle(const void* raw_id) | 485 explicit DontMangle(const void* raw_id) |
447 : raw_id_(static_cast<unsigned long long>( | 486 : raw_id_(static_cast<unsigned long long>( |
448 reinterpret_cast<uintptr_t>(raw_id))) {} | 487 reinterpret_cast<uintptr_t>(raw_id))) {} |
449 explicit DontMangle(unsigned long long raw_id) : raw_id_(raw_id) {} | 488 explicit DontMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
450 explicit DontMangle(unsigned long raw_id) : raw_id_(raw_id) {} | 489 explicit DontMangle(unsigned long raw_id) : raw_id_(raw_id) {} |
451 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {} | 490 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {} |
452 explicit DontMangle(unsigned short raw_id) : raw_id_(raw_id) {} | 491 explicit DontMangle(unsigned short raw_id) : raw_id_(raw_id) {} |
453 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {} | 492 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {} |
454 explicit DontMangle(long long raw_id) | 493 explicit DontMangle(long long raw_id) |
455 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 494 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
456 explicit DontMangle(long raw_id) | 495 explicit DontMangle(long raw_id) |
457 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 496 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
458 explicit DontMangle(int raw_id) | 497 explicit DontMangle(int raw_id) |
459 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 498 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
460 explicit DontMangle(short raw_id) | 499 explicit DontMangle(short raw_id) |
461 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 500 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
462 explicit DontMangle(signed char raw_id) | 501 explicit DontMangle(signed char raw_id) |
463 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 502 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
464 explicit DontMangle(WithScope scoped_id) | |
465 : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {} | |
466 const char* scope() const { return scope_; } | |
467 unsigned long long raw_id() const { return raw_id_; } | 503 unsigned long long raw_id() const { return raw_id_; } |
468 private: | 504 private: |
469 const char* scope_ = nullptr; | |
470 unsigned long long raw_id_; | 505 unsigned long long raw_id_; |
471 }; | 506 }; |
472 | 507 |
508 // DEPRECATED: consider using LocalId or GlobalId, instead. | |
473 class ForceMangle { | 509 class ForceMangle { |
474 public: | 510 public: |
475 explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} | 511 explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
476 explicit ForceMangle(unsigned long raw_id) : raw_id_(raw_id) {} | 512 explicit ForceMangle(unsigned long raw_id) : raw_id_(raw_id) {} |
477 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {} | 513 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {} |
478 explicit ForceMangle(unsigned short raw_id) : raw_id_(raw_id) {} | 514 explicit ForceMangle(unsigned short raw_id) : raw_id_(raw_id) {} |
479 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {} | 515 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {} |
480 explicit ForceMangle(long long raw_id) | 516 explicit ForceMangle(long long raw_id) |
481 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 517 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
482 explicit ForceMangle(long raw_id) | 518 explicit ForceMangle(long raw_id) |
483 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 519 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
484 explicit ForceMangle(int raw_id) | 520 explicit ForceMangle(int raw_id) |
485 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 521 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
486 explicit ForceMangle(short raw_id) | 522 explicit ForceMangle(short raw_id) |
487 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 523 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
488 explicit ForceMangle(signed char raw_id) | 524 explicit ForceMangle(signed char raw_id) |
489 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 525 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
490 unsigned long long raw_id() const { return raw_id_; } | 526 unsigned long long raw_id() const { return raw_id_; } |
491 private: | 527 private: |
492 unsigned long long raw_id_; | 528 unsigned long long raw_id_; |
493 }; | 529 }; |
494 TraceID(const void* raw_id, unsigned int* flags) | 530 |
495 : raw_id_(static_cast<unsigned long long>( | 531 TraceID(const void* raw_id) : raw_id_(static_cast<unsigned long long>( |
496 reinterpret_cast<uintptr_t>(raw_id))) { | 532 reinterpret_cast<uintptr_t>(raw_id))) { |
497 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | 533 flags_ = TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_MANGLE_ID; |
498 } | 534 } |
499 TraceID(ForceMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { | 535 TraceID(ForceMangle raw_id) : raw_id_(raw_id.raw_id()) { |
500 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | 536 flags_ = TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_MANGLE_ID; |
501 } | 537 } |
502 TraceID(DontMangle maybe_scoped_id, unsigned int* flags) | 538 TraceID(DontMangle raw_id) : raw_id_(raw_id.raw_id()) {} |
503 : scope_(maybe_scoped_id.scope()), raw_id_(maybe_scoped_id.raw_id()) { | 539 TraceID(unsigned long long raw_id) : raw_id_(raw_id) {} |
540 TraceID(unsigned long raw_id) : raw_id_(raw_id) {} | |
541 TraceID(unsigned int raw_id) : raw_id_(raw_id) {} | |
542 TraceID(unsigned short raw_id) : raw_id_(raw_id) {} | |
543 TraceID(unsigned char raw_id) : raw_id_(raw_id) {} | |
544 TraceID(long long raw_id) | |
545 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | |
546 TraceID(long raw_id) | |
547 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | |
548 TraceID(int raw_id) | |
549 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | |
550 TraceID(short raw_id) | |
551 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | |
552 TraceID(signed char raw_id) | |
553 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | |
554 TraceID(LocalId raw_id) : raw_id_(raw_id.raw_id()) { | |
555 flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; | |
504 } | 556 } |
505 TraceID(unsigned long long raw_id, unsigned int* flags) : raw_id_(raw_id) { | 557 TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) { |
506 (void)flags; | 558 flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; |
507 } | 559 } |
508 TraceID(unsigned long raw_id, unsigned int* flags) : raw_id_(raw_id) { | 560 TraceID(WithScope scoped_id) : scope_(scoped_id.scope()), |
509 (void)flags; | 561 raw_id_(scoped_id.raw_id()), flags_(scoped_id.flags()) {} |
510 } | |
511 TraceID(unsigned int raw_id, unsigned int* flags) : raw_id_(raw_id) { | |
512 (void)flags; | |
513 } | |
514 TraceID(unsigned short raw_id, unsigned int* flags) : raw_id_(raw_id) { | |
515 (void)flags; | |
516 } | |
517 TraceID(unsigned char raw_id, unsigned int* flags) : raw_id_(raw_id) { | |
518 (void)flags; | |
519 } | |
520 TraceID(long long raw_id, unsigned int* flags) | |
521 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | |
522 TraceID(long raw_id, unsigned int* flags) | |
523 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | |
524 TraceID(int raw_id, unsigned int* flags) | |
525 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | |
526 TraceID(short raw_id, unsigned int* flags) | |
527 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | |
528 TraceID(signed char raw_id, unsigned int* flags) | |
529 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | |
530 TraceID(WithScope scoped_id, unsigned int* flags) | |
531 : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {} | |
532 | 562 |
533 unsigned long long raw_id() const { return raw_id_; } | 563 unsigned long long raw_id() const { return raw_id_; } |
534 const char* scope() const { return scope_; } | 564 const char* scope() const { return scope_; } |
565 void update_flags(unsigned int* flags) { *flags |= flags_; } | |
caseq
2016/08/29 23:39:26
perhaps just a getter for flags and then something
chiniforooshan
2016/08/30 17:40:46
Done. Changed the method name to id_flags so that
| |
535 | 566 |
536 private: | 567 private: |
537 const char* scope_ = nullptr; | 568 const char* scope_ = nullptr; |
538 unsigned long long raw_id_; | 569 unsigned long long raw_id_; |
570 unsigned int flags_ = TRACE_EVENT_FLAG_HAS_ID; | |
539 }; | 571 }; |
540 | 572 |
541 // Simple union to store various types as unsigned long long. | 573 // Simple union to store various types as unsigned long long. |
542 union TraceValueUnion { | 574 union TraceValueUnion { |
543 bool as_bool; | 575 bool as_bool; |
544 unsigned long long as_uint; | 576 unsigned long long as_uint; |
545 long long as_int; | 577 long long as_int; |
546 double as_double; | 578 double as_double; |
547 const void* as_pointer; | 579 const void* as_pointer; |
548 const char* as_string; | 580 const char* as_string; |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 const char* name_; | 1140 const char* name_; |
1109 IDType id_; | 1141 IDType id_; |
1110 | 1142 |
1111 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1143 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
1112 }; | 1144 }; |
1113 | 1145 |
1114 } // namespace trace_event | 1146 } // namespace trace_event |
1115 } // namespace base | 1147 } // namespace base |
1116 | 1148 |
1117 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 1149 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
OLD | NEW |