struct IPCacheEntry
{
- size_t id;
+ unsigned int id;
bool skip;
bool stop;
};
-atomic<size_t> next_cache_id;
-atomic<size_t> next_thread_id;
+atomic<unsigned int> next_cache_id;
+atomic<unsigned int> next_thread_id;
// must be kept separately from ThreadData to ensure it stays valid
// even until after ThreadData is destroyed
struct Tree
{
- static const size_t MAX_DEPTH = 64;
- size_t data[MAX_DEPTH];
- size_t depth;
+ static const unsigned int MAX_DEPTH = 64;
+ unsigned int data[MAX_DEPTH];
+ unsigned int depth;
bool operator==(const Tree& o) const
{
- return depth == o.depth && !memcmp(data, o.data, sizeof(size_t) * depth);
+ return depth == o.depth && !memcmp(data, o.data, sizeof(unsigned int) * depth);
}
};
size_t operator()(const Tree& tree) const
{
size_t seed = 0;
- hash<size_t> nodeHash;
- for (size_t i = 0; i < tree.depth; ++i) {
+ hash<unsigned int> nodeHash;
+ for (unsigned int i = 0; i < tree.depth; ++i) {
boost::hash_combine(seed, nodeHash(tree.data[i]));
}
return seed;
{
bool wasInHandler = in_handler;
in_handler = true;
- ipCache.reserve(1024);
+ ipCache.reserve(16384);
+ treeCache.reserve(16384);
string outputFileName = env("DUMP_MALLOC_TRACE_OUTPUT") + to_string(getpid()) + '.' + to_string(thread_id);
out = fopen(outputFileName.c_str(), "wa");
if (!out) {
}
unordered_map<unw_word_t, IPCacheEntry> ipCache;
- unordered_map<Tree, size_t, TreeHasher> treeCache;
- size_t thread_id;
+ unordered_map<Tree, unsigned int, TreeHasher> treeCache;
+ unsigned int thread_id;
FILE* out;
};
thread_local ThreadData threadData;
-size_t print_caller()
+unsigned int print_caller()
{
unw_context_t uc;
unw_getcontext (&uc);
const bool stop = !skip && (!strcmp(name, "main")
|| !strcmp(name, "_GLOBAL__sub_I_main")
|| !strcmp(name, "_Z41__static_initialization_and_destruction_0ii"));
- const size_t id = next_cache_id++;
+ const unsigned int id = next_cache_id++;
// and store it in the cache
it = ipCache.insert(it, make_pair(ip, IPCacheEntry{id, skip, stop}));
if (!skip) {
- fprintf(threadData.out, "%lu=%lx@%s+0x%lx\n", id, ip, name, offset);
+ fprintf(threadData.out, "%u=%lx@%s+0x%lx\n", id, ip, name, offset);
}
}
if (it == treeCache.end()) {
it = treeCache.insert(it, make_pair(tree, next_cache_id++));
- fprintf(threadData.out, "%lu=", it->second);
- for (size_t i = 0; i < tree.depth; ++i) {
- fprintf(threadData.out, "%lu;", tree.data[i]);
+ fprintf(threadData.out, "%u=", it->second);
+ for (unsigned int i = 0; i < tree.depth; ++i) {
+ fprintf(threadData.out, "%u;", tree.data[i]);
}
fputs("\n", threadData.out);
}
void handleMalloc(void* ptr, size_t size)
{
- const size_t treeId = print_caller();
- fprintf(threadData.out, "+%lu:%p %lu\n", size, ptr, treeId);
+ const unsigned int treeId = print_caller();
+ fprintf(threadData.out, "+%lu:%p %u\n", size, ptr, treeId);
}
void handleFree(void* ptr)