Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: third_party/tcmalloc/chromium/src/allocated_type_map.cc

Issue 10411047: Type profiler by intercepting 'new' and 'delete' expressions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reflected comments #21,22 Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/allocated_type_map.cc
diff --git a/third_party/tcmalloc/chromium/src/allocated_type_map.cc b/third_party/tcmalloc/chromium/src/allocated_type_map.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f641ccda7d11136844f014f1edd75668551a7b8
--- /dev/null
+++ b/third_party/tcmalloc/chromium/src/allocated_type_map.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 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/allocated_type_map.h>
+
+#include "addressmap-inl.h"
+#include "base/logging.h"
+#include "base/low_level_alloc.h"
+#include "base/spinlock.h"
+#include "tcmalloc_guard.h"
+
+
+//----------------------------------------------------------------------
+// Locking
+//----------------------------------------------------------------------
+
+static SpinLock allocated_type_lock(SpinLock::LINKER_INITIALIZED);
Ryan Sleevi 2012/08/10 04:16:09 Please consider the guidance from Google's Open So
Dai Mikurube (NOT FULLTIME) 2012/08/10 07:30:03 It was following other tcmalloc files. I renamed
+
+//----------------------------------------------------------------------
+// Simple allocator for allocated type map's internal memory
+//----------------------------------------------------------------------
+
+static LowLevelAlloc::Arena* allocated_type_map_memory = NULL;
+
+static void* AllocatedTypeMalloc(size_t bytes) {
+ return LowLevelAlloc::AllocWithArena(bytes, allocated_type_map_memory);
+}
+
+static void AllocatedTypeFree(void* p) {
+ LowLevelAlloc::Free(p);
+}
+
+//----------------------------------------------------------------------
+// Profiling control/state data
+//----------------------------------------------------------------------
+
+static AddressMap<AllocatedObject>* allocated_type_map = NULL;
+
+//----------------------------------------------------------------------
+// Manage allocated type map
+//----------------------------------------------------------------------
+
+static void InitializeAllocatedTypeMemory() {
+ if (allocated_type_map_memory != NULL) {
+ DCHECK_NE(allocated_type_map, NULL);
Ryan Sleevi 2012/08/10 04:16:09 BUG? Your use of std::cerr in the _logger wrappers
Dai Mikurube (NOT FULLTIME) 2012/08/10 07:30:03 _log doesn't call this function. Functions in thi
Ryan Sleevi 2012/08/10 09:38:50 I think you may have missed my point. I'm aware of
Dai Mikurube (NOT FULLTIME) 2012/08/13 12:57:42 Sorry, I overlooked it. I'll handle it tomorrow.
Dai Mikurube (NOT FULLTIME) 2012/08/14 05:30:48 Actually, this DCHECK_NE is in third_party/tcmallo
+ return;
+ }
+
+ allocated_type_map_memory =
+ LowLevelAlloc::NewArena(0, LowLevelAlloc::DefaultArena());
+
+ allocated_type_map =
+ new(AllocatedTypeMalloc(sizeof(AddressMap<AllocatedObject>)))
+ AddressMap<AllocatedObject>(AllocatedTypeMalloc, AllocatedTypeFree);
Ryan Sleevi 2012/08/10 04:16:09 BUG? Do you not need to add any barriers here? Do
Dai Mikurube (NOT FULLTIME) 2012/08/10 07:30:03 Ah, I understand your question. I was thinking it
+}
+
+void InsertAllocatedType(void* address,
+ unsigned int size,
+ const std::type_info& type) {
+ SpinLockHolder l(&allocated_type_lock);
+ InitializeAllocatedTypeMemory();
+
+ allocated_type_map->Insert(address, AllocatedObject(size, &type));
+}
+
+void EraseAllocatedType(void* address) {
+ SpinLockHolder l(&allocated_type_lock);
+ InitializeAllocatedTypeMemory();
+
+ AllocatedObject obj;
+ allocated_type_map->FindAndRemove(address, &obj);
+}
+
+const std::type_info* LookupAllocatedType(const void* address) {
+ SpinLockHolder l(&allocated_type_lock);
+ InitializeAllocatedTypeMemory();
+
+ const AllocatedObject* found = allocated_type_map->Find(address);
+ if (found == NULL)
+ return NULL;
+ return found->type;
+}
+
+static const TCMallocGuard tcmalloc_initializer;

Powered by Google App Engine
This is Rietveld 408576698