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

Unified Diff: base/allocator/type_profiler.cc

Issue 10411047: Type profiler by intercepting 'new' and 'delete' expressions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed comments. 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/type_profiler.cc
diff --git a/base/allocator/type_profiler.cc b/base/allocator/type_profiler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b8299e1e47d6a0969d3c6228df2c227bfb74b6f3
--- /dev/null
+++ b/base/allocator/type_profiler.cc
@@ -0,0 +1,50 @@
+// 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 "base/allocator/type_profiler.h"
+
+#if defined(PROFILING_TYPE)
+
+namespace base {
+namespace type_profiler {
+
+static InterceptFunction* g_new_intercept = NULL;
+static InterceptFunction* g_delete_intercept = NULL;
+
+void SetInterceptFunctions(InterceptFunction* new_intercept,
+ InterceptFunction* delete_intercept) {
+ g_new_intercept = new_intercept;
+ g_delete_intercept = delete_intercept;
+}
+
+bool IsInterceptFunctionsAvailable() {
+ return g_new_intercept != NULL || g_delete_intercept != NULL;
jar (doing other things) 2012/08/30 16:02:10 Note that this is not very thread safe, relative t
Dai Mikurube (NOT FULLTIME) 2012/08/31 06:10:30 Yeah, I know... In fact, it is not called in the
jar (doing other things) 2012/09/02 01:37:11 The most common pattern for enforcing this is to h
Dai Mikurube (NOT FULLTIME) 2012/09/03 08:16:30 Done.
+}
+
+} // namespace type_profiler
+} // namespace base
+
+void* __op_new_intercept__(void* ptr,
jar (doing other things) 2012/08/30 16:02:10 can we say: void* ::__op_new_intercept(...) { ...
Dai Mikurube (NOT FULLTIME) 2012/08/31 06:10:30 It is impossible. Clang++ says : ../../base/allo
+ size_t size,
+ const std::type_info& type) {
+ base::type_profiler::InterceptFunction* new_intercept =
+ base::type_profiler::g_new_intercept;
+ if (new_intercept)
+ return new_intercept(ptr, size, type);
+
+ return ptr;
+}
+
+void* __op_delete_intercept__(void* ptr,
+ size_t size,
+ const std::type_info& type) {
+ base::type_profiler::InterceptFunction* delete_intercept =
+ base::type_profiler::g_delete_intercept;
+ if (delete_intercept)
+ return delete_intercept(ptr, size, type);
+
+ return ptr;
+}
+
+#endif // defined(PROFILING_TYPE)

Powered by Google App Engine
This is Rietveld 408576698