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

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

Issue 2504753002: tracing: Introduce API for composite IDs (Closed)
Patch Set: comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #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 25 matching lines...) Expand all
36 #define TRACE_ID_MANGLE(id) \ 36 #define TRACE_ID_MANGLE(id) \
37 trace_event_internal::TraceID::ForceMangle(id) 37 trace_event_internal::TraceID::ForceMangle(id)
38 38
39 // DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros, 39 // DEPRECATED: do not use: Consider using TRACE_ID_{GLOBAL, LOCAL} macros,
40 // instead. By default, pointers are mangled with the Process ID in 40 // instead. By default, pointers are mangled with the Process ID in
41 // TRACE_EVENT_ASYNC macros. Use this macro to prevent Process ID mangling. 41 // TRACE_EVENT_ASYNC macros. Use this macro to prevent Process ID mangling.
42 #define TRACE_ID_DONT_MANGLE(id) \ 42 #define TRACE_ID_DONT_MANGLE(id) \
43 trace_event_internal::TraceID::DontMangle(id) 43 trace_event_internal::TraceID::DontMangle(id)
44 44
45 // By default, trace IDs are eventually converted to a single 64-bit number. Use 45 // By default, trace IDs are eventually converted to a single 64-bit number. Use
46 // this macro to add a scope string. 46 // this macro to add a scope string. For example,
47 #define TRACE_ID_WITH_SCOPE(scope, id) \ 47 //
48 trace_event_internal::TraceID::WithScope(scope, id) 48 // TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
49 // "network", "ResourceLoad",
50 // TRACE_ID_WITH_SCOPE("BlinkResourceID", resourceID));
51 //
52 // Also, it is possible to prepend the ID with another number, like the process
53 // ID. This is useful in creatin IDs that are unique among all processes. To do
54 // that, pass two numbers after the scope string instead of one. For example,
55 //
56 // TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(
57 // "network", "ResourceLoad",
58 // TRACE_ID_WITH_SCOPE("BlinkResourceID", pid, resourceID));
59 #define TRACE_ID_WITH_SCOPE(scope, ...) \
60 trace_event_internal::TraceID::WithScope(scope, ##__VA_ARGS__)
49 61
50 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id) 62 #define TRACE_ID_GLOBAL(id) trace_event_internal::TraceID::GlobalId(id)
51 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id) 63 #define TRACE_ID_LOCAL(id) trace_event_internal::TraceID::LocalId(id)
52 64
53 #define TRACE_EVENT_API_CURRENT_THREAD_ID \ 65 #define TRACE_EVENT_API_CURRENT_THREAD_ID \
54 static_cast<int>(base::PlatformThread::CurrentId()) 66 static_cast<int>(base::PlatformThread::CurrentId())
55 67
56 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ 68 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
57 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ 69 UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
58 (base::trace_event::TraceCategory::ENABLED_FOR_RECORDING | \ 70 (base::trace_event::TraceCategory::ENABLED_FOR_RECORDING | \
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 WithScope(const char* scope, unsigned long long raw_id) 435 WithScope(const char* scope, unsigned long long raw_id)
424 : scope_(scope), raw_id_(raw_id) {} 436 : scope_(scope), raw_id_(raw_id) {}
425 WithScope(const char* scope, LocalId local_id) 437 WithScope(const char* scope, LocalId local_id)
426 : scope_(scope), raw_id_(local_id.raw_id()) { 438 : scope_(scope), raw_id_(local_id.raw_id()) {
427 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; 439 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID;
428 } 440 }
429 WithScope(const char* scope, GlobalId global_id) 441 WithScope(const char* scope, GlobalId global_id)
430 : scope_(scope), raw_id_(global_id.raw_id()) { 442 : scope_(scope), raw_id_(global_id.raw_id()) {
431 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; 443 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID;
432 } 444 }
445 WithScope(const char* scope,
446 unsigned long long prefix,
447 unsigned long long raw_id)
448 : scope_(scope), has_prefix_(true), prefix_(prefix), raw_id_(raw_id) {}
449 WithScope(const char* scope, unsigned long long prefix, GlobalId global_id)
450 : scope_(scope),
451 has_prefix_(true),
452 prefix_(prefix),
453 raw_id_(global_id.raw_id()) {
454 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID;
455 }
433 unsigned long long raw_id() const { return raw_id_; } 456 unsigned long long raw_id() const { return raw_id_; }
434 const char* scope() const { return scope_; } 457 const char* scope() const { return scope_; }
458 bool has_prefix() const { return has_prefix_; }
459 unsigned long long prefix() const { return prefix_; }
435 unsigned int id_flags() const { return id_flags_; } 460 unsigned int id_flags() const { return id_flags_; }
461
436 private: 462 private:
437 const char* scope_ = nullptr; 463 const char* scope_ = nullptr;
464 bool has_prefix_ = false;
465 unsigned long long prefix_;
438 unsigned long long raw_id_; 466 unsigned long long raw_id_;
439 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; 467 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID;
440 }; 468 };
441 469
442 // DEPRECATED: consider using LocalId or GlobalId, instead. 470 // DEPRECATED: consider using LocalId or GlobalId, instead.
443 class DontMangle { 471 class DontMangle {
444 public: 472 public:
445 explicit DontMangle(const void* raw_id) 473 explicit DontMangle(const void* raw_id)
446 : raw_id_(static_cast<unsigned long long>( 474 : raw_id_(static_cast<unsigned long long>(
447 reinterpret_cast<uintptr_t>(raw_id))) {} 475 reinterpret_cast<uintptr_t>(raw_id))) {}
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 TraceID(short raw_id) 538 TraceID(short raw_id)
511 : raw_id_(static_cast<unsigned long long>(raw_id)) {} 539 : raw_id_(static_cast<unsigned long long>(raw_id)) {}
512 TraceID(signed char raw_id) 540 TraceID(signed char raw_id)
513 : raw_id_(static_cast<unsigned long long>(raw_id)) {} 541 : raw_id_(static_cast<unsigned long long>(raw_id)) {}
514 TraceID(LocalId raw_id) : raw_id_(raw_id.raw_id()) { 542 TraceID(LocalId raw_id) : raw_id_(raw_id.raw_id()) {
515 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID; 543 id_flags_ = TRACE_EVENT_FLAG_HAS_LOCAL_ID;
516 } 544 }
517 TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) { 545 TraceID(GlobalId raw_id) : raw_id_(raw_id.raw_id()) {
518 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID; 546 id_flags_ = TRACE_EVENT_FLAG_HAS_GLOBAL_ID;
519 } 547 }
520 TraceID(WithScope scoped_id) : scope_(scoped_id.scope()), 548 TraceID(WithScope scoped_id)
521 raw_id_(scoped_id.raw_id()), id_flags_(scoped_id.id_flags()) {} 549 : scope_(scoped_id.scope()),
550 has_prefix_(scoped_id.has_prefix()),
551 prefix_(scoped_id.prefix()),
552 raw_id_(scoped_id.raw_id()),
553 id_flags_(scoped_id.id_flags()) {}
522 554
523 unsigned long long raw_id() const { return raw_id_; } 555 unsigned long long raw_id() const { return raw_id_; }
524 const char* scope() const { return scope_; } 556 const char* scope() const { return scope_; }
557 bool has_prefix() const { return has_prefix_; }
558 unsigned long long prefix() const { return prefix_; }
525 unsigned int id_flags() const { return id_flags_; } 559 unsigned int id_flags() const { return id_flags_; }
526 560
527 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 561 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
528 AsConvertableToTraceFormat() const; 562 AsConvertableToTraceFormat() const;
529 563
530 private: 564 private:
531 const char* scope_ = nullptr; 565 const char* scope_ = nullptr;
566 bool has_prefix_ = false;
567 unsigned long long prefix_;
532 unsigned long long raw_id_; 568 unsigned long long raw_id_;
533 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID; 569 unsigned int id_flags_ = TRACE_EVENT_FLAG_HAS_ID;
534 }; 570 };
535 571
536 // Simple union to store various types as unsigned long long. 572 // Simple union to store various types as unsigned long long.
537 union TraceValueUnion { 573 union TraceValueUnion {
538 bool as_bool; 574 bool as_bool;
539 unsigned long long as_uint; 575 unsigned long long as_uint;
540 long long as_int; 576 long long as_int;
541 double as_double; 577 double as_double;
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 const char* name_; 1109 const char* name_;
1074 IDType id_; 1110 IDType id_;
1075 1111
1076 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 1112 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
1077 }; 1113 };
1078 1114
1079 } // namespace trace_event 1115 } // namespace trace_event
1080 } // namespace base 1116 } // namespace base
1081 1117
1082 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 1118 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698