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

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: 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 HEAP_PROFILER_API_SCOPED_TASK_EXECUTION_EVENT \
26 trace_event_internal::HeapProfilerScopedTaskExecutionEvent
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 // HeapProfilerScopedTaskExecutionEvent records the current task's context in
38 // the heap profiler.
39 class HeapProfilerScopedTaskExecutionEvent {
40 public:
41 inline explicit HeapProfilerScopedTaskExecutionEvent(const char* task_context)
42 : context_(task_context) {
43 if (UNLIKELY(
44 base::trace_event::AllocationContextTracker::capture_enabled())) {
45 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread()
46 ->PushCurrentTaskContext(context_);
47 }
48 }
49
50 inline ~HeapProfilerScopedTaskExecutionEvent() {
51 if (UNLIKELY(
52 base::trace_event::AllocationContextTracker::capture_enabled())) {
53 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread()
54 ->PopCurrentTaskContext(context_);
55 }
56 }
57
58 private:
59 const char* context_;
60 };
61
33 class BASE_EXPORT HeapProfilerScopedIgnore { 62 class BASE_EXPORT HeapProfilerScopedIgnore {
34 public: 63 public:
35 inline HeapProfilerScopedIgnore() { 64 inline HeapProfilerScopedIgnore() {
36 if (UNLIKELY( 65 if (UNLIKELY(
37 base::trace_event::AllocationContextTracker::capture_enabled())) { 66 base::trace_event::AllocationContextTracker::capture_enabled())) {
38 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() 67 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread()
39 ->begin_ignore_scope(); 68 ->begin_ignore_scope();
40 } 69 }
41 } 70 }
42 inline ~HeapProfilerScopedIgnore() { 71 inline ~HeapProfilerScopedIgnore() {
43 if (UNLIKELY( 72 if (UNLIKELY(
44 base::trace_event::AllocationContextTracker::capture_enabled())) { 73 base::trace_event::AllocationContextTracker::capture_enabled())) {
45 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() 74 base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread()
46 ->end_ignore_scope(); 75 ->end_ignore_scope();
47 } 76 }
48 } 77 }
49 }; 78 };
50 79
51 } // namespace trace_event_internal 80 } // namespace trace_event_internal
52 81
53 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_H 82 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698