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

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

Issue 2873433004: Replace SharedMemory::UniqueID usages with SharedMemoryHandle's guid (Closed)
Patch Set: Address on reviews 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 <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 ProcessMemoryDump; 17 class ProcessMemoryDump;
18 } 18 }
19 19
20 // SharedMemoryTracker tracks shared memory usage. 20 // SharedMemoryTracker tracks shared memory usage.
21 class BASE_EXPORT SharedMemoryTracker 21 class BASE_EXPORT SharedMemoryTracker : public trace_event::MemoryDumpProvider {
22 : public base::trace_event::MemoryDumpProvider {
23 public: 22 public:
24 // Returns a singleton instance. 23 // Returns a singleton instance.
25 static SharedMemoryTracker* GetInstance(); 24 static SharedMemoryTracker* GetInstance();
26 25
27 // Records shared memory usage on mapping. 26 // Records shared memory usage on mapping.
28 void IncrementMemoryUsage(const SharedMemory& shared_memory); 27 void IncrementMemoryUsage(const SharedMemory& shared_memory);
29 28
30 // Records shared memory usage on unmapping. 29 // Records shared memory usage on unmapping.
31 void DecrementMemoryUsage(const SharedMemory& shared_memory); 30 void DecrementMemoryUsage(const SharedMemory& shared_memory);
32 31
33 private: 32 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(); 33 SharedMemoryTracker();
43 ~SharedMemoryTracker() override; 34 ~SharedMemoryTracker() override;
44 35
45 // base::trace_event::MemoryDumpProvider implementation. 36 // trace_event::MemoryDumpProvider implementation.
46 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 37 bool OnMemoryDump(const trace_event::MemoryDumpArgs& args,
47 base::trace_event::ProcessMemoryDump* pmd) override; 38 trace_event::ProcessMemoryDump* pmd) override;
48 39
49 // Used to lock when |usages_| is modified or read. 40 // Used to lock when |usages_| is modified or read.
50 Lock usages_lock_; 41 Lock usages_lock_;
51 std::unordered_map<const SharedMemory*, Usage> usages_; 42 std::map<const SharedMemory*, size_t> usages_;
52 43
53 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker); 44 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
54 }; 45 };
55 46
56 } // namespace base 47 } // namespace base
57 48
58 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ 49 #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