| 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) |
| 56 | 62 |
| 57 // Returns a current sampling state of the given bucket. | 63 // Returns a current sampling state of the given bucket. |
| 58 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \ | 64 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \ |
| 59 trace_event_internal::TraceEventSamplingStateScope<bucket_number>::Current() | 65 trace_event_internal::TraceEventSamplingStateScope<bucket_number>::Current() |
| 60 | 66 |
| 61 // Creates a scope of a sampling state of the given bucket. | 67 // Creates a scope of a sampling state of the given bucket. |
| 62 // | 68 // |
| 63 // { // The sampling state is set within this scope. | 69 // { // The sampling state is set within this scope. |
| 64 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); | 70 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name"); |
| 65 // ...; | 71 // ...; |
| 66 // } | 72 // } |
| 67 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \ | 73 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET( \ |
| 68 bucket_number, category, name) \ | 74 bucket_number, category, name) \ |
| 69 trace_event_internal::TraceEventSamplingStateScope<bucket_number> \ | 75 trace_event_internal::TraceEventSamplingStateScope<bucket_number> \ |
| 70 traceEventSamplingScope(category "\0" name); | 76 traceEventSamplingScope(category "\0" name); |
| 71 | 77 |
| 72 #define TRACE_EVENT_API_CURRENT_THREAD_ID \ | 78 #define TRACE_EVENT_API_CURRENT_THREAD_ID \ |
| 73 static_cast<int>(base::PlatformThread::CurrentId()) | 79 static_cast<int>(base::PlatformThread::CurrentId()) |
| 74 | 80 |
| 81 #define INTERNAL_SET_ID_FLAGS(flags, id_bits) \ |
| 82 flags &= TRACE_EVENT_FLAG_ALL - TRACE_EVENT_FLAG_ID_MASK; \ |
| 83 flags |= id_bits; |
| 84 |
| 75 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ | 85 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ |
| 76 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ | 86 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
| 77 (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \ | 87 (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \ |
| 78 base::trace_event::TraceLog::ENABLED_FOR_EVENT_CALLBACK | \ | 88 base::trace_event::TraceLog::ENABLED_FOR_EVENT_CALLBACK | \ |
| 79 base::trace_event::TraceLog::ENABLED_FOR_ETW_EXPORT)) | 89 base::trace_event::TraceLog::ENABLED_FOR_ETW_EXPORT)) |
| 80 | 90 |
| 81 //////////////////////////////////////////////////////////////////////////////// | 91 //////////////////////////////////////////////////////////////////////////////// |
| 82 // Implementation specific tracing API definitions. | 92 // Implementation specific tracing API definitions. |
| 83 | 93 |
| 84 // Get a pointer to the enabled state of the given trace category. Only | 94 // Get a pointer to the enabled state of the given trace category. Only |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 TRACE_EVENT_PHASE_COMPLETE, \ | 301 TRACE_EVENT_PHASE_COMPLETE, \ |
| 292 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 302 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
| 293 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ | 303 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
| 294 trace_event_flags, trace_event_bind_id.raw_id(), ##__VA_ARGS__); \ | 304 trace_event_flags, trace_event_bind_id.raw_id(), ##__VA_ARGS__); \ |
| 295 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ | 305 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ |
| 296 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ | 306 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ |
| 297 } | 307 } |
| 298 | 308 |
| 299 // Implementation detail: internal macro to create static category and add | 309 // Implementation detail: internal macro to create static category and add |
| 300 // event if the category is enabled. | 310 // event if the category is enabled. |
| 301 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ | 311 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ |
| 302 flags, ...) \ | 312 flags, ...) \ |
| 303 do { \ | 313 do { \ |
| 304 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 314 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 305 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 315 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 306 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 316 unsigned int trace_event_flags = flags; \ |
| 307 trace_event_internal::TraceID trace_event_trace_id( \ | 317 trace_event_internal::TraceID trace_event_trace_id( \ |
| 308 id, &trace_event_flags); \ | 318 id, &trace_event_flags); \ |
| 309 trace_event_internal::AddTraceEvent( \ | 319 trace_event_internal::AddTraceEvent( \ |
| 310 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 320 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| 311 name, trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ | 321 name, trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
| 312 trace_event_flags, trace_event_internal::kNoId, ##__VA_ARGS__); \ | 322 trace_event_flags, trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 313 } \ | 323 } \ |
| 314 } while (0) | 324 } while (0) |
| 315 | 325 |
| 316 // Implementation detail: internal macro to create static category and add | 326 // Implementation detail: internal macro to create static category and add |
| 317 // event if the category is enabled. | 327 // event if the category is enabled. |
| 318 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \ | 328 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \ |
| 319 timestamp, flags, ...) \ | 329 timestamp, flags, ...) \ |
| 320 do { \ | 330 do { \ |
| 321 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 331 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 322 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 332 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 323 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 333 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
| 324 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 334 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
| 325 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ | 335 trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
| 326 TRACE_EVENT_API_CURRENT_THREAD_ID, \ | 336 TRACE_EVENT_API_CURRENT_THREAD_ID, \ |
| 327 base::TimeTicks::FromInternalValue(timestamp), \ | 337 base::TimeTicks::FromInternalValue(timestamp), \ |
| 328 flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 338 flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
| 329 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 339 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 330 } \ | 340 } \ |
| 331 } while (0) | 341 } while (0) |
| 332 | 342 |
| 333 // Implementation detail: internal macro to create static category and add | 343 // Implementation detail: internal macro to create static category and add |
| 334 // event if the category is enabled. | 344 // event if the category is enabled. |
| 335 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ | 345 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ |
| 336 phase, category_group, name, id, thread_id, timestamp, flags, ...) \ | 346 phase, category_group, name, id, thread_id, timestamp, flags, ...) \ |
| 337 do { \ | 347 do { \ |
| 338 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 348 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 339 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 349 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 340 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ | 350 unsigned int trace_event_flags = flags; \ |
| 341 trace_event_internal::TraceID trace_event_trace_id(id, \ | 351 trace_event_internal::TraceID trace_event_trace_id(id, \ |
| 342 &trace_event_flags); \ | 352 &trace_event_flags); \ |
| 343 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ | 353 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ |
| 344 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ | 354 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
| 345 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ | 355 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \ |
| 346 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ | 356 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ |
| 347 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ | 357 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ |
| 348 trace_event_internal::kNoId, ##__VA_ARGS__); \ | 358 trace_event_internal::kNoId, ##__VA_ARGS__); \ |
| 349 } \ | 359 } \ |
| 350 } while (0) | 360 } while (0) |
| 351 | 361 |
| 352 // The trace ID and bind ID will never be mangled by this macro. | 362 // 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, \ | 363 #define INTERNAL_TRACE_EVENT_ADD_BIND_IDS(category_group, name, id, bind_id, \ |
| 354 ...) \ | 364 ...) \ |
| 355 do { \ | 365 do { \ |
| 356 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 366 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| 357 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ | 367 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
| 358 trace_event_internal::TraceID::DontMangle source_id(id); \ | 368 unsigned int source_flags = TRACE_EVENT_FLAG_NONE; \ |
| 359 trace_event_internal::TraceID::DontMangle target_id(bind_id); \ | 369 trace_event_internal::TraceID source_id(id, &source_flags); \ |
| 370 unsigned int target_flags = TRACE_EVENT_FLAG_NONE; \ |
| 371 trace_event_internal::TraceID target_id(bind_id, &target_flags); \ |
| 360 if (target_id.scope() == trace_event_internal::kGlobalScope) { \ | 372 if (target_id.scope() == trace_event_internal::kGlobalScope) { \ |
| 361 trace_event_internal::AddTraceEvent( \ | 373 trace_event_internal::AddTraceEvent( \ |
| 362 TRACE_EVENT_PHASE_BIND_IDS, \ | 374 TRACE_EVENT_PHASE_BIND_IDS, \ |
| 363 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 375 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| 364 name, source_id.scope(), source_id.raw_id(), \ | 376 name, source_id.scope(), source_id.raw_id(), \ |
| 365 TRACE_EVENT_FLAG_HAS_ID, target_id.raw_id(), ##__VA_ARGS__); \ | 377 source_flags, target_id.raw_id(), ##__VA_ARGS__); \ |
| 366 } else { \ | 378 } else { \ |
| 367 trace_event_internal::AddTraceEvent( \ | 379 trace_event_internal::AddTraceEvent( \ |
| 368 TRACE_EVENT_PHASE_BIND_IDS, \ | 380 TRACE_EVENT_PHASE_BIND_IDS, \ |
| 369 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ | 381 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ |
| 370 name, source_id.scope(), source_id.raw_id(), \ | 382 name, source_id.scope(), source_id.raw_id(), \ |
| 371 TRACE_EVENT_FLAG_HAS_ID, target_id.raw_id(), \ | 383 source_flags, target_id.raw_id(), \ |
| 372 "bind_scope", target_id.scope(), ##__VA_ARGS__); \ | 384 "bind_scope", target_id.scope(), ##__VA_ARGS__); \ |
| 373 } \ | 385 } \ |
| 374 } \ | 386 } \ |
| 375 } while (0) | 387 } while (0) |
| 376 | 388 |
| 377 // Implementation detail: internal macro to create static category and add | 389 // Implementation detail: internal macro to create static category and add |
| 378 // metadata event if the category is enabled. | 390 // metadata event if the category is enabled. |
| 379 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ | 391 #define INTERNAL_TRACE_EVENT_METADATA_ADD(category_group, name, ...) \ |
| 380 do { \ | 392 do { \ |
| 381 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ | 393 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 399 } \ | 411 } \ |
| 400 \ | 412 \ |
| 401 private: \ | 413 private: \ |
| 402 uint64_t cid_; \ | 414 uint64_t cid_; \ |
| 403 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ | 415 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ |
| 404 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 416 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| 405 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 417 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| 406 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ | 418 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ |
| 407 }; \ | 419 }; \ |
| 408 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ | 420 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| 409 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); | 421 INTERNAL_TRACE_EVENT_UID(scoped_context)(context); |
| 410 | 422 |
| 411 // Implementation detail: internal macro to trace a task execution with the | 423 // Implementation detail: internal macro to trace a task execution with the |
| 412 // location where it was posted from. | 424 // location where it was posted from. |
| 413 #define INTERNAL_TRACE_TASK_EXECUTION(run_function, task) \ | 425 #define INTERNAL_TRACE_TASK_EXECUTION(run_function, task) \ |
| 414 TRACE_EVENT2("toplevel", run_function, "src_file", \ | 426 TRACE_EVENT2("toplevel", run_function, "src_file", \ |
| 415 (task).posted_from.file_name(), "src_func", \ | 427 (task).posted_from.file_name(), "src_func", \ |
| 416 (task).posted_from.function_name()); \ | 428 (task).posted_from.function_name()); \ |
| 417 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION INTERNAL_TRACE_EVENT_UID( \ | 429 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION INTERNAL_TRACE_EVENT_UID( \ |
| 418 task_event)((task).posted_from.file_name()); | 430 task_event)((task).posted_from.file_name()); |
| 419 | 431 |
| 420 namespace trace_event_internal { | 432 namespace trace_event_internal { |
| 421 | 433 |
| 422 // Specify these values when the corresponding argument of AddTraceEvent is not | 434 // Specify these values when the corresponding argument of AddTraceEvent is not |
| 423 // used. | 435 // used. |
| 424 const int kZeroNumArgs = 0; | 436 const int kZeroNumArgs = 0; |
| 425 const std::nullptr_t kGlobalScope = nullptr; | 437 const std::nullptr_t kGlobalScope = nullptr; |
| 426 const unsigned long long kNoId = 0; | 438 const unsigned long long kNoId = 0; |
| 427 | 439 |
| 428 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | 440 // 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 | 441 // 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. | 442 // collide when the same pointer is used on different processes. |
| 431 class TraceID { | 443 class TraceID { |
| 432 public: | 444 public: |
| 445 // Can be combined with WithScope. |
| 446 class LocalId { |
| 447 public: |
| 448 explicit LocalId(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 449 unsigned long long raw_id() const { return raw_id_; } |
| 450 private: |
| 451 unsigned long long raw_id_; |
| 452 }; |
| 453 |
| 454 // Can be combined with WithScope. |
| 455 class GlobalId { |
| 456 public: |
| 457 explicit GlobalId(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 458 unsigned long long raw_id() const { return raw_id_; } |
| 459 private: |
| 460 unsigned long long raw_id_; |
| 461 }; |
| 462 |
| 433 class WithScope { | 463 class WithScope { |
| 434 public: | 464 public: |
| 435 WithScope(const char* scope, unsigned long long raw_id) | 465 WithScope(const char* scope, unsigned long long raw_id) |
| 436 : scope_(scope), raw_id_(raw_id) {} | 466 : scope_(scope), raw_id_(raw_id) {} |
| 467 WithScope(const char* scope, LocalId local_id) |
| 468 : scope_(scope), raw_id_(local_id.raw_id()) { |
| 469 flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; |
| 470 } |
| 471 WithScope(const char* scope, GlobalId global_id) |
| 472 : scope_(scope), raw_id_(global_id.raw_id()) { |
| 473 flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; |
| 474 } |
| 437 unsigned long long raw_id() const { return raw_id_; } | 475 unsigned long long raw_id() const { return raw_id_; } |
| 438 const char* scope() const { return scope_; } | 476 const char* scope() const { return scope_; } |
| 477 unsigned int flags() const { return flags_; } |
| 439 private: | 478 private: |
| 440 const char* scope_ = nullptr; | 479 const char* scope_ = nullptr; |
| 441 unsigned long long raw_id_; | 480 unsigned long long raw_id_; |
| 481 unsigned int flags_ = TRACE_EVENT_FLAG_HAS_ID; |
| 442 }; | 482 }; |
| 443 | 483 |
| 484 // DEPRECATED: consider using LocalId or GlobalId, instead. |
| 444 class DontMangle { | 485 class DontMangle { |
| 445 public: | 486 public: |
| 446 explicit DontMangle(const void* raw_id) | 487 explicit DontMangle(const void* raw_id) |
| 447 : raw_id_(static_cast<unsigned long long>( | 488 : raw_id_(static_cast<unsigned long long>( |
| 448 reinterpret_cast<uintptr_t>(raw_id))) {} | 489 reinterpret_cast<uintptr_t>(raw_id))) {} |
| 449 explicit DontMangle(unsigned long long raw_id) : raw_id_(raw_id) {} | 490 explicit DontMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 450 explicit DontMangle(unsigned long raw_id) : raw_id_(raw_id) {} | 491 explicit DontMangle(unsigned long raw_id) : raw_id_(raw_id) {} |
| 451 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {} | 492 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {} |
| 452 explicit DontMangle(unsigned short raw_id) : raw_id_(raw_id) {} | 493 explicit DontMangle(unsigned short raw_id) : raw_id_(raw_id) {} |
| 453 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {} | 494 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {} |
| 454 explicit DontMangle(long long raw_id) | 495 explicit DontMangle(long long raw_id) |
| 455 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 496 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 456 explicit DontMangle(long raw_id) | 497 explicit DontMangle(long raw_id) |
| 457 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 498 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 458 explicit DontMangle(int raw_id) | 499 explicit DontMangle(int raw_id) |
| 459 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 500 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 460 explicit DontMangle(short raw_id) | 501 explicit DontMangle(short raw_id) |
| 461 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 502 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 462 explicit DontMangle(signed char raw_id) | 503 explicit DontMangle(signed char raw_id) |
| 463 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 504 : 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_; } | 505 unsigned long long raw_id() const { return raw_id_; } |
| 468 private: | 506 private: |
| 469 const char* scope_ = nullptr; | |
| 470 unsigned long long raw_id_; | 507 unsigned long long raw_id_; |
| 471 }; | 508 }; |
| 472 | 509 |
| 510 // DEPRECATED: consider using LocalId or GlobalId, instead. |
| 473 class ForceMangle { | 511 class ForceMangle { |
| 474 public: | 512 public: |
| 475 explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} | 513 explicit ForceMangle(unsigned long long raw_id) : raw_id_(raw_id) {} |
| 476 explicit ForceMangle(unsigned long raw_id) : raw_id_(raw_id) {} | 514 explicit ForceMangle(unsigned long raw_id) : raw_id_(raw_id) {} |
| 477 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {} | 515 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {} |
| 478 explicit ForceMangle(unsigned short raw_id) : raw_id_(raw_id) {} | 516 explicit ForceMangle(unsigned short raw_id) : raw_id_(raw_id) {} |
| 479 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {} | 517 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {} |
| 480 explicit ForceMangle(long long raw_id) | 518 explicit ForceMangle(long long raw_id) |
| 481 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 519 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 482 explicit ForceMangle(long raw_id) | 520 explicit ForceMangle(long raw_id) |
| 483 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 521 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 484 explicit ForceMangle(int raw_id) | 522 explicit ForceMangle(int raw_id) |
| 485 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 523 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 486 explicit ForceMangle(short raw_id) | 524 explicit ForceMangle(short raw_id) |
| 487 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 525 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 488 explicit ForceMangle(signed char raw_id) | 526 explicit ForceMangle(signed char raw_id) |
| 489 : raw_id_(static_cast<unsigned long long>(raw_id)) {} | 527 : raw_id_(static_cast<unsigned long long>(raw_id)) {} |
| 490 unsigned long long raw_id() const { return raw_id_; } | 528 unsigned long long raw_id() const { return raw_id_; } |
| 491 private: | 529 private: |
| 492 unsigned long long raw_id_; | 530 unsigned long long raw_id_; |
| 493 }; | 531 }; |
| 532 |
| 494 TraceID(const void* raw_id, unsigned int* flags) | 533 TraceID(const void* raw_id, unsigned int* flags) |
| 495 : raw_id_(static_cast<unsigned long long>( | 534 : raw_id_(static_cast<unsigned long long>( |
| 496 reinterpret_cast<uintptr_t>(raw_id))) { | 535 reinterpret_cast<uintptr_t>(raw_id))) { |
| 536 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 497 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | 537 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; |
| 498 } | 538 } |
| 499 TraceID(ForceMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { | 539 TraceID(ForceMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| 540 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 500 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; | 541 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; |
| 501 } | 542 } |
| 502 TraceID(DontMangle maybe_scoped_id, unsigned int* flags) | 543 TraceID(DontMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| 503 : scope_(maybe_scoped_id.scope()), raw_id_(maybe_scoped_id.raw_id()) { | 544 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 504 } | 545 } |
| 505 TraceID(unsigned long long raw_id, unsigned int* flags) : raw_id_(raw_id) { | 546 TraceID(unsigned long long raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| 506 (void)flags; | 547 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 507 } | 548 } |
| 508 TraceID(unsigned long raw_id, unsigned int* flags) : raw_id_(raw_id) { | 549 TraceID(unsigned long raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| 509 (void)flags; | 550 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 510 } | 551 } |
| 511 TraceID(unsigned int raw_id, unsigned int* flags) : raw_id_(raw_id) { | 552 TraceID(unsigned int raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| 512 (void)flags; | 553 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 513 } | 554 } |
| 514 TraceID(unsigned short raw_id, unsigned int* flags) : raw_id_(raw_id) { | 555 TraceID(unsigned short raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| 515 (void)flags; | 556 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 516 } | 557 } |
| 517 TraceID(unsigned char raw_id, unsigned int* flags) : raw_id_(raw_id) { | 558 TraceID(unsigned char raw_id, unsigned int* flags) : raw_id_(raw_id) { |
| 518 (void)flags; | 559 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 519 } | 560 } |
| 520 TraceID(long long raw_id, unsigned int* flags) | 561 TraceID(long long raw_id, unsigned int* flags) |
| 521 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | 562 : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| 563 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 564 } |
| 522 TraceID(long raw_id, unsigned int* flags) | 565 TraceID(long raw_id, unsigned int* flags) |
| 523 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | 566 : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| 567 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 568 } |
| 524 TraceID(int raw_id, unsigned int* flags) | 569 TraceID(int raw_id, unsigned int* flags) |
| 525 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | 570 : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| 571 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 572 } |
| 526 TraceID(short raw_id, unsigned int* flags) | 573 TraceID(short raw_id, unsigned int* flags) |
| 527 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | 574 : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| 575 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 576 } |
| 528 TraceID(signed char raw_id, unsigned int* flags) | 577 TraceID(signed char raw_id, unsigned int* flags) |
| 529 : raw_id_(static_cast<unsigned long long>(raw_id)) { (void)flags; } | 578 : raw_id_(static_cast<unsigned long long>(raw_id)) { |
| 579 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_ID); |
| 580 } |
| 581 TraceID(LocalId raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| 582 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_LOCAL_ID); |
| 583 } |
| 584 TraceID(GlobalId raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) { |
| 585 INTERNAL_SET_ID_FLAGS(*flags, TRACE_EVENT_FLAG_HAS_GLOBAL_ID); |
| 586 } |
| 530 TraceID(WithScope scoped_id, unsigned int* flags) | 587 TraceID(WithScope scoped_id, unsigned int* flags) |
| 531 : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {} | 588 : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) { |
| 589 INTERNAL_SET_ID_FLAGS(*flags, scoped_id.flags()); |
| 590 } |
| 532 | 591 |
| 533 unsigned long long raw_id() const { return raw_id_; } | 592 unsigned long long raw_id() const { return raw_id_; } |
| 534 const char* scope() const { return scope_; } | 593 const char* scope() const { return scope_; } |
| 535 | 594 |
| 536 private: | 595 private: |
| 537 const char* scope_ = nullptr; | 596 const char* scope_ = nullptr; |
| 538 unsigned long long raw_id_; | 597 unsigned long long raw_id_; |
| 539 }; | 598 }; |
| 540 | 599 |
| 541 // Simple union to store various types as unsigned long long. | 600 // Simple union to store various types as unsigned long long. |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 const char* name_; | 1167 const char* name_; |
| 1109 IDType id_; | 1168 IDType id_; |
| 1110 | 1169 |
| 1111 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); | 1170 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); |
| 1112 }; | 1171 }; |
| 1113 | 1172 |
| 1114 } // namespace trace_event | 1173 } // namespace trace_event |
| 1115 } // namespace base | 1174 } // namespace base |
| 1116 | 1175 |
| 1117 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ | 1176 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ |
| OLD | NEW |