Index: base/allocator/type_profiler.h |
diff --git a/base/allocator/type_profiler.h b/base/allocator/type_profiler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..babc3d8f4482fac82c984ac6b56465b09fee7301 |
--- /dev/null |
+++ b/base/allocator/type_profiler.h |
@@ -0,0 +1,59 @@ |
+// 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. |
+ |
+#ifndef BASE_ALLOCATOR_TYPE_PROFILER_H_ |
+#define BASE_ALLOCATOR_TYPE_PROFILER_H_ |
+ |
+#if defined(TYPE_PROFILING) |
+ |
+#include <cstddef> // for size_t |
+#include <typeinfo> // for std::typeinfo |
+ |
+// These two functions wrap all 'new' and 'delete' expressions. |
+// They are called by a modified version of Clang checked-in |
+// at deps/third_party/llvm-allocated-type. |
+// These prototype declarations are required to make them friends of |
+// InterceptFunctions below. |
+ |
+void* __op_new_intercept__(void* ptr, |
+ size_t size, |
+ const std::type_info& type); |
+ |
+void* __op_delete_intercept__(void* ptr, |
+ size_t size, |
+ const std::type_info& type); |
+ |
+namespace base { |
+namespace type_profiler { |
+ |
+typedef void* InterceptFunction(void*, size_t, const std::type_info&); |
+ |
+class InterceptFunctions { |
+ public: |
+ // It must be called only once in a process while it is in single-thread. |
+ // For now, ContentMainRunnerImpl::Initialize is the only supposed caller |
+ // of this function except for single-threaded unit tests. |
+ static void SetFunctions(InterceptFunction* new_intercept, |
+ InterceptFunction* delete_intercept); |
+ |
+ private: |
+ friend class TypeProfilerTest; |
+ friend void* ::__op_new_intercept__(void*, size_t, const std::type_info&); |
+ friend void* ::__op_delete_intercept__(void*, size_t, const std::type_info&); |
jar (doing other things)
2012/09/12 00:34:09
Why does this require a pre-declaration of the fun
Dai Mikurube (NOT FULLTIME)
2012/09/12 04:26:27
Clang without any compiler option says as follows
|
+ |
+ // These functions are not thread safe. |
+ // They must be used only from single-threaded unit tests. |
+ static void ResetFunctions(); |
+ static bool IsAvailable(); |
+ |
+ static InterceptFunction* new_intercept_; |
+ static InterceptFunction* delete_intercept_; |
+}; |
+ |
+} // namespace type_profiler |
+} // namespace base |
+ |
+#endif // defined(TYPE_PROFILING) |
+ |
+#endif // BASE_ALLOCATOR_TYPE_PROFILER_H_ |