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

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

Issue 1469843002: Remove dependency on allocator from 'content' targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify_allocator1_2
Patch Set: Fix build Created 5 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_MEMORY_H_ 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_H_
6 #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_H_ 6 #define BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_H_
7 7
8 #include "base/allocator/allocator_extension.h"
8 #include "base/base_export.h" 9 #include "base/base_export.h"
9 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
13 #include "base/trace_event/trace_log.h" 14 #include "base/trace_event/trace_log.h"
14 15
15 // TODO(jamescook): Windows support for memory tracing. 16 // TODO(jamescook): Windows support for memory tracing.
16 #if !defined(NO_TCMALLOC) && !defined(OS_NACL) && \ 17 #if !defined(NO_TCMALLOC) && !defined(OS_NACL) && \
17 (defined(OS_LINUX) || defined(OS_ANDROID)) 18 (defined(OS_LINUX) || defined(OS_ANDROID))
18 #define TCMALLOC_TRACE_MEMORY_SUPPORTED 1 19 #define TCMALLOC_TRACE_MEMORY_SUPPORTED 1
19 #endif 20 #endif
20 21
21 namespace base { 22 namespace base {
22 23
23 class SingleThreadTaskRunner; 24 class SingleThreadTaskRunner;
24 25
25 namespace trace_event { 26 namespace trace_event {
26 27
27 // Watches for chrome://tracing to be enabled or disabled. When tracing is 28 // Watches for chrome://tracing to be enabled or disabled. When tracing is
28 // enabled, also enables tcmalloc heap profiling. This class is the preferred 29 // enabled, also enables tcmalloc heap profiling. This class is the preferred
29 // way to turn trace-base heap memory profiling on and off. 30 // way to turn trace-base heap memory profiling on and off.
30 class BASE_EXPORT TraceMemoryController 31 class BASE_EXPORT TraceMemoryController
31 : public TraceLog::EnabledStateObserver { 32 : public TraceLog::EnabledStateObserver {
32 public: 33 public:
33 typedef int (*StackGeneratorFunction)(int skip_count, void** stack);
34 typedef void (*HeapProfilerStartFunction)(StackGeneratorFunction callback);
35 typedef void (*HeapProfilerStopFunction)();
36 typedef char* (*GetHeapProfileFunction)();
37
38 // |task_runner| must be a task runner for the primary thread for the client 34 // |task_runner| must be a task runner for the primary thread for the client
39 // process, e.g. the UI thread in a browser. The function pointers must be 35 // process, e.g. the UI thread in a browser.
40 // pointers to tcmalloc heap profiling functions; by avoiding direct calls to 36 TraceMemoryController(scoped_refptr<SingleThreadTaskRunner> task_runner);
41 // these functions we avoid a dependency on third_party/tcmalloc from base.
42 TraceMemoryController(scoped_refptr<SingleThreadTaskRunner> task_runner,
43 HeapProfilerStartFunction heap_profiler_start_function,
44 HeapProfilerStopFunction heap_profiler_stop_function,
45 GetHeapProfileFunction get_heap_profile_function);
46 ~TraceMemoryController() override; 37 ~TraceMemoryController() override;
47 38
48 // base::trace_event::TraceLog::EnabledStateChangedObserver overrides: 39 // base::trace_event::TraceLog::EnabledStateChangedObserver overrides:
49 void OnTraceLogEnabled() override; 40 void OnTraceLogEnabled() override;
50 void OnTraceLogDisabled() override; 41 void OnTraceLogDisabled() override;
51 42
52 // Starts heap memory profiling. 43 // Starts heap memory profiling.
53 void StartProfiling(); 44 void StartProfiling();
54 45
55 // Captures a heap profile. 46 // Captures a heap profile.
56 void DumpMemoryProfile(); 47 void DumpMemoryProfile();
57 48
58 // If memory tracing is enabled, dumps a memory profile to the tracing system. 49 // If memory tracing is enabled, dumps a memory profile to the tracing system.
59 void StopProfiling(); 50 void StopProfiling();
60 51
61 private: 52 private:
62 FRIEND_TEST_ALL_PREFIXES(TraceMemoryTest, TraceMemoryController); 53 FRIEND_TEST_ALL_PREFIXES(TraceMemoryTest, TraceMemoryController);
63 54
64 bool IsTimerRunningForTest() const; 55 bool IsTimerRunningForTest() const;
65 56
66 // Ensures the observer starts and stops tracing on the primary thread. 57 // Ensures the observer starts and stops tracing on the primary thread.
67 scoped_refptr<SingleThreadTaskRunner> task_runner_; 58 scoped_refptr<SingleThreadTaskRunner> task_runner_;
68 59
69 // Pointers to tcmalloc heap profiling functions. Allows this class to use
70 // tcmalloc functions without introducing a dependency from base to tcmalloc.
71 HeapProfilerStartFunction heap_profiler_start_function_;
72 HeapProfilerStopFunction heap_profiler_stop_function_;
73 GetHeapProfileFunction get_heap_profile_function_;
74
75 // Timer to schedule memory profile dumps. 60 // Timer to schedule memory profile dumps.
76 RepeatingTimer dump_timer_; 61 RepeatingTimer dump_timer_;
77 62
78 WeakPtrFactory<TraceMemoryController> weak_factory_; 63 WeakPtrFactory<TraceMemoryController> weak_factory_;
79 64
80 DISALLOW_COPY_AND_ASSIGN(TraceMemoryController); 65 DISALLOW_COPY_AND_ASSIGN(TraceMemoryController);
81 }; 66 };
82 67
83 ////////////////////////////////////////////////////////////////////////////// 68 //////////////////////////////////////////////////////////////////////////////
84 69
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 #else 147 #else
163 #define INTERNAL_TRACE_MEMORY(category, name) 148 #define INTERNAL_TRACE_MEMORY(category, name)
164 #endif // defined(TRACE_MEMORY_SUPPORTED) 149 #endif // defined(TRACE_MEMORY_SUPPORTED)
165 150
166 // A special trace name that allows us to ignore memory allocations inside 151 // A special trace name that allows us to ignore memory allocations inside
167 // the memory dump system itself. The allocations are recorded, but the 152 // the memory dump system itself. The allocations are recorded, but the
168 // visualizer skips them. Must match the value in heap.js. 153 // visualizer skips them. Must match the value in heap.js.
169 #define TRACE_MEMORY_IGNORE "trace-memory-ignore" 154 #define TRACE_MEMORY_IGNORE "trace-memory-ignore"
170 155
171 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_H_ 156 #endif // BASE_TRACE_EVENT_TRACE_EVENT_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698