Chromium Code Reviews| 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) |