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

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: fix IsAvailable Created 8 years, 3 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..d3ced5728343f0cc2217382191391753dfed0f84
--- /dev/null
+++ b/base/allocator/type_profiler.cc
@@ -0,0 +1,62 @@
+// 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(TYPE_PROFILING)
+
+namespace base {
+namespace type_profiler {
+
+// These variables are not in the InterceptFunctios class so that:
jar (doing other things) 2012/09/06 19:31:43 nit: InterceptFunctios --> InterceptFunctions
Dai Mikurube (NOT FULLTIME) 2012/09/07 08:06:45 Finally, removed the comment.
+// * They are visible from __op_new_intercept__ and __op_delete_intercept__.
+// * They are invisible from any other functions.
jar (doing other things) 2012/09/06 19:31:43 I don't understand why you didn't just make them p
Dai Mikurube (NOT FULLTIME) 2012/09/07 08:06:45 Done.
+//
+// Note that it is impossible to hide them by 'friend'
+// since __op_new_intercept__ and __op_delete_intercept__ must be global.
jar (doing other things) 2012/09/06 19:31:43 Global function can be friends. Nice example in ht
Dai Mikurube (NOT FULLTIME) 2012/09/07 08:06:45 Done.
+static InterceptFunction* g_new_intercept = NopIntercept;
+static InterceptFunction* g_delete_intercept = NopIntercept;
+
+// static
+bool InterceptFunctions::SetFunctions(InterceptFunction* new_intercept,
+ InterceptFunction* delete_intercept) {
+#if !defined(NDEBUG)
+ // DCHECKs are wanted for these checks, but base/logging is not acceptable.
jar (doing other things) 2012/09/06 19:31:43 It is confusing to have code in base/allocator/*,
Dai Mikurube (NOT FULLTIME) 2012/09/07 08:06:45 Done.
+ // This file is linked with many non-Chromium code.
+ if (g_new_intercept != NopIntercept)
+ return false;
+ if (g_delete_intercept != NopIntercept)
+ return false;
+#endif // !defined(NDEBUG)
+
+ g_new_intercept = new_intercept;
+ g_delete_intercept = delete_intercept;
+ return true;
+}
+
+// static
+bool InterceptFunctions::IsAvailable() {
+ return g_new_intercept != NopIntercept || g_delete_intercept != NopIntercept;
+}
+
+void* NopIntercept(void* ptr, size_t size, const std::type_info& type) {
+ return ptr;
+}
+
+} // namespace type_profiler
+} // namespace base
+
+void* __op_new_intercept__(void* ptr,
+ size_t size,
+ const std::type_info& type) {
+ return base::type_profiler::g_new_intercept(ptr, size, type);
+}
+
+void* __op_delete_intercept__(void* ptr,
+ size_t size,
+ const std::type_info& type) {
+ return base::type_profiler::g_delete_intercept(ptr, size, type);
+}
+
+#endif // defined(TYPE_PROFILING)

Powered by Google App Engine
This is Rietveld 408576698