Skip to content

Commit

Permalink
Revert "[vm, service] Gather used and capacity from various mallocs."
Browse files Browse the repository at this point in the history
This reverts commit 84f9eee.

Reason for revert: Weak linking does not work on iOS

Original change's description:
> [vm, service] Gather used and capacity from various mallocs.
> 
> Change-Id: I9d397b3b865a804252d1adc90c03a369bf88aff3
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159186
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

TBR=bkonyi@google.com,rmacnak@google.com

Change-Id: I6c9e17783ee5a3296296677cad11d036aa8fa060
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160401
Reviewed-by: Ryan Macnak <rmacnak@google.com>
  • Loading branch information
rmacnak-google committed Aug 26, 2020
1 parent 569fc70 commit d373ff5
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 208 deletions.
30 changes: 9 additions & 21 deletions runtime/observatory/lib/src/elements/vm_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,39 +174,27 @@ class VMViewElement extends CustomElement implements Renderable {
..children = <Element>[
new DivElement()
..classes = ['memberName']
..text = 'malloc used memory',
..text = 'malloc memory',
new DivElement()
..classes = ['memberValue']
..text = _vm.mallocUsed != null
? Utils.formatSize(_vm.mallocUsed)
..text = _vm.heapAllocatedMemoryUsage != null
? Utils.formatSize(_vm.heapAllocatedMemoryUsage)
: 'unavailable'
..title =
_vm.mallocUsed != null ? '${_vm.mallocUsed} bytes' : null
],
new DivElement()
..classes = ['memberItem']
..children = <Element>[
new DivElement()
..classes = ['memberName']
..text = 'malloc capacity memory',
new DivElement()
..classes = ['memberValue']
..text = _vm.mallocCapacity != null
? Utils.formatSize(_vm.mallocCapacity)
: 'unavailable'
..title = _vm.mallocCapacity != null
? '${_vm.mallocCapacity} bytes'
..title = _vm.heapAllocatedMemoryUsage != null
? '${_vm.heapAllocatedMemoryUsage} bytes'
: null
],
new DivElement()
..classes = ['memberItem']
..children = <Element>[
new DivElement()
..classes = ['memberName']
..text = 'malloc implementation',
..text = 'malloc allocation count',
new DivElement()
..classes = ['memberValue']
..text = _vm.mallocImplementation
..text = _vm.heapAllocationCount != null
? '${_vm.heapAllocationCount}'
: 'unavailable'
],
new DivElement()
..classes = ['memberItem']
Expand Down
7 changes: 4 additions & 3 deletions runtime/observatory/lib/src/models/objects/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ abstract class VM implements VMRef {
int get pid;

/// The current amount of native heap allocated memory within the VM.
int get mallocUsed;
int get mallocCapacity;
String get mallocImplementation;
int get heapAllocatedMemoryUsage;

/// The current number of allocations on the native heap within the VM.
int get heapAllocationCount;

int get currentMemory;
int get maxRSS;
Expand Down
10 changes: 4 additions & 6 deletions runtime/observatory/lib/src/service/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,8 @@ abstract class VM extends ServiceObjectOwner implements M.VM {
bool typeChecksEnabled = false;
int nativeZoneMemoryUsage = 0;
int pid = 0;
int mallocUsed = 0;
int mallocCapacity = 0;
String mallocImplementation = 'unknown';
int heapAllocatedMemoryUsage = 0;
int heapAllocationCount = 0;
int currentMemory;
int maxRSS;
int currentRSS;
Expand Down Expand Up @@ -1048,9 +1047,8 @@ abstract class VM extends ServiceObjectOwner implements M.VM {
nativeZoneMemoryUsage = map['_nativeZoneMemoryUsage'];
}
pid = map['pid'];
mallocUsed = map['_mallocUsed'];
mallocCapacity = map['_mallocCapacity'];
mallocImplementation = map['_mallocImplementation'];
heapAllocatedMemoryUsage = map['_heapAllocatedMemoryUsage'];
heapAllocationCount = map['_heapAllocationCount'];
embedder = map['_embedder'];
currentMemory = map['_currentMemory'];
maxRSS = map['_maxRSS'];
Expand Down
4 changes: 1 addition & 3 deletions runtime/vm/malloc_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class MallocHooks : public AllStatic {
static void set_stack_trace_collection_enabled(bool enabled);
static void ResetStats();
static bool Active();
static bool GetStats(intptr_t* used,
intptr_t* capacity,
const char** implementation);
static void PrintToJSONObject(JSONObject* jsobj);
static Sample* GetSample(const void* ptr);

static intptr_t allocation_count();
Expand Down
33 changes: 23 additions & 10 deletions runtime/vm/malloc_hooks_tcmalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#include "gperftools/malloc_hook.h"

#include <malloc.h>

#include "platform/assert.h"
#include "vm/hash_map.h"
#include "vm/json_stream.h"
Expand Down Expand Up @@ -336,14 +334,29 @@ bool MallocHooks::Active() {
return MallocHooksState::Active();
}

bool MallocHooks::GetStats(intptr_t* used,
intptr_t* capacity,
const char** implementation) {
struct mallinfo info = mallinfo();
*used = info.uordblks;
*capacity = *used + info.fordblks;
*implementation = "tcmalloc";
return true;
void MallocHooks::PrintToJSONObject(JSONObject* jsobj) {
if (!FLAG_profiler_native_memory) {
return;
}
intptr_t allocated_memory = 0;
intptr_t allocation_count = 0;
bool add_usage = false;
// AddProperty may call malloc which would result in an attempt
// to acquire the lock recursively so we extract the values first
// and then add the JSON properties.
{
MallocLocker ml(MallocHooksState::malloc_hook_mutex(),
MallocHooksState::malloc_hook_mutex_owner());
if (MallocHooksState::Active()) {
allocated_memory = MallocHooksState::heap_allocated_memory_in_bytes();
allocation_count = MallocHooksState::allocation_count();
add_usage = true;
}
}
if (add_usage) {
jsobj->AddProperty("_heapAllocatedMemoryUsage", allocated_memory);
jsobj->AddProperty("_heapAllocationCount", allocation_count);
}
}

intptr_t MallocHooks::allocation_count() {
Expand Down
51 changes: 2 additions & 49 deletions runtime/vm/malloc_hooks_unsupported.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@

#include "vm/malloc_hooks.h"

#include "vm/json_stream.h"

#if defined(HOST_OS_LINUX) || defined(HOST_OS_ANDROID)
#include <malloc.h>
#elif defined(HOST_OS_MACOS)
#include <malloc/malloc.h>
#endif

#if !defined(HOST_OS_WINDOWS)
extern "C" {
__attribute__((weak)) uintptr_t __sanitizer_get_current_allocated_bytes();
__attribute__((weak)) uintptr_t __sanitizer_get_heap_size();
__attribute__((weak)) int __sanitizer_install_malloc_and_free_hooks(
void (*malloc_hook)(const void*, uintptr_t),
void (*free_hook)(const void*));
}
#endif

namespace dart {

void MallocHooks::Init() {
Expand Down Expand Up @@ -56,37 +38,8 @@ bool MallocHooks::Active() {
return false;
}

bool MallocHooks::GetStats(intptr_t* used,
intptr_t* capacity,
const char** implementation) {
#if !defined(PRODUCT)
#if !defined(HOST_OS_WINDOWS)
if (__sanitizer_get_current_allocated_bytes != nullptr &&
__sanitizer_get_heap_size != nullptr) {
*used = __sanitizer_get_current_allocated_bytes();
*capacity = __sanitizer_get_heap_size();
*implementation = "scudo";
return true;
}
#endif
#if defined(HOST_OS_LINUX) || defined(HOST_OS_ANDROID)
struct mallinfo info = mallinfo();
*used = info.uordblks;
*capacity = *used + info.fordblks;
*implementation = "unknown";
return true;
#elif defined(HOST_OS_MACOS)
struct mstats stats = mstats();
*used = stats.bytes_used;
*capacity = stats.bytes_total;
*implementation = "macos";
return true;
#else
return false;
#endif
#else
return false;
#endif
void MallocHooks::PrintToJSONObject(JSONObject* jsobj) {
// Do nothing.
}

Sample* MallocHooks::GetSample(const void* ptr) {
Expand Down
Loading

0 comments on commit d373ff5

Please sign in to comment.