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..7a492a3473ccca0d24b22c96820958bd081b1213 |
| --- /dev/null |
| +++ b/base/allocator/type_profiler.cc |
| @@ -0,0 +1,63 @@ |
| +// 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" |
| + |
| +#include <assert.h> |
| + |
| +#if defined(TYPE_PROFILING) |
| + |
| +namespace { |
| + |
| +void* NopIntercept(void* ptr, size_t size, const std::type_info& type) { |
| + return ptr; |
| +} |
| + |
| +base::type_profiler::InterceptFunction* g_new_intercept = NopIntercept; |
| +base::type_profiler::InterceptFunction* g_delete_intercept = NopIntercept; |
| + |
| +} // anonymous namespace |
|
Ryan Sleevi
2012/09/13 09:13:25
For unnamed namespaces (nit-peeve: not anonymous,
Dai Mikurube (NOT FULLTIME)
2012/09/13 10:45:04
Done. (also for type_profiler_control.cc)
|
| + |
| +void* __op_new_intercept__(void* ptr, |
| + size_t size, |
| + const std::type_info& type) { |
| + return g_new_intercept(ptr, size, type); |
| +} |
| + |
| +void* __op_delete_intercept__(void* ptr, |
| + size_t size, |
| + const std::type_info& type) { |
| + return g_delete_intercept(ptr, size, type); |
| +} |
| + |
| +namespace base { |
| +namespace type_profiler { |
| + |
| +// static |
| +void InterceptFunctions::SetFunctions(InterceptFunction* new_intercept, |
| + InterceptFunction* delete_intercept) { |
| + // Don't use DCHECK, as this file is injected into targets |
| + // that do not and should not depend on base/base.gyp:base |
| + assert(g_new_intercept == NopIntercept); |
| + assert(g_delete_intercept == NopIntercept); |
| + |
| + g_new_intercept = new_intercept; |
| + g_delete_intercept = delete_intercept; |
| +} |
| + |
| +// static |
| +void InterceptFunctions::ResetFunctions() { |
| + g_new_intercept = NopIntercept; |
| + g_delete_intercept = NopIntercept; |
| +} |
| + |
| +// static |
| +bool InterceptFunctions::IsAvailable() { |
| + return g_new_intercept != NopIntercept || g_delete_intercept != NopIntercept; |
| +} |
| + |
| +} // namespace type_profiler |
| +} // namespace base |
| + |
| +#endif // defined(TYPE_PROFILING) |