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

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

Issue 1784133002: [tracing] Adding task information to heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Petr's comments Created 4 years, 8 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
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.
11 11
12 #include <stddef.h> 12 #include <stddef.h>
13 #include <stdint.h> 13 #include <stdint.h>
14 14
15 #include <string> 15 #include <string>
16 16
17 #include "base/atomicops.h" 17 #include "base/atomicops.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "base/trace_event/common/trace_event_common.h" 20 #include "base/trace_event/common/trace_event_common.h"
21 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
21 #include "base/trace_event/trace_event_system_stats_monitor.h" 22 #include "base/trace_event/trace_event_system_stats_monitor.h"
22 #include "base/trace_event/trace_log.h" 23 #include "base/trace_event/trace_log.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 25
25 // 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
26 // 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.
27 #define TRACE_STR_COPY(str) \ 28 #define TRACE_STR_COPY(str) \
28 trace_event_internal::TraceStringWithCopy(str) 29 trace_event_internal::TraceStringWithCopy(str)
29 30
30 // By default, uint64_t ID argument values are not mangled with the Process ID 31 // By default, uint64_t ID argument values are not mangled with the Process ID
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 private: \ 376 private: \
376 uint64_t cid_; \ 377 uint64_t cid_; \
377 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \ 378 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \
378 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ 379 INTERNAL_TRACE_EVENT_UID(ScopedContext) \
379 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ 380 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \
380 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \ 381 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {}; \
381 }; \ 382 }; \
382 INTERNAL_TRACE_EVENT_UID(ScopedContext) \ 383 INTERNAL_TRACE_EVENT_UID(ScopedContext) \
383 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); 384 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id());
384 385
386 // Special trace event macro to trace task execution with the location where it
387 // was posted from.
388 #define TRACE_TASK_EXECUTION(run_function, task) \
oystein (OOO til 10th of July) 2016/03/29 21:28:35 I don't think this belongs in trace_event.h; typic
ssid 2016/03/29 23:04:19 Thanks I was really confused about trace_event.h a
oystein (OOO til 10th of July) 2016/03/29 23:44:52 Almost! I mainly don't think trace_event.h should
389 TRACE_EVENT2("toplevel", (run_function), "src_file", \
oystein (OOO til 10th of July) 2016/03/29 21:28:35 Why are the parameter usages all wrapped by ()? We
ssid 2016/03/29 23:04:19 Ah, it existed in the other file and I had copied
390 (task).posted_from.file_name(), "src_func", \
391 (task).posted_from.function_name()); \
392 trace_event_internal::ScopedTaskExecutionEvent event( \
oystein (OOO til 10th of July) 2016/03/29 21:28:35 INTERNAL_TRACE_EVENT_UID(event) to avoid conflicts
ssid 2016/03/29 23:04:19 Done.
393 (task).posted_from.file_name());
394
385 namespace trace_event_internal { 395 namespace trace_event_internal {
386 396
387 // Specify these values when the corresponding argument of AddTraceEvent is not 397 // Specify these values when the corresponding argument of AddTraceEvent is not
388 // used. 398 // used.
389 const int kZeroNumArgs = 0; 399 const int kZeroNumArgs = 0;
390 const std::nullptr_t kGlobalScope = nullptr; 400 const std::nullptr_t kGlobalScope = nullptr;
391 const unsigned long long kNoId = 0; 401 const unsigned long long kNoId = 0;
392 402
393 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers 403 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers
394 // are by default mangled with the Process ID so that they are unlikely to 404 // are by default mangled with the Process ID so that they are unlikely to
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 TRACE_EVENT_API_ATOMIC_STORE( 1048 TRACE_EVENT_API_ATOMIC_STORE(
1039 g_trace_state[BucketNumber], 1049 g_trace_state[BucketNumber],
1040 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( 1050 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
1041 const_cast<char*>(category_and_name))); 1051 const_cast<char*>(category_and_name)));
1042 } 1052 }
1043 1053
1044 private: 1054 private:
1045 const char* previous_state_; 1055 const char* previous_state_;
1046 }; 1056 };
1047 1057
1058 // ScopedTaskExecutionEvent records the current task's context in the heap
1059 // profiler.
1060 class ScopedTaskExecutionEvent {
1061 public:
1062 ScopedTaskExecutionEvent(const char* task_context) : context_(task_context) {
1063 if (UNLIKELY(
1064 base::trace_event::AllocationContextTracker::capture_enabled())) {
1065 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread()
1066 ->PushCurrentTaskContext(context_);
1067 }
1068 }
1069
1070 ~ScopedTaskExecutionEvent() {
1071 if (UNLIKELY(
1072 base::trace_event::AllocationContextTracker::capture_enabled())) {
1073 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread()
1074 ->PopCurrentTaskContext(context_);
1075 }
1076 }
1077
1078 private:
1079 const char* context_;
1080 };
1081
1048 } // namespace trace_event_internal 1082 } // namespace trace_event_internal
1049 1083
1050 namespace base { 1084 namespace base {
1051 namespace trace_event { 1085 namespace trace_event {
1052 1086
1053 template<typename IDType> class TraceScopedTrackableObject { 1087 template<typename IDType> class TraceScopedTrackableObject {
1054 public: 1088 public:
1055 TraceScopedTrackableObject(const char* category_group, const char* name, 1089 TraceScopedTrackableObject(const char* category_group, const char* name,
1056 IDType id) 1090 IDType id)
1057 : category_group_(category_group), 1091 : category_group_(category_group),
(...skipping 15 matching lines...) Expand all
1073 const char* name_; 1107 const char* name_;
1074 IDType id_; 1108 IDType id_;
1075 1109
1076 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject); 1110 DISALLOW_COPY_AND_ASSIGN(TraceScopedTrackableObject);
1077 }; 1111 };
1078 1112
1079 } // namespace trace_event 1113 } // namespace trace_event
1080 } // namespace base 1114 } // namespace base
1081 1115
1082 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_ 1116 #endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698