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

Unified Diff: base/process/process_metrics_posix.cc

Issue 2925073002: Move malloc/partition_alloc memory usage functions to base (Closed)
Patch Set: Moved to ProcessMetrics method, etc Created 3 years, 6 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
« no previous file with comments | « base/process/process_metrics.h ('k') | base/process/process_metrics_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_posix.cc
diff --git a/base/process/process_metrics_posix.cc b/base/process/process_metrics_posix.cc
index a4445e8bc2e80ff6fdac1e04074224298ba422ca..677e26d12148d084f21a2906837e939f82be4664 100644
--- a/base/process/process_metrics_posix.cc
+++ b/base/process/process_metrics_posix.cc
@@ -14,6 +14,12 @@
#include "base/logging.h"
#include "build/build_config.h"
+#if defined(OS_MACOSX)
+#include <malloc/malloc.h>
+#else
+#include <malloc.h>
+#endif
+
namespace base {
int64_t TimeValToMicroseconds(const struct timeval& tv) {
@@ -83,4 +89,19 @@ size_t GetPageSize() {
return getpagesize();
}
+size_t ProcessMetrics::GetMallocUsage() {
+#if defined(OS_MACOSX) || defined(OS_IOS)
+ malloc_statistics_t stats = {0};
+ malloc_zone_statistics(nullptr, &stats);
+ return stats.size_in_use;
+#elif defined(OS_LINUX) || defined(OS_ANDROID)
+ struct mallinfo minfo = mallinfo();
+#if defined(USE_TCMALLOC)
+ return minfo.uordblks;
+#else
+ return minfo.hblkhd + minfo.arena;
+#endif
+#endif
+}
+
} // namespace base
« no previous file with comments | « base/process/process_metrics.h ('k') | base/process/process_metrics_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698