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

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

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Add comments Created 3 years, 11 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/atomicops.h"
9 #include "base/memory/shared_memory_handle.h"
10 #include "base/memory/singleton.h"
11 #include "base/trace_event/memory_dump_provider.h"
12
13 namespace base {
14
15 class SharedMemory;
16
17 namespace trace_event {
18 class ProcessMemoryDump;
19 }
20
21 // SharedMemoryTracker tracks shared memory usage.
22 class BASE_EXPORT SharedMemoryTracker
23 : public base::trace_event::MemoryDumpProvider {
24 public:
25 // Returns a singleton instance.
26 static SharedMemoryTracker* GetInstance();
27
28 // base::trace_event::MemoryDumpProvider implementation.
29 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
30 base::trace_event::ProcessMemoryDump* pmd) override;
31
32 // Records shared memory usage on mapping.
33 bool IncrementMemoryUsage(const SharedMemory& shared_memory);
34
35 // Records shared memory usage on unmapping.
36 bool DecrementMemoryUsage(const SharedMemory& shared_memory);
37
38 private:
39 // TrackerBucket represents a group of shared memory handle ids and their
40 // usages. Shared memorys are split into these buckets instead of using one
41 // big unordered_map so that locking for exclusive control would occur much
42 // less often.
43 struct TrackerBucket {
44 TrackerBucket();
45 ~TrackerBucket();
46 base::Lock lock;
47 std::unordered_map<SharedMemoryHandleID,
48 size_t,
49 SharedMemoryHandleIDHash,
50 SharedMemoryHandleIDEqual>
51 usages;
52 };
53
54 friend struct base::DefaultSingletonTraits<SharedMemoryTracker>;
55
56 static const int kTrackerBucketNum = 1024;
57
58 SharedMemoryTracker();
59 ~SharedMemoryTracker() override;
60
61 TrackerBucket buckets_[kTrackerBucketNum];
62
63 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
64 };
65
66 } // namespace base
67
68 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698