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

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

Issue 1499683002: tracing: Add macros for generating context trace events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 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 | « base/trace_event/common/trace_event_common.h ('k') | base/trace_event/trace_event_unittest.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_macros_common.h instead of here. 10 // implementation-specific should go in trace_macros_common.h instead of here.
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 &trace_event_flags); \ 329 &trace_event_flags); \
330 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ 330 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \
331 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 331 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
332 trace_event_trace_id.data(), thread_id, \ 332 trace_event_trace_id.data(), thread_id, \
333 base::TimeTicks::FromInternalValue(timestamp), \ 333 base::TimeTicks::FromInternalValue(timestamp), \
334 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ 334 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \
335 trace_event_internal::kNoId, ##__VA_ARGS__); \ 335 trace_event_internal::kNoId, ##__VA_ARGS__); \
336 } \ 336 } \
337 } while (0) 337 } while (0)
338 338
339 // Implementation detail: internal macro to enter and leave a context based on
340 // the current scope.
341 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \
342 trace_event_internal::TraceScopedContext INTERNAL_TRACE_EVENT_UID( \
343 scoped_trace)(category_group, name, context)
344
339 namespace trace_event_internal { 345 namespace trace_event_internal {
340 346
341 // Specify these values when the corresponding argument of AddTraceEvent is not 347 // Specify these values when the corresponding argument of AddTraceEvent is not
342 // used. 348 // used.
343 const int kZeroNumArgs = 0; 349 const int kZeroNumArgs = 0;
344 const unsigned long long kNoId = 0; 350 const unsigned long long kNoId = 0;
345 351
346 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers 352 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers
347 // are by default mangled with the Process ID so that they are unlikely to 353 // are by default mangled with the Process ID so that they are unlikely to
348 // collide when the same pointer is used on different processes. 354 // collide when the same pointer is used on different processes.
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 TRACE_EVENT_API_ATOMIC_STORE( 882 TRACE_EVENT_API_ATOMIC_STORE(
877 g_trace_state[BucketNumber], 883 g_trace_state[BucketNumber],
878 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( 884 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
879 const_cast<char*>(category_and_name))); 885 const_cast<char*>(category_and_name)));
880 } 886 }
881 887
882 private: 888 private:
883 const char* previous_state_; 889 const char* previous_state_;
884 }; 890 };
885 891
892 using TraceContext = const void*;
893
894 class TraceScopedContext {
895 public:
896 TraceScopedContext(const char* category_group,
897 const char* name,
898 TraceContext context)
899 : category_group_(category_group), name_(name), context_(context) {
900 TRACE_EVENT_ENTER_CONTEXT(category_group_, name_, context_);
901 }
902
903 ~TraceScopedContext() {
904 TRACE_EVENT_LEAVE_CONTEXT(category_group_, name_, context_);
905 }
906
907 private:
908 const char* category_group_;
909 const char* name_;
910 TraceContext context_;
911 DISALLOW_COPY_AND_ASSIGN(TraceScopedContext);
912 };
913
886 } // namespace trace_event_internal 914 } // namespace trace_event_internal
887 915
888 namespace base { 916 namespace base {
889 namespace trace_event { 917 namespace trace_event {
890 918
919 using trace_event_internal::TraceContext;
920
891 template<typename IDType> class TraceScopedTrackableObject { 921 template<typename IDType> class TraceScopedTrackableObject {
892 public: 922 public:
893 TraceScopedTrackableObject(const char* category_group, const char* name, 923 TraceScopedTrackableObject(const char* category_group, const char* name,
894 IDType id) 924 IDType id)
895 : category_group_(category_group), 925 : category_group_(category_group),
896 name_(name), 926 name_(name),
897 id_(id) { 927 id_(id) {
898 TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group_, name_, id_); 928 TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group_, name_, id_);
899 } 929 }
900 930
(...skipping 10 matching lines...) Expand all
911 const char* name_; 941 const char* name_;
912 IDType id_; 942 IDType id_;
913 943
914 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 944 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
915 }; 945 };
916 946
917 } // namespace trace_event 947 } // namespace trace_event
918 } // namespace base 948 } // namespace base
919 949
920 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 950 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « base/trace_event/common/trace_event_common.h ('k') | base/trace_event/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698