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..f389b432760886820b8ac17f9bed58552a6ae8ac |
| --- /dev/null |
| +++ b/base/allocator/type_profiler.cc |
| @@ -0,0 +1,52 @@ |
| +// 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 { |
| + |
| +static InterceptFunction* g_new_intercept = NULL; |
| +static InterceptFunction* g_delete_intercept = NULL; |
| + |
| +void SetInterceptFunctions(InterceptFunction* new_intercept, |
|
jar (doing other things)
2012/09/02 01:37:11
You added a comment on IsInterceptFunctionAvailabl
Dai Mikurube (NOT FULLTIME)
2012/09/03 08:16:30
ContentMainRunnerImpl::Initialize (content/app/con
|
| + InterceptFunction* delete_intercept) { |
| + g_new_intercept = new_intercept; |
| + g_delete_intercept = delete_intercept; |
| +} |
| + |
| +// This function is not thread safe. Use it only when SetInterceptFunctions() |
| +// is called in a single-threaded status such as type_profiler_unittests. |
|
jar (doing other things)
2012/09/02 01:37:11
This comment should appear in the header, rather t
Dai Mikurube (NOT FULLTIME)
2012/09/03 08:16:30
Done.
|
| +bool IsInterceptFunctionsAvailable() { |
| + return g_new_intercept != NULL || g_delete_intercept != NULL; |
| +} |
| + |
| +} // namespace type_profiler |
| +} // namespace base |
| + |
| +void* __op_new_intercept__(void* ptr, |
| + size_t size, |
| + const std::type_info& type) { |
| + base::type_profiler::InterceptFunction* new_intercept = |
|
jar (doing other things)
2012/09/02 01:37:11
As noted above, this is a racy assignment, relativ
Dai Mikurube (NOT FULLTIME)
2012/09/03 08:16:30
It is because of maruel's suggestion...
http://co
jar (doing other things)
2012/09/04 17:40:38
I put comments into the thread you suggested.
My
|
| + base::type_profiler::g_new_intercept; |
| + if (new_intercept) |
| + return new_intercept(ptr, size, type); |
| + |
| + return ptr; |
| +} |
| + |
| +void* __op_delete_intercept__(void* ptr, |
| + size_t size, |
| + const std::type_info& type) { |
| + base::type_profiler::InterceptFunction* delete_intercept = |
| + base::type_profiler::g_delete_intercept; |
| + if (delete_intercept) |
| + return delete_intercept(ptr, size, type); |
| + |
| + return ptr; |
| +} |
| + |
| +#endif // defined(TYPE_PROFILING) |