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

Side by Side Diff: base/memory/shared_memory_tracker.h

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (wip) Created 3 years, 9 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_MEMORY_SHARED_MEMORY_TRACKER_H_ 5 #ifndef BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
6 #define BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ 6 #define BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
7 7
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "base/trace_event/memory_dump_provider.h" 10 #include "base/trace_event/memory_dump_provider.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 namespace trace_event { 14 namespace trace_event {
15 class MemoryAllocatorDumpGuid;
15 class ProcessMemoryDump; 16 class ProcessMemoryDump;
16 } 17 }
17 18
19 #if !defined(OS_NACL)
18 // SharedMemoryTracker tracks shared memory usage. 20 // SharedMemoryTracker tracks shared memory usage.
19 class BASE_EXPORT SharedMemoryTracker 21 class BASE_EXPORT SharedMemoryTracker
20 : public base::trace_event::MemoryDumpProvider { 22 : public base::trace_event::MemoryDumpProvider {
21 public: 23 public:
22 // Returns a singleton instance. 24 // Returns a singleton instance.
23 static SharedMemoryTracker* GetInstance(); 25 static SharedMemoryTracker* GetInstance();
24 26
27 // TODO: Importances
28 static bool AddOwnershipEdges(
29 trace_event::ProcessMemoryDump* pmd,
30 const trace_event::MemoryAllocatorDumpGuid& source,
31 const SharedMemoryHandle& shared_memory_handle,
32 size_t mapped_size);
33
25 // Records shared memory usage on mapping. 34 // Records shared memory usage on mapping.
26 void IncrementMemoryUsage(const SharedMemory& shared_memory); 35 void IncrementMemoryUsage(const SharedMemory& shared_memory);
27 36
28 // Records shared memory usage on unmapping. 37 // Records shared memory usage on unmapping.
29 void DecrementMemoryUsage(const SharedMemory& shared_memory); 38 void DecrementMemoryUsage(const SharedMemory& shared_memory);
30 39
31 private: 40 private:
32 struct Usage { 41 struct Usage {
33 Usage(); 42 Usage();
34 Usage(const Usage& rhs); 43 Usage(const Usage& rhs);
35 ~Usage(); 44 ~Usage();
36 SharedMemory::UniqueId unique_id; 45 SharedMemory::UniqueId unique_id;
37 size_t size; 46 size_t size;
38 }; 47 };
39 48
40 SharedMemoryTracker(); 49 SharedMemoryTracker();
41 ~SharedMemoryTracker() override; 50 ~SharedMemoryTracker() override;
42 51
43 // base::trace_event::MemoryDumpProvider implementation. 52 // base::trace_event::MemoryDumpProvider implementation.
44 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 53 bool OnMemoryDump(const trace_event::MemoryDumpArgs& args,
45 base::trace_event::ProcessMemoryDump* pmd) override; 54 trace_event::ProcessMemoryDump* pmd) override;
46 55
47 // Used to lock when |usages_| is modified or read. 56 // Used to lock when |usages_| is modified or read.
48 Lock usages_lock_; 57 Lock usages_lock_;
49 std::unordered_map<const SharedMemory*, Usage> usages_; 58 std::unordered_map<const SharedMemory*, Usage> usages_;
50 59
51 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker); 60 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
52 }; 61 };
53 62
63 #else
64
65 class BASE_EXPORT SharedMemoryTracker {
66 public:
67 static SharedMemoryTracker* GetInstance() {
68 static SharedMemoryTracker* instance = new SharedMemoryTracker;
69 return instance;
70 }
71
72 // TODO: Importances
73 static bool AddOwnershipEdges(
74 trace_event::ProcessMemoryDump* pmd,
75 const trace_event::MemoryAllocatorDumpGuid& source,
76 const SharedMemoryHandle& shared_memory_handle,
77 size_t mapped_size) {
78 return true;
79 }
80
81 // Records shared memory usage on mapping.
82 void IncrementMemoryUsage(const SharedMemory& shared_memory) {}
83
84 // Records shared memory usage on unmapping.
85 void DecrementMemoryUsage(const SharedMemory& shared_memory) {}
86 };
87
88 #endif // !defined(OS_NACL)
89
54 } // namespace base 90 } // namespace base
55 91
56 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ 92 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698