Index: base/process/process_metrics.cc |
diff --git a/base/process/process_metrics.cc b/base/process/process_metrics.cc |
index f24901c3d997ae7a13848ebe71680c2a6badb0e5..3847f78a5957319159cb6ff08bed01236c2b1f32 100644 |
--- a/base/process/process_metrics.cc |
+++ b/base/process/process_metrics.cc |
@@ -6,10 +6,20 @@ |
#include <utility> |
+#include "base/allocator/partition_allocator/partition_alloc.h" |
#include "base/logging.h" |
#include "base/values.h" |
#include "build/build_config.h" |
+#if defined(OS_MACOSX) |
Primiano Tucci (use gerrit)
2017/06/14 12:10:32
looks like you could split this file in process_me
keishi
2017/06/14 13:21:39
Done.
|
+#include <malloc/malloc.h> |
+#else |
+#include <malloc.h> |
+#endif |
+#if defined(OS_WIN) |
+#include <windows.h> |
+#endif |
+ |
namespace base { |
SystemMemoryInfoKB::SystemMemoryInfoKB() = default; |
@@ -101,4 +111,66 @@ int ProcessMetrics::GetIdleWakeupsPerSecond() { |
} |
#endif // defined(OS_MACOSX) || defined(OS_LINUX) |
+// TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
+// when it is possible to run memory-infra without tracing. |
+size_t GetMallocUsage() { |
+#if defined(OS_WIN) |
+ // Iterate through whichever heap the CRT is using. |
+ HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
+ if (crt_heap == NULL) |
+ return 0; |
+ if (!::HeapLock(crt_heap)) |
+ return 0; |
+ size_t malloc_usage = 0; |
+ PROCESS_HEAP_ENTRY heap_entry; |
+ heap_entry.lpData = NULL; |
+ while (::HeapWalk(crt_heap, &heap_entry) != 0) { |
+ if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) |
+ malloc_usage += heap_entry.cbData; |
+ } |
+ ::HeapUnlock(crt_heap); |
+ return malloc_usage; |
+#elif 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 { |
+ |
+class LightPartitionStatsDumperImpl : public base::PartitionStatsDumper { |
+ public: |
+ LightPartitionStatsDumperImpl() : total_active_bytes_(0) {} |
+ |
+ void PartitionDumpTotals( |
+ const char* partition_name, |
+ const base::PartitionMemoryStats* memory_stats) override { |
+ total_active_bytes_ += memory_stats->total_active_bytes; |
+ } |
+ |
+ void PartitionsDumpBucketStats( |
+ const char* partition_name, |
+ const base::PartitionBucketMemoryStats*) override {} |
+ |
+ size_t TotalActiveBytes() const { return total_active_bytes_; } |
+ |
+ private: |
+ size_t total_active_bytes_; |
+}; |
+ |
+} // namespace |
+ |
+size_t GetPartitionAllocUsage() { |
+ LightPartitionStatsDumperImpl dumper; |
Primiano Tucci (use gerrit)
2017/06/14 12:19:49
also, looks like you should call PartitionDumpTot
keishi
2017/06/14 13:21:39
I forgot to call WTF::Partitions::DumpMemoryStats(
|
+ return dumper.TotalActiveBytes(); |
+} |
+ |
} // namespace base |