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

Unified Diff: base/memory/shared_memory_tracker.h

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Fix PRESUBMIT.py 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 side-by-side diff with in-line comments
Download patch
Index: base/memory/shared_memory_tracker.h
diff --git a/base/memory/shared_memory_tracker.h b/base/memory/shared_memory_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..d4503b1fae6892d10705f6e2616a0e6cfe7f3629
--- /dev/null
+++ b/base/memory/shared_memory_tracker.h
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
+#define BASE_MEMORY_SHARED_MEMORY_TRACKER_H_
+
+#include "base/memory/shared_memory.h"
+#include "base/synchronization/lock.h"
+#include "base/trace_event/memory_dump_provider.h"
+
+namespace base {
+
+namespace trace_event {
+class ProcessMemoryDump;
+}
+
+// SharedMemoryTracker tracks shared memory usage.
+class BASE_EXPORT SharedMemoryTracker
+ : public base::trace_event::MemoryDumpProvider {
+ public:
+ // Returns a singleton instance.
+ static SharedMemoryTracker* GetInstance();
+
+ // Records shared memory usage on mapping.
+ void IncrementMemoryUsage(const SharedMemory& shared_memory);
+
+ // Records shared memory usage on unmapping.
+ void DecrementMemoryUsage(const SharedMemory& shared_memory);
+
+ private:
+ struct Usage {
+ Usage();
+ Usage(const Usage& rhs);
+ ~Usage();
+ SharedMemory::UniqueId unique_id;
+ size_t size;
+ };
+
+ SharedMemoryTracker();
+ ~SharedMemoryTracker() override;
+
+ // base::trace_event::MemoryDumpProvider implementation.
+ bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) override;
+
+ 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.
+ std::unordered_map<const SharedMemory*, Usage> usages_;
+
+ DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
+};
+
+} // namespace base
+
+#endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698