OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_MALLOC_DUMP_PROVIDER_H_ | 5 #ifndef BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_ |
6 #define BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_ | 6 #define BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_ |
7 | 7 |
8 #include <istream> | 8 #include <istream> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/synchronization/lock.h" | |
14 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
15 #include "base/trace_event/memory_dump_provider.h" | 14 #include "base/trace_event/memory_dump_provider.h" |
16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
17 | 16 |
18 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN) || \ | 17 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_WIN) || \ |
19 (defined(OS_MACOSX) && !defined(OS_IOS)) | 18 (defined(OS_MACOSX) && !defined(OS_IOS)) |
20 #define MALLOC_MEMORY_TRACING_SUPPORTED | 19 #define MALLOC_MEMORY_TRACING_SUPPORTED |
21 #endif | 20 #endif |
22 | 21 |
23 namespace base { | 22 namespace base { |
24 namespace trace_event { | 23 namespace trace_event { |
25 | 24 |
26 class AllocationRegister; | 25 class ShardedAllocationRegister; |
27 | 26 |
28 // Dump provider which collects process-wide memory stats. | 27 // Dump provider which collects process-wide memory stats. |
29 class BASE_EXPORT MallocDumpProvider : public MemoryDumpProvider { | 28 class BASE_EXPORT MallocDumpProvider : public MemoryDumpProvider { |
30 public: | 29 public: |
31 // Name of the allocated_objects dump. Use this to declare suballocator dumps | 30 // Name of the allocated_objects dump. Use this to declare suballocator dumps |
32 // from other dump providers. | 31 // from other dump providers. |
33 static const char kAllocatedObjects[]; | 32 static const char kAllocatedObjects[]; |
34 | 33 |
35 static MallocDumpProvider* GetInstance(); | 34 static MallocDumpProvider* GetInstance(); |
36 | 35 |
37 // MemoryDumpProvider implementation. | 36 // MemoryDumpProvider implementation. |
38 bool OnMemoryDump(const MemoryDumpArgs& args, | 37 bool OnMemoryDump(const MemoryDumpArgs& args, |
39 ProcessMemoryDump* pmd) override; | 38 ProcessMemoryDump* pmd) override; |
40 | 39 |
41 void OnHeapProfilingEnabled(bool enabled) override; | 40 void OnHeapProfilingEnabled(bool enabled) override; |
42 | 41 |
43 // For heap profiling. | 42 // For heap profiling. |
44 void InsertAllocation(void* address, size_t size); | 43 void InsertAllocation(void* address, size_t size); |
45 void RemoveAllocation(void* address); | 44 void RemoveAllocation(void* address); |
46 | 45 |
47 private: | 46 private: |
48 friend struct DefaultSingletonTraits<MallocDumpProvider>; | 47 friend struct DefaultSingletonTraits<MallocDumpProvider>; |
49 | 48 |
50 MallocDumpProvider(); | 49 MallocDumpProvider(); |
51 ~MallocDumpProvider() override; | 50 ~MallocDumpProvider() override; |
52 | 51 |
53 // For heap profiling. | 52 // For heap profiling. |
54 bool heap_profiler_enabled_; | 53 std::unique_ptr<ShardedAllocationRegister> allocation_register_; |
Primiano Tucci (use gerrit)
2017/05/22 16:37:50
there is no need for a unique_ptr anymore here now
erikchen
2017/05/22 17:10:42
Done.
| |
55 std::unique_ptr<AllocationRegister> allocation_register_; | |
56 Lock allocation_register_lock_; | |
57 | 54 |
58 // When in OnMemoryDump(), this contains the current thread ID. | 55 // When in OnMemoryDump(), this contains the current thread ID. |
59 // This is to prevent re-entrancy in the heap profiler when the heap dump | 56 // This is to prevent re-entrancy in the heap profiler when the heap dump |
60 // generation is malloc/new-ing for its own bookeeping data structures. | 57 // generation is malloc/new-ing for its own bookeeping data structures. |
61 PlatformThreadId tid_dumping_heap_; | 58 PlatformThreadId tid_dumping_heap_; |
62 | 59 |
63 DISALLOW_COPY_AND_ASSIGN(MallocDumpProvider); | 60 DISALLOW_COPY_AND_ASSIGN(MallocDumpProvider); |
64 }; | 61 }; |
65 | 62 |
66 } // namespace trace_event | 63 } // namespace trace_event |
67 } // namespace base | 64 } // namespace base |
68 | 65 |
69 #endif // BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_ | 66 #endif // BASE_TRACE_EVENT_MALLOC_DUMP_PROVIDER_H_ |
OLD | NEW |