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

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: Created 5 years 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.
11 11
12 #include <string> 12 #include <string>
13 13
14 #include "base/atomicops.h" 14 #include "base/atomicops.h"
15 #include "base/macros.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/trace_event/common/trace_event_common.h" 17 #include "base/trace_event/common/trace_event_common.h"
17 #include "base/trace_event/trace_event_system_stats_monitor.h" 18 #include "base/trace_event/trace_event_system_stats_monitor.h"
18 #include "base/trace_event/trace_log.h" 19 #include "base/trace_event/trace_log.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 21
21 // By default, const char* argument values are assumed to have long-lived scope 22 // By default, const char* argument values are assumed to have long-lived scope
22 // and will not be copied. Use this macro to force a const char* to be copied. 23 // and will not be copied. Use this macro to force a const char* to be copied.
23 #define TRACE_STR_COPY(str) \ 24 #define TRACE_STR_COPY(str) \
24 trace_event_internal::TraceStringWithCopy(str) 25 trace_event_internal::TraceStringWithCopy(str)
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 id, &trace_event_flags); \ 329 id, &trace_event_flags); \
329 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \ 330 trace_event_internal::AddTraceEventWithThreadIdAndTimestamp( \
330 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \ 331 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
331 name, trace_event_trace_id.data(), trace_event_internal::kNoId, \ 332 name, trace_event_trace_id.data(), trace_event_internal::kNoId, \
332 thread_id, base::TimeTicks::FromInternalValue(timestamp), \ 333 thread_id, base::TimeTicks::FromInternalValue(timestamp), \
333 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \ 334 trace_event_flags | TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP, \
334 trace_event_internal::kNoId, ##__VA_ARGS__); \ 335 trace_event_internal::kNoId, ##__VA_ARGS__); \
335 } \ 336 } \
336 } while (0) 337 } while (0)
337 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)
fmeawad 2016/01/19 18:38:10 Can you move this to common as well, I do not see
Sami 2016/01/20 10:34:08 Yeah, I wasn't sure where we draw the line. I didn
338 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
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 TRACE_EVENT_API_ATOMIC_STORE( 896 TRACE_EVENT_API_ATOMIC_STORE(
891 g_trace_state[BucketNumber], 897 g_trace_state[BucketNumber],
892 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( 898 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
893 const_cast<char*>(category_and_name))); 899 const_cast<char*>(category_and_name)));
894 } 900 }
895 901
896 private: 902 private:
897 const char* previous_state_; 903 const char* previous_state_;
898 }; 904 };
899 905
906 using TraceContext = const void*;
907
908 class TraceScopedContext {
909 public:
910 TraceScopedContext(const char* category_group,
911 const char* name,
912 TraceContext context)
913 : category_group_(category_group), name_(name), context_(context) {
914 TRACE_EVENT_ENTER_CONTEXT(category_group_, name_, context_);
915 }
916
917 ~TraceScopedContext() {
918 TRACE_EVENT_LEAVE_CONTEXT(category_group_, name_, context_);
919 }
920
921 private:
922 const char* category_group_;
923 const char* name_;
924 TraceContext context_;
925 DISALLOW_COPY_AND_ASSIGN(TraceScopedContext);
926 };
927
900 } // namespace trace_event_internal 928 } // namespace trace_event_internal
901 929
902 namespace base { 930 namespace base {
903 namespace trace_event { 931 namespace trace_event {
904 932
933 using trace_event_internal::TraceContext;
934
905 template<typename IDType> class TraceScopedTrackableObject { 935 template<typename IDType> class TraceScopedTrackableObject {
906 public: 936 public:
907 TraceScopedTrackableObject(const char* category_group, const char* name, 937 TraceScopedTrackableObject(const char* category_group, const char* name,
908 IDType id) 938 IDType id)
909 : category_group_(category_group), 939 : category_group_(category_group),
910 name_(name), 940 name_(name),
911 id_(id) { 941 id_(id) {
912 TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group_, name_, id_); 942 TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group_, name_, id_);
913 } 943 }
914 944
(...skipping 10 matching lines...) Expand all
925 const char* name_; 955 const char* name_;
926 IDType id_; 956 IDType id_;
927 957
928 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 958 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
929 }; 959 };
930 960
931 } // namespace trace_event 961 } // namespace trace_event
932 } // namespace base 962 } // namespace base
933 963
934 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 964 #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