summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorssid <ssid@chromium.org>2015-11-07 08:15:07 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-07 16:16:01 +0000
commit3aa02fe74186a07f11dae868b659db0ecf0d4013 (patch)
tree4aa4ffcaf99f2bed78fff5018a8e6c30723f40b3
parentb5af4352f96d0e60a033e8a70c9ad5675adf9e2c (diff)
downloadchromium_src-3aa02fe74186a07f11dae868b659db0ecf0d4013.zip
chromium_src-3aa02fe74186a07f11dae868b659db0ecf0d4013.tar.gz
chromium_src-3aa02fe74186a07f11dae868b659db0ecf0d4013.tar.bz2
[tracing] Add malloc dump provider for mac
The malloc.h provides malloc_zone_statistics, which provides the size allocated by malloc. This CL adds these numbers to tracing. BUG=466141 Review URL: https://codereview.chromium.org/1431903003 Cr-Commit-Position: refs/heads/master@{#358530}
-rw-r--r--base/trace_event/BUILD.gn7
-rw-r--r--base/trace_event/malloc_dump_provider.cc19
-rw-r--r--base/trace_event/malloc_dump_provider.h7
-rw-r--r--base/trace_event/memory_dump_manager.cc9
-rw-r--r--base/trace_event/trace_event.gypi8
5 files changed, 38 insertions, 12 deletions
diff --git a/base/trace_event/BUILD.gn b/base/trace_event/BUILD.gn
index 862b450..70ebeaa 100644
--- a/base/trace_event/BUILD.gn
+++ b/base/trace_event/BUILD.gn
@@ -71,14 +71,17 @@ source_set("trace_event") {
]
}
- if (is_linux || is_android) {
+ if (is_linux || is_android || is_mac) {
sources += [
"malloc_dump_provider.cc",
"malloc_dump_provider.h",
- "process_memory_maps_dump_provider.cc",
]
}
+ if (is_linux || is_android) {
+ sources += [ "process_memory_maps_dump_provider.cc" ]
+ }
+
configs += [ "//base:base_implementation" ]
deps = [
diff --git a/base/trace_event/malloc_dump_provider.cc b/base/trace_event/malloc_dump_provider.cc
index 914c684..5279ab0 100644
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -4,7 +4,11 @@
#include "base/trace_event/malloc_dump_provider.h"
+#if defined(OS_MACOSX)
+#include <malloc/malloc.h>
+#else
#include <malloc.h>
+#endif
#include "base/allocator/allocator_extension_thunks.h"
#include "base/trace_event/process_memory_dump.h"
@@ -21,11 +25,9 @@ MallocDumpProvider* MallocDumpProvider::GetInstance() {
LeakySingletonTraits<MallocDumpProvider>>::get();
}
-MallocDumpProvider::MallocDumpProvider() {
-}
+MallocDumpProvider::MallocDumpProvider() {}
-MallocDumpProvider::~MallocDumpProvider() {
-}
+MallocDumpProvider::~MallocDumpProvider() {}
// Called at trace dump point time. Creates a snapshot the memory counters for
// the current process.
@@ -34,7 +36,13 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
size_t total_virtual_size = 0;
size_t resident_size = 0;
size_t allocated_objects_size = 0;
-
+#if defined(OS_MACOSX) || defined(OS_IOS)
+ malloc_statistics_t stats = {0};
+ malloc_zone_statistics(nullptr, &stats);
+ total_virtual_size = stats.size_allocated;
+ resident_size = stats.size_in_use;
+ allocated_objects_size = stats.size_in_use;
+#else
allocator::thunks::GetNumericPropertyFunction get_property_function =
allocator::thunks::GetGetNumericPropertyFunction();
if (get_property_function) {
@@ -58,6 +66,7 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
resident_size = info.uordblks;
allocated_objects_size = info.uordblks;
}
+#endif
MemoryAllocatorDump* outer_dump = pmd->CreateAllocatorDump("malloc");
outer_dump->AddScalar("virtual_size", MemoryAllocatorDump::kUnitsBytes,
diff --git a/base/trace_event/malloc_dump_provider.h b/base/trace_event/malloc_dump_provider.h
index f351999..f463d0a 100644
--- a/base/trace_event/malloc_dump_provider.h
+++ b/base/trace_event/malloc_dump_provider.h
@@ -7,8 +7,15 @@
#include <istream>
+#include "base/macros.h"
#include "base/memory/singleton.h"
#include "base/trace_event/memory_dump_provider.h"
+#include "build/build_config.h"
+
+#if defined(OS_LINUX) || defined(OS_ANDROID) || \
+ (defined(OS_MACOXS) && !defined(OS_IOS))
+#define SUPPORTS_MALLOC_MEMORY_TRACING
+#endif
namespace base {
namespace trace_event {
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc
index eec2ff3..43c784b 100644
--- a/base/trace_event/memory_dump_manager.cc
+++ b/base/trace_event/memory_dump_manager.cc
@@ -12,6 +12,7 @@
#include "base/compiler_specific.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
+#include "base/trace_event/malloc_dump_provider.h"
#include "base/trace_event/memory_dump_provider.h"
#include "base/trace_event/memory_dump_session_state.h"
#include "base/trace_event/memory_profiler_allocation_context.h"
@@ -24,7 +25,6 @@
#endif
#if defined(OS_LINUX) || defined(OS_ANDROID)
-#include "base/trace_event/malloc_dump_provider.h"
#include "base/trace_event/process_memory_maps_dump_provider.h"
#endif
@@ -96,7 +96,7 @@ const uint64_t MemoryDumpManager::kInvalidTracingProcessId = 0;
// static
const char* const MemoryDumpManager::kSystemAllocatorPoolName =
-#if defined(OS_LINUX) || defined(OS_ANDROID)
+#if defined(SUPPORTS_MALLOC_MEMORY_TRACING)
MallocDumpProvider::kAllocatedObjects;
#elif defined(OS_WIN)
WinHeapDumpProvider::kAllocatedObjects;
@@ -155,10 +155,13 @@ void MemoryDumpManager::Initialize(MemoryDumpManagerDelegate* delegate,
"ProcessMemoryTotals", nullptr);
#endif
+#if defined(SUPPORTS_MALLOC_MEMORY_TRACING)
+ RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr);
+#endif
+
#if defined(OS_LINUX) || defined(OS_ANDROID)
RegisterDumpProvider(ProcessMemoryMapsDumpProvider::GetInstance(),
"ProcessMemoryMaps", nullptr);
- RegisterDumpProvider(MallocDumpProvider::GetInstance(), "Malloc", nullptr);
#endif
#if defined(OS_ANDROID)
diff --git a/base/trace_event/trace_event.gypi b/base/trace_event/trace_event.gypi
index db87e4b..4713311 100644
--- a/base/trace_event/trace_event.gypi
+++ b/base/trace_event/trace_event.gypi
@@ -81,10 +81,14 @@
'trace_event/winheap_dump_provider_win_unittest.cc',
],
'conditions': [
+ ['OS == "linux" or OS=="android" or OS=="mac"', {
+ 'trace_event_sources': [
+ 'trace_event/malloc_dump_provider.cc',
+ 'trace_event/malloc_dump_provider.h',
+ ],
+ }],
['OS == "linux" or OS == "android"', {
'trace_event_sources': [
- 'trace_event/malloc_dump_provider.cc',
- 'trace_event/malloc_dump_provider.h',
'trace_event/process_memory_maps_dump_provider.cc',
],
'trace_event_test_sources' : [