diff options
Diffstat (limited to 'src/malloc_extension.cc')
-rw-r--r-- | src/malloc_extension.cc | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/malloc_extension.cc b/src/malloc_extension.cc index 6e69552..c143f13 100644 --- a/src/malloc_extension.cc +++ b/src/malloc_extension.cc @@ -1,5 +1,4 @@ -// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- -// Copyright (c) 2005, Google Inc. +// Copyright (c) 2012, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -51,7 +50,12 @@ #include "gperftools/malloc_extension.h" #include "gperftools/malloc_extension_c.h" #include "maybe_threads.h" -#include "base/googleinit.h" + +#ifdef USE_TCMALLOC +// Note that malloc_extension can be used without tcmalloc if gperftools' +// heap-profiler is enabled without the tcmalloc memory allocator. +#include "thread_cache.h" +#endif using STL_NAMESPACE::string; using STL_NAMESPACE::vector; @@ -193,37 +197,25 @@ void MallocExtension::GetFreeListSizes( v->clear(); } -size_t MallocExtension::GetThreadCacheSize() { - return 0; -} - -void MallocExtension::MarkThreadTemporarilyIdle() { - // Default implementation does nothing -} - // The current malloc extension object. -static MallocExtension* current_instance; +static pthread_once_t module_init = PTHREAD_ONCE_INIT; +static MallocExtension* current_instance = NULL; static void InitModule() { - if (current_instance != NULL) { - return; - } current_instance = new MallocExtension; #ifndef NO_HEAP_CHECK HeapLeakChecker::IgnoreObject(current_instance); #endif } -REGISTER_MODULE_INITIALIZER(malloc_extension_init, InitModule()) - MallocExtension* MallocExtension::instance() { - InitModule(); + perftools_pthread_once(&module_init, InitModule); return current_instance; } void MallocExtension::Register(MallocExtension* implementation) { - InitModule(); + perftools_pthread_once(&module_init, InitModule); // When running under valgrind, our custom malloc is replaced with // valgrind's one and malloc extensions will not work. (Note: // callers should be responsible for checking that they are the @@ -234,6 +226,17 @@ void MallocExtension::Register(MallocExtension* implementation) { } } +unsigned int MallocExtension::GetBytesAllocatedOnCurrentThread() { + // This function is added in Chromium for profiling. +#ifdef USE_TCMALLOC + // Note that malloc_extension can be used without tcmalloc if gperftools' + // heap-profiler is enabled without the tcmalloc memory allocator. + return tcmalloc::ThreadCache::GetBytesAllocatedOnCurrentThread(); +#else + return 0; +#endif +} + // ----------------------------------------------------------------------- // Heap sampling support // ----------------------------------------------------------------------- @@ -377,8 +380,6 @@ C_SHIM(ReleaseFreeMemory, void, (void), ()); C_SHIM(ReleaseToSystem, void, (size_t num_bytes), (num_bytes)); C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size)); C_SHIM(GetAllocatedSize, size_t, (const void* p), (p)); -C_SHIM(GetThreadCacheSize, size_t, (void), ()); -C_SHIM(MarkThreadTemporarilyIdle, void, (void), ()); // Can't use the shim here because of the need to translate the enums. extern "C" |