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

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

Issue 2775423003: Add ownership edges between HostSharedBitmap and shared memory
Patch Set: Fix comments Created 3 years, 8 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 "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
18 // SharedMemoryTracker tracks shared memory usage. 19 // SharedMemoryTracker tracks shared memory usage.
19 class BASE_EXPORT SharedMemoryTracker 20 class BASE_EXPORT SharedMemoryTracker
20 : public base::trace_event::MemoryDumpProvider { 21 : public base::trace_event::MemoryDumpProvider {
21 public: 22 public:
22 // Returns a singleton instance. 23 // Returns a singleton instance.
23 static SharedMemoryTracker* GetInstance(); 24 static SharedMemoryTracker* GetInstance();
24 25
26 // Adds two ownership edges between the given guid |source| and its global
27 // shared memory dump. This helps to get accurate effective size of modules
28 // that backend is shared memory.
29 static bool AddOwnershipEdges(
30 trace_event::ProcessMemoryDump* pmd,
31 const trace_event::MemoryAllocatorDumpGuid& source,
32 const SharedMemoryHandle& shared_memory_handle);
33 static bool AddOwnershipEdges(
34 trace_event::ProcessMemoryDump* pmd,
35 const trace_event::MemoryAllocatorDumpGuid& source,
36 const SharedMemoryHandle& shared_memory_handle,
37 int importance);
38
25 // Records shared memory usage on mapping. 39 // Records shared memory usage on mapping.
26 void IncrementMemoryUsage(const SharedMemory& shared_memory); 40 void IncrementMemoryUsage(const SharedMemory& shared_memory);
27 41
28 // Records shared memory usage on unmapping. 42 // Records shared memory usage on unmapping.
29 void DecrementMemoryUsage(const SharedMemory& shared_memory); 43 void DecrementMemoryUsage(const SharedMemory& shared_memory);
30 44
31 private: 45 private:
32 struct Usage { 46 struct Usage {
33 Usage(); 47 Usage();
34 Usage(const Usage& rhs); 48 Usage(const Usage& rhs);
35 ~Usage(); 49 ~Usage();
36 SharedMemory::UniqueId unique_id; 50 SharedMemory::UniqueId unique_id;
37 size_t size; 51 size_t size;
38 }; 52 };
39 53
40 SharedMemoryTracker(); 54 SharedMemoryTracker();
41 ~SharedMemoryTracker() override; 55 ~SharedMemoryTracker() override;
42 56
43 // base::trace_event::MemoryDumpProvider implementation. 57 // base::trace_event::MemoryDumpProvider implementation.
44 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 58 bool OnMemoryDump(const trace_event::MemoryDumpArgs& args,
45 base::trace_event::ProcessMemoryDump* pmd) override; 59 trace_event::ProcessMemoryDump* pmd) override;
46 60
47 // Used to lock when |usages_| is modified or read. 61 // Used to lock when |usages_| is modified or read.
48 Lock usages_lock_; 62 Lock usages_lock_;
49 std::unordered_map<const SharedMemory*, Usage> usages_; 63 std::unordered_map<const SharedMemory*, Usage> usages_;
50 64
51 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker); 65 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
52 }; 66 };
53 67
54 } // namespace base 68 } // namespace base
55 69
56 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ 70 #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