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

Unified Diff: base/memory/shared_memory_handle_posix.cc

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_handle_posix.cc
diff --git a/base/memory/shared_memory_handle_posix.cc b/base/memory/shared_memory_handle_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e4e32107db3ef3ec2310a18ea8de6d08a4a483f2
--- /dev/null
+++ b/base/memory/shared_memory_handle_posix.cc
@@ -0,0 +1,33 @@
+// 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.
+
+#include "base/memory/shared_memory_handle.h"
+
+#include <sys/stat.h>
+
+#include "base/strings/stringprintf.h"
+
+namespace base {
+
+#if !(defined(OS_MACOSX) && !defined(OS_IOS))
+
+bool GetIDFromSharedMemoryHandle(const SharedMemoryHandle& handle,
+ SharedMemoryHandleID* id) {
+ // Get file name?
+ struct stat file_stat;
+ if (fstat(static_cast<int>(handle.fd), &file_stat) != 0)
Primiano Tucci (use gerrit) 2017/01/20 16:34:52 I checked the sandbox and fstat seems allowed (goo
hajimehoshi 2017/01/23 11:59:09 Thank you!
+ return false;
+ id->device_id = file_stat.st_dev;
+ id->file_id = file_stat.st_ino;
+ return true;
+}
+
+std::string GetSharedMemoryHandleIDString(const SharedMemoryHandleID& id) {
+ return base::StringPrintf("%lld.%lld", static_cast<long long>(id.device_id),
+ static_cast<long long>(id.file_id));
+}
+
+#endif
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698