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

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

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Address on danakj@'s review Created 3 years, 9 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
(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/lazy_instance.h"
9 #include "base/synchronization/lock.h"
10 #include "base/trace_event/memory_dump_provider.h"
11
12 namespace base {
13
14 class SharedMemory;
15
16 namespace trace_event {
17 class ProcessMemoryDump;
18 }
19
20 // SharedMemoryTracker tracks shared memory usage.
21 class BASE_EXPORT SharedMemoryTracker
22 : public base::trace_event::MemoryDumpProvider {
23 public:
24 // Returns a singleton instance.
25 static SharedMemoryTracker* GetInstance();
26
27 // Records shared memory usage on mapping.
28 void IncrementMemoryUsage(const SharedMemory& shared_memory);
29
30 // Records shared memory usage on unmapping.
31 void DecrementMemoryUsage(const SharedMemory& shared_memory);
32
33 private:
34 friend base::DefaultLazyInstanceTraits<SharedMemoryTracker>;
35
36 SharedMemoryTracker();
37 ~SharedMemoryTracker() override;
38
39 // base::trace_event::MemoryDumpProvider implementation.
40 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
41 base::trace_event::ProcessMemoryDump* pmd) override;
42
43 base::Lock lock_;
44 std::unordered_map<const SharedMemory*, size_t> usages_;
45
46 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
47 };
48
49 } // namespace base
50
51 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698