Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ | |
| 6 #define BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ | |
| 7 | |
| 8 #include "base/memory/shared_memory.h" | |
| 9 #include "base/synchronization/lock.h" | |
| 10 #include "base/trace_event/memory_dump_provider.h" | |
| 11 | |
| 12 namespace base { | |
| 13 | |
| 14 namespace trace_event { | |
| 15 class ProcessMemoryDump; | |
| 16 } | |
| 17 | |
| 18 // SharedMemoryTracker tracks shared memory usage. | |
| 19 class BASE_EXPORT SharedMemoryTracker | |
| 20 : public base::trace_event::MemoryDumpProvider { | |
| 21 public: | |
| 22 // Returns a singleton instance. | |
| 23 static SharedMemoryTracker* GetInstance(); | |
| 24 | |
| 25 // Records shared memory usage on mapping. | |
| 26 void IncrementMemoryUsage(const SharedMemory& shared_memory); | |
| 27 | |
| 28 // Records shared memory usage on unmapping. | |
| 29 void DecrementMemoryUsage(const SharedMemory& shared_memory); | |
| 30 | |
| 31 private: | |
| 32 struct Usage { | |
| 33 Usage(); | |
| 34 Usage(const Usage& rhs); | |
| 35 ~Usage(); | |
| 36 SharedMemory::UniqueId unique_id; | |
| 37 size_t size; | |
| 38 }; | |
| 39 | |
| 40 SharedMemoryTracker(); | |
| 41 ~SharedMemoryTracker() override; | |
| 42 | |
| 43 // base::trace_event::MemoryDumpProvider implementation. | |
| 44 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
| 45 base::trace_event::ProcessMemoryDump* pmd) override; | |
| 46 | |
| 47 Lock lock_; | |
|
danakj
2017/03/06 16:06:04
Can you name this usages_lock_? And/or add a comme
hajimehoshi
2017/03/07 06:22:34
Done.
| |
| 48 std::unordered_map<const SharedMemory*, Usage> usages_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker); | |
| 51 }; | |
| 52 | |
| 53 } // namespace base | |
| 54 | |
| 55 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ | |
| OLD | NEW |