8 #ifndef ATHENAAUDITORS_MEMORYHOOKSTCMALLOC_H
9 #define ATHENAAUDITORS_MEMORYHOOKSTCMALLOC_H
26 #include <gperftools/malloc_extension.h>
27 #include <gperftools/malloc_hook.h>
28 #include <gperftools/stacktrace.h>
29 #include "gperftools/tcmalloc.h"
32 static long long counter_tc_m(0);
33 static long long counter_tc_f(0);
34 static long long counter_tc_mtf(0);
35 static long long counter_tc_mm(0);
36 static long long counter_tc_mum(0);
45 { std::cerr <<
"TCMALLOC HOOKS: RemoveNewHook - Should not be here\n"; abort();
return 1; }
47 { std::cerr <<
"TCMALLOC HOOKS: RemoveDeleteHook - Should not be here\n"; abort();
return 1; }
49 { std::cerr <<
"TCMALLOC HOOKS: AddNewHook - Should not be here\n"; abort();
return 1; }
51 { std::cerr <<
"TCMALLOC HOOKS: AddDeleteHook - Should not be here\n"; abort();
return 1; }
54 { std::cerr <<
"TCMALLOC HOOKS: AddMmapHook - Should not be here\n"; abort();
return 1; }
56 { std::cerr <<
"TCMALLOC HOOKS: AddMunmapHook - Should not be here\n"; abort();
return 1; }
67 if(collectStacktraces)
69 b->allocatedFrom.resize(stacktraceDepth);
70 unw_backtrace (
b->allocatedFrom.data(),
b->allocatedFrom.capacity());
72 std::pair<allocSet_tc::iterator, bool>
i = allocset_tc.insert( *
b );
75 std::cerr <<
"ALREADY EXISTING " << std::hex <<
ptr << std::dec <<
"\n";
77 allocset_last=
i.first;
91 if ( allocset_last == allocset_tc.end() || allocset_last->allocated != (uintptr_t)
ptr )
95 if (
i != allocset_tc.end() )
104 allocset_tc.erase(allocset_last);
105 delete &(*allocset_last);
106 allocset_last = allocset_tc.end();
139 allocset_last=allocset_tc.end();
142 std::cerr <<
"TCMALLOC NEW HOOK OK\n";
144 std::cerr <<
"TCMALLOC DELETE HOOK OK\n";
146 std::cerr <<
"TCMALLOC MMAP HOOK OK\n";
148 std::cerr <<
"TCMALLOC MUNMAP HOOK OK\n";