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

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

Issue 1950313005: [tracing] Move and rename TRACE_EVENT_API_TASK_EXECUTION_EVENT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_missing_task
Patch Set: fix unittest. Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_HEAP_PROFILER_H 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_H
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_H 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_H
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 9 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
10 10
11 // This header file defines the set of macros that are used to track memory 11 // This header file defines the set of macros that are used to track memory
12 // usage in the heap profiler. This is in addition to the macros defined in 12 // usage in the heap profiler. This is in addition to the macros defined in
13 // trace_event.h and are specific to heap profiler. This file also defines 13 // trace_event.h and are specific to heap profiler. This file also defines
14 // implementation details of these macros. 14 // implementation details of these macros.
15 15
16 // Implementation detail: heap profiler macros create temporary variables to 16 // Implementation detail: heap profiler macros create temporary variables to
17 // keep instrumentation overhead low. These macros give each temporary variable 17 // keep instrumentation overhead low. These macros give each temporary variable
18 // a unique name based on the line number to prevent name collisions. 18 // a unique name based on the line number to prevent name collisions.
19 #define INTERNAL_HEAP_PROFILER_UID3(a, b) heap_profiler_unique_##a##b 19 #define INTERNAL_HEAP_PROFILER_UID3(a, b) heap_profiler_unique_##a##b
20 #define INTERNAL_HEAP_PROFILER_UID2(a, b) INTERNAL_HEAP_PROFILER_UID3(a, b) 20 #define INTERNAL_HEAP_PROFILER_UID2(a, b) INTERNAL_HEAP_PROFILER_UID3(a, b)
21 #define INTERNAL_HEAP_PROFILER_UID(name_prefix) \ 21 #define INTERNAL_HEAP_PROFILER_UID(name_prefix) \
22 INTERNAL_HEAP_PROFILER_UID2(name_prefix, __LINE__) 22 INTERNAL_HEAP_PROFILER_UID2(name_prefix, __LINE__)
23 23
24 // Scoped tracker for task execution context in the heap profiler.
25 #define TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION \
26 trace_event_internal::HeapProfilerScopedTaskExecutionTracker
27
24 // A scoped ignore event used to tell heap profiler to ignore all the 28 // A scoped ignore event used to tell heap profiler to ignore all the
25 // allocations in the scope. It is useful to exclude allocations made for 29 // allocations in the scope. It is useful to exclude allocations made for
26 // tracing from the heap profiler dumps. 30 // tracing from the heap profiler dumps.
27 #define HEAP_PROFILER_SCOPED_IGNORE \ 31 #define HEAP_PROFILER_SCOPED_IGNORE \
28 trace_event_internal::HeapProfilerScopedIgnore INTERNAL_HEAP_PROFILER_UID( \ 32 trace_event_internal::HeapProfilerScopedIgnore INTERNAL_HEAP_PROFILER_UID( \
29 scoped_ignore) 33 scoped_ignore)
30 34
31 namespace trace_event_internal { 35 namespace trace_event_internal {
32 36
37 // HeapProfilerScopedTaskExecutionTracker records the current task's context in
38 // the heap profiler.
39 class HeapProfilerScopedTaskExecutionTracker {
40 public:
41 inline explicit HeapProfilerScopedTaskExecutionTracker(
42 const char* task_context)
43 : context_(task_context) {
44 using base::trace_event::AllocationContextTracker;
45 if (UNLIKELY(AllocationContextTracker::capture_mode() !=
46 AllocationContextTracker::CaptureMode::DISABLED)) {
47 AllocationContextTracker::GetInstanceForCurrentThread()
48 ->PushCurrentTaskContext(context_);
49 }
50 }
51
52 inline ~HeapProfilerScopedTaskExecutionTracker() {
53 using base::trace_event::AllocationContextTracker;
54 if (UNLIKELY(AllocationContextTracker::capture_mode() !=
55 AllocationContextTracker::CaptureMode::DISABLED)) {
56 AllocationContextTracker::GetInstanceForCurrentThread()
57 ->PopCurrentTaskContext(context_);
58 }
59 }
60
61 private:
62 const char* context_;
63 };
64
33 class BASE_EXPORT HeapProfilerScopedIgnore { 65 class BASE_EXPORT HeapProfilerScopedIgnore {
34 public: 66 public:
35 inline HeapProfilerScopedIgnore() { 67 inline HeapProfilerScopedIgnore() {
36 using base::trace_event::AllocationContextTracker; 68 using base::trace_event::AllocationContextTracker;
37 if (UNLIKELY( 69 if (UNLIKELY(
38 AllocationContextTracker::capture_mode() != 70 AllocationContextTracker::capture_mode() !=
39 AllocationContextTracker::CaptureMode::DISABLED)) { 71 AllocationContextTracker::CaptureMode::DISABLED)) {
40 AllocationContextTracker::GetInstanceForCurrentThread() 72 AllocationContextTracker::GetInstanceForCurrentThread()
41 ->begin_ignore_scope(); 73 ->begin_ignore_scope();
42 } 74 }
43 } 75 }
44 inline ~HeapProfilerScopedIgnore() { 76 inline ~HeapProfilerScopedIgnore() {
45 using base::trace_event::AllocationContextTracker; 77 using base::trace_event::AllocationContextTracker;
46 if (UNLIKELY( 78 if (UNLIKELY(
47 AllocationContextTracker::capture_mode() != 79 AllocationContextTracker::capture_mode() !=
48 AllocationContextTracker::CaptureMode::DISABLED)) { 80 AllocationContextTracker::CaptureMode::DISABLED)) {
49 AllocationContextTracker::GetInstanceForCurrentThread() 81 AllocationContextTracker::GetInstanceForCurrentThread()
50 ->end_ignore_scope(); 82 ->end_ignore_scope();
51 } 83 }
52 } 84 }
53 }; 85 };
54 86
55 } // namespace trace_event_internal 87 } // namespace trace_event_internal
56 88
57 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_H 89 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_H
OLDNEW
« no previous file with comments | « base/trace_event/common/trace_event_common.h ('k') | base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698