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

Unified Diff: base/allocator/allocated_type_tcmalloc.cc

Issue 10411047: Type profiler by intercepting 'new' and 'delete' expressions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: upload again 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: base/allocator/allocated_type_tcmalloc.cc
diff --git a/base/allocator/allocated_type_tcmalloc.cc b/base/allocator/allocated_type_tcmalloc.cc
new file mode 100644
index 0000000000000000000000000000000000000000..09d581956788552a8cc82f551a33e590ef734823
--- /dev/null
+++ b/base/allocator/allocated_type_tcmalloc.cc
@@ -0,0 +1,41 @@
+// 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 "allocated_type.h"
+#include "allocated_type_tcmalloc.h"
+#include "base/atomicops.h"
+#include <gperftools/allocated_type_map.h>
+#include <gperftools/heap-profiler.h>
+
+volatile static Atomic32 g_disable_intercept_if_positive = 0;
+
+void SuspendAllocatedTypeIntercept() {
+ base::subtle::NoBarrier_AtomicIncrement(&g_disable_intercept_if_positive, 1);
+}
+
+void ResumeAllocatedTypeIntercept() {
+ base::subtle::NoBarrier_AtomicIncrement(&g_disable_intercept_if_positive, -1);
+}
+
+void* __op_new_intercept__(void* ptr,
+ size_t size,
+ const std::type_info& type) {
+ if (base::subtle::NoBarrier_Load(&g_disable_intercept_if_positive) > 0) {
+ if (IsHeapProfilerRunning()) {
+ InsertAllocatedType(ptr, size, type);
+ }
+ }
+ return ptr;
+}
+
+void* __op_delete_intercept__(void* ptr,
+ size_t size,
+ const std::type_info &type) {
+ if (base::subtle::NoBarrier_Load(&g_disable_intercept_if_positive) > 0) {
+ if (IsHeapProfilerRunning()) {
+ EraseAllocatedType(ptr);
+ }
+ }
+ return ptr;
+}

Powered by Google App Engine
This is Rietveld 408576698