Chromium Code Reviews| Index: third_party/tcmalloc/chromium/src/type_profiler_map.cc |
| diff --git a/third_party/tcmalloc/chromium/src/type_profiler_map.cc b/third_party/tcmalloc/chromium/src/type_profiler_map.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3390168211ad8d4318fbef9d7abf0b4e3d3e9787 |
| --- /dev/null |
| +++ b/third_party/tcmalloc/chromium/src/type_profiler_map.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <config.h> |
| + |
| +#include <new> |
| +#include <typeinfo> |
| + |
| +#include <gperftools/type_profiler_map.h> |
| + |
| +#include "addressmap-inl.h" |
| +#include "base/logging.h" |
| +#include "base/low_level_alloc.h" |
| +#include "base/spinlock.h" |
| +#include "tcmalloc_guard.h" |
| + |
| +static const TCMallocGuard tcmalloc_initializer; |
| + |
| +//---------------------------------------------------------------------- |
| +// A struct to store size and type_info of an object |
| +//---------------------------------------------------------------------- |
| + |
| +struct ObjectInfo { |
| + public: |
| + ObjectInfo(): size(0), type(NULL) {} |
| + ObjectInfo(unsigned int size_arg, const std::type_info* type_arg) |
| + : size(size_arg), |
| + type(type_arg) { |
| + } |
| + |
| + unsigned int size; |
| + const std::type_info* type; |
| +}; |
| + |
| +//---------------------------------------------------------------------- |
| +// Locking |
| +//---------------------------------------------------------------------- |
| + |
| +static SpinLock g_type_profiler_lock(SpinLock::LINKER_INITIALIZED); |
| + |
| +//---------------------------------------------------------------------- |
| +// Simple allocator for type_info map's internal memory |
| +//---------------------------------------------------------------------- |
| + |
| +static LowLevelAlloc::Arena* g_type_profiler_map_memory = NULL; |
| + |
| +static void* TypeProfilerMalloc(size_t bytes) { |
| + return LowLevelAlloc::AllocWithArena(bytes, g_type_profiler_map_memory); |
| +} |
| + |
| +static void TypeProfilerFree(void* p) { |
| + LowLevelAlloc::Free(p); |
| +} |
| + |
| +//---------------------------------------------------------------------- |
| +// Profiling control/state data |
| +//---------------------------------------------------------------------- |
| + |
| +static AddressMap<ObjectInfo>* g_type_profiler_map = NULL; |
| + |
| +//---------------------------------------------------------------------- |
| +// Manage type_info map |
| +//---------------------------------------------------------------------- |
| + |
| +static void InitializeTypeProfilerMemory() { |
| + if (g_type_profiler_map_memory != NULL) { |
| + RAW_DCHECK(g_type_profiler_map != NULL, "TypeProfilerMap is NULL"); |
| + return; |
| + } |
| + |
| + g_type_profiler_map_memory = |
| + LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena()); |
| + |
| + g_type_profiler_map = |
| + new(TypeProfilerMalloc(sizeof(AddressMap<ObjectInfo>))) |
|
jar (doing other things)
2012/08/30 16:02:10
better is:
sizeof(*g_type_profiler_map)
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
Done.
|
| + AddressMap<ObjectInfo>(TypeProfilerMalloc, TypeProfilerFree); |
| +} |
| + |
| +void TypeProfilerInsertType(void* address, |
| + unsigned int size, |
|
jar (doing other things)
2012/08/30 16:02:10
nit: indent
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
Done.
|
| + const std::type_info& type) { |
| + SpinLockHolder lock(&g_type_profiler_lock); |
| + InitializeTypeProfilerMemory(); |
| + |
| + g_type_profiler_map->Insert(address, ObjectInfo(size, &type)); |
| +} |
| + |
| +void TypeProfilerEraseType(void* address) { |
| + SpinLockHolder lock(&g_type_profiler_lock); |
| + InitializeTypeProfilerMemory(); |
| + |
| + ObjectInfo obj; |
| + g_type_profiler_map->FindAndRemove(address, &obj); |
|
jar (doing other things)
2012/08/30 16:02:10
Is this the only users of FindAndRemove?
Why not s
Dai Mikurube (NOT FULLTIME)
2012/08/31 06:10:30
heap-profile-table.cc uses it, and the only one re
jar (doing other things)
2012/09/02 01:37:11
You'll notice in the examples you cited, that the
Dai Mikurube (NOT FULLTIME)
2012/09/03 08:16:30
That is because we don't think accumulating 'delet
|
| +} |
| + |
| +const std::type_info* TypeProfilerLookupType(const void* address) { |
| + SpinLockHolder lock(&g_type_profiler_lock); |
| + InitializeTypeProfilerMemory(); |
| + |
| + const ObjectInfo* found = g_type_profiler_map->Find(address); |
| + if (found == NULL) |
| + return NULL; |
| + return found->type; |
| +} |