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

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

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (rebase) Created 3 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
« no previous file with comments | « base/memory/shared_memory_posix.cc ('k') | base/memory/shared_memory_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <unordered_map> 8 #include <unordered_map>
9 9
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "base/trace_event/memory_dump_provider.h" 12 #include "base/trace_event/memory_dump_provider.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 namespace trace_event { 16 namespace trace_event {
17 class MemoryAllocatorDumpGuid;
17 class ProcessMemoryDump; 18 class ProcessMemoryDump;
18 } 19 }
19 20
20 // SharedMemoryTracker tracks shared memory usage. 21 // SharedMemoryTracker tracks shared memory usage.
21 class BASE_EXPORT SharedMemoryTracker 22 class BASE_EXPORT SharedMemoryTracker
22 : public base::trace_event::MemoryDumpProvider { 23 : public base::trace_event::MemoryDumpProvider {
23 public: 24 public:
24 // Returns a singleton instance. 25 // Returns a singleton instance.
25 static SharedMemoryTracker* GetInstance(); 26 static SharedMemoryTracker* GetInstance();
26 27
28 // Adds two ownership edges between the given guid |source| and its global
29 // shared memory dump. This helps to get accurate effective size of modules
30 // that backend is shared memory.
31 static bool AddOwnershipEdges(
32 trace_event::ProcessMemoryDump* pmd,
33 const trace_event::MemoryAllocatorDumpGuid& source,
34 const SharedMemory& shared_memory);
35
27 // Records shared memory usage on mapping. 36 // Records shared memory usage on mapping.
28 void IncrementMemoryUsage(const SharedMemory& shared_memory); 37 void IncrementMemoryUsage(const SharedMemory& shared_memory);
29 38
30 // Records shared memory usage on unmapping. 39 // Records shared memory usage on unmapping.
31 void DecrementMemoryUsage(const SharedMemory& shared_memory); 40 void DecrementMemoryUsage(const SharedMemory& shared_memory);
32 41
33 private: 42 private:
34 struct Usage {
35 Usage();
36 Usage(const Usage& rhs);
37 ~Usage();
38 SharedMemory::UniqueId unique_id;
39 size_t size;
40 };
41
42 SharedMemoryTracker(); 43 SharedMemoryTracker();
43 ~SharedMemoryTracker() override; 44 ~SharedMemoryTracker() override;
44 45
45 // base::trace_event::MemoryDumpProvider implementation. 46 // base::trace_event::MemoryDumpProvider implementation.
46 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 47 bool OnMemoryDump(const trace_event::MemoryDumpArgs& args,
47 base::trace_event::ProcessMemoryDump* pmd) override; 48 trace_event::ProcessMemoryDump* pmd) override;
48 49
49 // Used to lock when |usages_| is modified or read. 50 // Used to lock when |usages_| is modified or read.
50 Lock usages_lock_; 51 Lock usages_lock_;
51 std::unordered_map<const SharedMemory*, Usage> usages_; 52 std::unordered_map<const SharedMemory*, size_t> usages_;
52 53
53 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker); 54 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
54 }; 55 };
55 56
56 } // namespace base 57 } // namespace base
57 58
58 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ 59 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
OLDNEW
« no previous file with comments | « base/memory/shared_memory_posix.cc ('k') | base/memory/shared_memory_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698