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

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

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

Powered by Google App Engine
This is Rietveld 408576698