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

Unified Diff: base/memory/shared_memory_tracker.h

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: Implement buckets 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 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..e867f8b7fd5b624b99eefe268f6506490d5227a7
--- /dev/null
+++ b/base/memory/shared_memory_tracker.h
@@ -0,0 +1,66 @@
+// 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/atomicops.h"
+#include "base/memory/shared_memory_handle.h"
+#include "base/memory/singleton.h"
+#include "base/trace_event/memory_dump_provider.h"
+
+namespace base {
+
+class SharedMemory;
+
+namespace trace_event {
+
+class MemoryAllocatorDumpGuid;
+class ProcessMemoryDump;
+}
+
+class BASE_EXPORT SharedMemoryTracker
+ : public base::trace_event::MemoryDumpProvider {
+ public:
+ // Returns a singleton instance.
+ static SharedMemoryTracker* GetInstance();
+
+ static bool AddOwnershipEdgeToSharedGlobalDump(
+ trace_event::ProcessMemoryDump* pmd,
+ const trace_event::MemoryAllocatorDumpGuid& source,
+ const base::SharedMemoryHandle& shared_memory_handle,
+ size_t mapped_size);
+
+ // base::trace_event::MemoryDumpProvider implementation.
+ bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) override;
+
+ bool IncrementMemoryUsage(const SharedMemory& shared_memory);
+ bool DecrementMemoryUsage(const SharedMemory& shared_memory);
+
+ private:
+ struct TrackerBucket {
+ TrackerBucket();
+ ~TrackerBucket();
+ base::Lock lock;
+ // The first map's key is a device ID and the second map's key is a file
+ // ID. See SharedMemoryHandleID struct.
+ std::unordered_map<int64_t, std::unordered_map<int64_t, size_t>> usage;
Primiano Tucci (use gerrit) 2017/01/20 16:34:52 I don't think you should expose device id and file
hajimehoshi 2017/01/23 11:59:09 Done.
+ };
+
+ friend struct base::DefaultSingletonTraits<SharedMemoryTracker>;
+
+ static const int kTrackerBucketNum = 1024;
+
+ SharedMemoryTracker();
+ ~SharedMemoryTracker() override;
+
+ TrackerBucket buckets_[kTrackerBucketNum];
+
+ DISALLOW_COPY_AND_ASSIGN(SharedMemoryTracker);
+};
+
+} // namespace base
+
+#endif // BASE_MEMORY_SHARED_MEMORY_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698