• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #if defined(TYPE_PROFILING)
6 
7 #include "base/allocator/type_profiler.h"
8 
9 #include <assert.h>
10 
11 namespace {
12 
NopIntercept(void * ptr,size_t size,const std::type_info & type)13 void* NopIntercept(void* ptr, size_t size, const std::type_info& type) {
14   return ptr;
15 }
16 
17 base::type_profiler::InterceptFunction* g_new_intercept = NopIntercept;
18 base::type_profiler::InterceptFunction* g_delete_intercept = NopIntercept;
19 
20 }
21 
__op_new_intercept__(void * ptr,size_t size,const std::type_info & type)22 void* __op_new_intercept__(void* ptr,
23                            size_t size,
24                            const std::type_info& type) {
25   return g_new_intercept(ptr, size, type);
26 }
27 
__op_delete_intercept__(void * ptr,size_t size,const std::type_info & type)28 void* __op_delete_intercept__(void* ptr,
29                               size_t size,
30                               const std::type_info& type) {
31   return g_delete_intercept(ptr, size, type);
32 }
33 
34 namespace base {
35 namespace type_profiler {
36 
37 // static
SetFunctions(InterceptFunction * new_intercept,InterceptFunction * delete_intercept)38 void InterceptFunctions::SetFunctions(InterceptFunction* new_intercept,
39                                       InterceptFunction* delete_intercept) {
40   // Don't use DCHECK, as this file is injected into targets
41   // that do not and should not depend on base/base.gyp:base
42   assert(g_new_intercept == NopIntercept);
43   assert(g_delete_intercept == NopIntercept);
44 
45   g_new_intercept = new_intercept;
46   g_delete_intercept = delete_intercept;
47 }
48 
49 // static
ResetFunctions()50 void InterceptFunctions::ResetFunctions() {
51   g_new_intercept = NopIntercept;
52   g_delete_intercept = NopIntercept;
53 }
54 
55 // static
IsAvailable()56 bool InterceptFunctions::IsAvailable() {
57   return g_new_intercept != NopIntercept || g_delete_intercept != NopIntercept;
58 }
59 
60 }  // namespace type_profiler
61 }  // namespace base
62 
63 #endif  // defined(TYPE_PROFILING)
64