mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 19:21:30 +00:00
[Fuchsia] Grab the number of malloc'd bytes from jemalloc
This allows us to report the "native heap memory" value in the Observatory for VMs running on Fuchsia. This change also renames the flag --enable-malloc-hooks to --profiler-native-memory to better reflect what the flag does. (In the future we may also want to rename --profiler to --profiler-cpu.) R=rmacnak@google.com Review-Url: https://codereview.chromium.org/2829833003 .
This commit is contained in:
parent
746fd35307
commit
135b1907ee
|
@ -135,6 +135,11 @@ config("dart_config") {
|
|||
include_dirs += [ "../third_party/tcmalloc/gperftools/src" ]
|
||||
}
|
||||
|
||||
if (defined(is_fuchsia) && is_fuchsia) {
|
||||
defines += [ "DART_USE_JEMALLOC" ]
|
||||
include_dirs += [ "//magenta/third_party/ulib/jemalloc/include" ]
|
||||
}
|
||||
|
||||
if (!is_win) {
|
||||
cflags = [
|
||||
"-Werror",
|
||||
|
|
|
@ -75,9 +75,6 @@
|
|||
"Emit DWARF line number and inlining info" \
|
||||
"in dylib snapshots and don't symbolize stack traces.") \
|
||||
R(enable_asserts, false, bool, false, "Enable assert statements.") \
|
||||
R(enable_malloc_hooks, false, bool, false, \
|
||||
"Enable native memory statistic collection. Enabled by default in Debug " \
|
||||
"mode") \
|
||||
C(enable_mirrors, false, false, bool, true, \
|
||||
"Disable to make importing dart:mirrors an error.") \
|
||||
R(enable_type_checks, false, bool, false, "Enable type checks.") \
|
||||
|
@ -145,6 +142,8 @@
|
|||
"Print variable descriptors in disassembly.") \
|
||||
R(profiler, false, bool, !USING_DBC && !USING_FUCHSIA, \
|
||||
"Enable the profiler.") \
|
||||
R(profiler_native_memory, false, bool, false, \
|
||||
"Enable native memory statistic collection.") \
|
||||
P(reorder_basic_blocks, bool, true, "Reorder basic blocks") \
|
||||
C(causal_async_stacks, false, false, bool, true, "Improved async stacks") \
|
||||
C(stress_async_stacks, false, false, bool, false, \
|
||||
|
|
90
runtime/vm/malloc_hooks_jemalloc.cc
Normal file
90
runtime/vm/malloc_hooks_jemalloc.cc
Normal file
|
@ -0,0 +1,90 @@
|
|||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#include "platform/globals.h"
|
||||
#if defined(DART_USE_JEMALLOC) && !defined(PRODUCT) && !defined(TARGET_ARCH_DBC)
|
||||
|
||||
#include "vm/malloc_hooks.h"
|
||||
|
||||
#include <jemalloc/jemalloc.h>
|
||||
|
||||
#include "vm/json_stream.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
void MallocHooks::InitOnce() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
||||
void MallocHooks::TearDown() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
||||
void MallocHooks::PrintToJSONObject(JSONObject* jsobj) {
|
||||
// Here, we ignore the value of FLAG_profiler_native_memory because we can
|
||||
// gather this information cheaply without hooking into every call to the
|
||||
// malloc library.
|
||||
jsobj->AddProperty("_heapAllocatedMemoryUsage",
|
||||
heap_allocated_memory_in_bytes());
|
||||
jsobj->AddProperty("_heapAllocationCount", allocation_count());
|
||||
}
|
||||
|
||||
|
||||
intptr_t MallocHooks::heap_allocated_memory_in_bytes() {
|
||||
uint64_t epoch = 1;
|
||||
size_t epoch_sz = sizeof(epoch);
|
||||
int result = mallctl("epoch", &epoch, &epoch_sz, &epoch, epoch_sz);
|
||||
if (result != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
intptr_t allocated;
|
||||
size_t allocated_sz = sizeof(allocated);
|
||||
result = mallctl("stats.allocated", &allocated, &allocated_sz, NULL, 0);
|
||||
if (result != 0) {
|
||||
return 0;
|
||||
}
|
||||
return allocated;
|
||||
}
|
||||
|
||||
|
||||
intptr_t MallocHooks::allocation_count() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool MallocHooks::ProfilingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MallocHooks::stack_trace_collection_enabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void MallocHooks::set_stack_trace_collection_enabled(bool enabled) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
||||
void MallocHooks::ResetStats() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
||||
bool MallocHooks::Active() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Sample* MallocHooks::GetSample(const void* ptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // defined(DART_USE_JEMALLOC) && ...
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
#include "platform/globals.h"
|
||||
|
||||
#if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && \
|
||||
!defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA)
|
||||
#if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && !defined(TARGET_ARCH_DBC)
|
||||
|
||||
#include "vm/malloc_hooks.h"
|
||||
|
||||
|
@ -262,7 +261,7 @@ void MallocHooksState::TearDown() {
|
|||
|
||||
|
||||
void MallocHooks::InitOnce() {
|
||||
if (!FLAG_enable_malloc_hooks || MallocHooks::Active()) {
|
||||
if (!FLAG_profiler_native_memory || MallocHooks::Active()) {
|
||||
return;
|
||||
}
|
||||
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
|
||||
|
@ -281,7 +280,7 @@ void MallocHooks::InitOnce() {
|
|||
|
||||
|
||||
void MallocHooks::TearDown() {
|
||||
if (!FLAG_enable_malloc_hooks || !MallocHooks::Active()) {
|
||||
if (!FLAG_profiler_native_memory || !MallocHooks::Active()) {
|
||||
return;
|
||||
}
|
||||
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
|
||||
|
@ -319,7 +318,7 @@ void MallocHooks::set_stack_trace_collection_enabled(bool enabled) {
|
|||
|
||||
|
||||
void MallocHooks::ResetStats() {
|
||||
if (!FLAG_enable_malloc_hooks) {
|
||||
if (!FLAG_profiler_native_memory) {
|
||||
return;
|
||||
}
|
||||
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
|
||||
|
@ -331,7 +330,7 @@ void MallocHooks::ResetStats() {
|
|||
|
||||
|
||||
bool MallocHooks::Active() {
|
||||
if (!FLAG_enable_malloc_hooks) {
|
||||
if (!FLAG_profiler_native_memory) {
|
||||
return false;
|
||||
}
|
||||
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
|
||||
|
@ -342,7 +341,7 @@ bool MallocHooks::Active() {
|
|||
|
||||
|
||||
void MallocHooks::PrintToJSONObject(JSONObject* jsobj) {
|
||||
if (!FLAG_enable_malloc_hooks) {
|
||||
if (!FLAG_profiler_native_memory) {
|
||||
return;
|
||||
}
|
||||
intptr_t allocated_memory = 0;
|
||||
|
@ -368,7 +367,7 @@ void MallocHooks::PrintToJSONObject(JSONObject* jsobj) {
|
|||
|
||||
|
||||
intptr_t MallocHooks::allocation_count() {
|
||||
if (!FLAG_enable_malloc_hooks) {
|
||||
if (!FLAG_profiler_native_memory) {
|
||||
return 0;
|
||||
}
|
||||
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
|
||||
|
@ -378,7 +377,7 @@ intptr_t MallocHooks::allocation_count() {
|
|||
|
||||
|
||||
intptr_t MallocHooks::heap_allocated_memory_in_bytes() {
|
||||
if (!FLAG_enable_malloc_hooks) {
|
||||
if (!FLAG_profiler_native_memory) {
|
||||
return 0;
|
||||
}
|
||||
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
#include "platform/globals.h"
|
||||
|
||||
#if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && \
|
||||
!defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA)
|
||||
#if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && !defined(TARGET_ARCH_DBC)
|
||||
|
||||
#include "platform/assert.h"
|
||||
#include "vm/globals.h"
|
||||
|
@ -28,8 +27,8 @@ static void MallocHookTestBufferInitializer(volatile char* buffer,
|
|||
|
||||
|
||||
UNIT_TEST_CASE(BasicMallocHookTest) {
|
||||
bool enable_malloc_hooks_saved = FLAG_enable_malloc_hooks;
|
||||
FLAG_enable_malloc_hooks = true;
|
||||
bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
|
||||
FLAG_profiler_native_memory = true;
|
||||
|
||||
MallocHooks::InitOnce();
|
||||
MallocHooks::ResetStats();
|
||||
|
@ -48,13 +47,13 @@ UNIT_TEST_CASE(BasicMallocHookTest) {
|
|||
EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes());
|
||||
MallocHooks::TearDown();
|
||||
|
||||
FLAG_enable_malloc_hooks = enable_malloc_hooks_saved;
|
||||
FLAG_profiler_native_memory = enable_malloc_hooks_saved;
|
||||
}
|
||||
|
||||
|
||||
UNIT_TEST_CASE(FreeUnseenMemoryMallocHookTest) {
|
||||
bool enable_malloc_hooks_saved = FLAG_enable_malloc_hooks;
|
||||
FLAG_enable_malloc_hooks = true;
|
||||
bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
|
||||
FLAG_profiler_native_memory = true;
|
||||
|
||||
MallocHooks::InitOnce();
|
||||
const intptr_t pre_hook_buffer_size = 3;
|
||||
|
@ -84,13 +83,13 @@ UNIT_TEST_CASE(FreeUnseenMemoryMallocHookTest) {
|
|||
EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes());
|
||||
MallocHooks::TearDown();
|
||||
|
||||
FLAG_enable_malloc_hooks = enable_malloc_hooks_saved;
|
||||
FLAG_profiler_native_memory = enable_malloc_hooks_saved;
|
||||
}
|
||||
|
||||
|
||||
VM_UNIT_TEST_CASE(StackTraceMallocHookSimpleTest) {
|
||||
bool enable_malloc_hooks_saved = FLAG_enable_malloc_hooks;
|
||||
FLAG_enable_malloc_hooks = true;
|
||||
bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
|
||||
FLAG_profiler_native_memory = true;
|
||||
|
||||
MallocHooks::InitOnce();
|
||||
MallocHooks::ResetStats();
|
||||
|
@ -108,7 +107,7 @@ VM_UNIT_TEST_CASE(StackTraceMallocHookSimpleTest) {
|
|||
EXPECT(sample == NULL);
|
||||
MallocHooks::TearDown();
|
||||
MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved);
|
||||
FLAG_enable_malloc_hooks = enable_malloc_hooks_saved;
|
||||
FLAG_profiler_native_memory = enable_malloc_hooks_saved;
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,8 +119,8 @@ static char* DART_NOINLINE StackTraceLengthHelper(uintptr_t* end_address) {
|
|||
|
||||
|
||||
VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) {
|
||||
bool enable_malloc_hooks_saved = FLAG_enable_malloc_hooks;
|
||||
FLAG_enable_malloc_hooks = true;
|
||||
bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
|
||||
FLAG_profiler_native_memory = true;
|
||||
|
||||
uintptr_t test_start_address =
|
||||
reinterpret_cast<uintptr_t>(Dart_TestStackTraceMallocHookLengthTest);
|
||||
|
@ -169,13 +168,13 @@ VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) {
|
|||
free(var);
|
||||
MallocHooks::TearDown();
|
||||
MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved);
|
||||
FLAG_enable_malloc_hooks = enable_malloc_hooks_saved;
|
||||
FLAG_profiler_native_memory = enable_malloc_hooks_saved;
|
||||
}
|
||||
|
||||
|
||||
ISOLATE_UNIT_TEST_CASE(StackTraceMallocHookSimpleJSONTest) {
|
||||
bool enable_malloc_hooks_saved = FLAG_enable_malloc_hooks;
|
||||
FLAG_enable_malloc_hooks = true;
|
||||
bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
|
||||
FLAG_profiler_native_memory = true;
|
||||
|
||||
MallocHooks::InitOnce();
|
||||
MallocHooks::ResetStats();
|
||||
|
@ -205,7 +204,7 @@ ISOLATE_UNIT_TEST_CASE(StackTraceMallocHookSimpleJSONTest) {
|
|||
free(var);
|
||||
MallocHooks::TearDown();
|
||||
MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved);
|
||||
FLAG_enable_malloc_hooks = enable_malloc_hooks_saved;
|
||||
FLAG_profiler_native_memory = enable_malloc_hooks_saved;
|
||||
}
|
||||
|
||||
}; // namespace dart
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
#include "platform/globals.h"
|
||||
|
||||
#if !defined(DART_USE_TCMALLOC) || defined(PRODUCT) || \
|
||||
defined(TARGET_ARCH_DBC) || defined(HOST_OS_FUCHSIA)
|
||||
#if (!defined(DART_USE_TCMALLOC) && !defined(DART_USE_JEMALLOC)) || \
|
||||
defined(PRODUCT) || defined(TARGET_ARCH_DBC)
|
||||
|
||||
#include "vm/malloc_hooks.h"
|
||||
|
||||
|
@ -67,5 +67,4 @@ intptr_t MallocHooks::heap_allocated_memory_in_bytes() {
|
|||
|
||||
} // namespace dart
|
||||
|
||||
#endif // !defined(DART_USE_TCMALLOC) || defined(PRODUCT) ||
|
||||
// defined(TARGET_ARCH_DBC) || defined(HOST_OS_FUCHSIA)
|
||||
#endif // !defined(DART_USE_TCMALLOC) && ...
|
||||
|
|
|
@ -326,8 +326,8 @@ DART_NOINLINE static void NativeAllocationSampleHelper(char** result) {
|
|||
|
||||
|
||||
ISOLATE_UNIT_TEST_CASE(Profiler_NativeAllocation) {
|
||||
bool enable_malloc_hooks_saved = FLAG_enable_malloc_hooks;
|
||||
FLAG_enable_malloc_hooks = true;
|
||||
bool enable_malloc_hooks_saved = FLAG_profiler_native_memory;
|
||||
FLAG_profiler_native_memory = true;
|
||||
|
||||
MallocHooks::InitOnce();
|
||||
MallocHooks::ResetStats();
|
||||
|
@ -522,7 +522,7 @@ ISOLATE_UNIT_TEST_CASE(Profiler_NativeAllocation) {
|
|||
MallocHooks::set_stack_trace_collection_enabled(
|
||||
stack_trace_collection_enabled);
|
||||
MallocHooks::TearDown();
|
||||
FLAG_enable_malloc_hooks = enable_malloc_hooks_saved;
|
||||
FLAG_profiler_native_memory = enable_malloc_hooks_saved;
|
||||
}
|
||||
#endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) &&
|
||||
// !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA)
|
||||
|
|
|
@ -287,7 +287,8 @@
|
|||
'longjump.cc',
|
||||
'longjump.h',
|
||||
'longjump_test.cc',
|
||||
'malloc_hooks.cc',
|
||||
'malloc_hooks_jemalloc.cc',
|
||||
'malloc_hooks_tcmalloc.cc',
|
||||
'malloc_hooks_arm.cc',
|
||||
'malloc_hooks_arm64.cc',
|
||||
'malloc_hooks_ia32.cc',
|
||||
|
|
Loading…
Reference in a new issue