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/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); | |
Primiano Tucci (use gerrit)
2017/01/27 20:09:49
why this (and Decrement below) are bool?
- it is n
hajimehoshi
2017/02/07 12:33:44
Done.
| |
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<const SharedMemory*, size_t> usages; | |
48 }; | |
49 | |
50 friend struct base::DefaultSingletonTraits<SharedMemoryTracker>; | |
51 | |
52 // TODO(hajimehoshi): Update this number based on actual performance | |
53 // measurements. | |
54 static const int kTrackerBucketNum = 1024; | |
55 | |
56 SharedMemoryTracker(); | |
57 ~SharedMemoryTracker() override; | |
58 | |
59 TrackerBucket buckets_[kTrackerBucketNum]; | |
Primiano Tucci (use gerrit)
2017/01/27 20:09:49
nit: this should go up to line 55. functions / ct
hajimehoshi
2017/02/07 12:33:44
Done.
| |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker); | |
62 }; | |
63 | |
64 } // namespace base | |
65 | |
66 #endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_ | |
OLD | NEW |