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..19b295c03fca1757545384b2a2bdc60154ad1c3f |
| --- /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; |
| +} |
| +} |
| + |
| +void* __op_new_intercept__(void* ptr, |
| + size_t size, |
| + const std::type_info& type) { |
| + return base::type_profiler::InterceptFunctions::new_intercept_( |
| + ptr, size, type); |
| +} |
| + |
| +void* __op_delete_intercept__(void* ptr, |
| + size_t size, |
| + const std::type_info& type) { |
| + return base::type_profiler::InterceptFunctions::delete_intercept_( |
| + ptr, size, type); |
| +} |
| + |
| +namespace base { |
| +namespace type_profiler { |
| + |
| +InterceptFunction* InterceptFunctions::new_intercept_ = NopIntercept; |
| +InterceptFunction* InterceptFunctions::delete_intercept_ = NopIntercept; |
| + |
| +// static |
| +void InterceptFunctions::SetFunctions(InterceptFunction* new_intercept, |
| + InterceptFunction* delete_intercept) { |
| + // Don't use DCHECKs as this file is injected also to non-Chromium binaries. |
| + // They don't link base/ files. |
|
Ryan Sleevi
2012/09/12 19:13:34
nit: wording
// Don't use DCHECK, as this file is
Dai Mikurube (NOT FULLTIME)
2012/09/13 04:00:12
Done.
|
| + assert(new_intercept_ == NopIntercept); |
| + assert(delete_intercept_ == NopIntercept); |
| + |
| + new_intercept_ = new_intercept; |
| + delete_intercept_ = delete_intercept; |
| +} |
| + |
| +// static |
| +void InterceptFunctions::ResetFunctions() { |
| + new_intercept_ = NopIntercept; |
| + delete_intercept_ = NopIntercept; |
| +} |
| + |
| +// static |
| +bool InterceptFunctions::IsAvailable() { |
| + return new_intercept_ != NopIntercept || delete_intercept_ != NopIntercept; |
| +} |
| + |
| +} // namespace type_profiler |
| +} // namespace base |
| + |
| +#endif // defined(TYPE_PROFILING) |