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

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

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

Powered by Google App Engine
This is Rietveld 408576698