void AllocatorTLSF_Impl::WalkHeap(WalkerFn _Walker, void* _pUserData, long _Flags) { TLSFContext ctx; ctx.Walker = _Walker; ctx.pUserData = _pUserData; ctx.Flags = _Flags; tlsf_walk_heap(hPool, TLSFWalker, &ctx); }
AllocatorTLSF_Impl::~AllocatorTLSF_Impl() { if (Stats.NumAllocations != 0) tlsf_walk_heap(hPool, TraceAllocated, DebugName); //AssertX(Stats.NumAllocations == 0, "Allocator %s being destroyed with %u allocations still unfreed! This may leave dangling pointers. See trace for addresses.", DebugName, Stats.NumAllocations); AssertX(AllocatorTLSF_Impl::IsValid(), "TLSF Heap is corrupt"); tlsf_destroy(hPool); }
void malloc_stats(void) { struct malloc_stats s; s.used = 0; s.free = 0; tlsf_walk_heap(tlsf_mem_pool, malloc_walker, &s); printf("used: %10d\nfree: %10d\n", s.used, s.free); }
static int memstats(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { htsbuf_queue_t out; allsegs_t as = {}; hts_lwmutex_lock(&mutex); tlsf_walk_heap(gpool, list_all_segs_walk, &as); int size = as.count * sizeof(seginfo_t); as.ptr = halloc(size); as.count = 0; tlsf_walk_heap(gpool, list_all_segs_walk, &as); hts_lwmutex_unlock(&mutex); qsort(as.ptr, as.count, sizeof(seginfo_t), seginfo_cmp); htsbuf_queue_init(&out, 0); htsbuf_qprintf(&out, "%d segments ptr=%p\n\n", as.count, as.ptr); int lastsize = -1; int dup = 0; for(int i = 0; i < as.count; i++) { if(as.ptr[i].size == lastsize && i != as.count - 1) { dup++; } else { htsbuf_qprintf(&out, "%s %10d * %d\n", as.ptr[i].used ? "Used" : "Free", as.ptr[i].size, dup + 1); dup = 0; } lastsize = as.ptr[i].size; } hfree(as.ptr, size); return http_send_reply(hc, 0, "text/plain", NULL, NULL, 0, &out); }
struct mallinfo mallinfo(void) { struct mallinfo mi; memstats_t ms = {0}; mi.arena = total_avail; hts_mutex_lock(&mutex); tlsf_walk_heap(gpool, mywalker, &ms); hts_mutex_unlock(&mutex); mi.ordblks = ms.free_segs; mi.uordblks = ms.used; mi.fordblks = ms.free; return mi; }
static void memtrace(void) { memstats_t ms = {0}; hts_lwmutex_lock(&mutex); tlsf_walk_heap(gpool, mywalker, &ms); hts_lwmutex_unlock(&mutex); tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "Memory allocator status -- Used: %d (%d segs) Free: %d (%d segs)", ms.used, ms.used_segs, ms.free, ms.free_segs); for(int i = 0; i < 33; i++) { tracelog(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "%2d: %8d %8d", i, ms.hist_used[i], ms.hist_free[i]); } }
static void memtrace(void) { memstats_t ms = {0}; hts_mutex_lock(&mutex); tlsf_walk_heap(gpool, mywalker, &ms); hts_mutex_unlock(&mutex); trace(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "Memory allocator status -- Used: %d (%d segs) Free: %d (%d segs)", ms.used, ms.used_segs, ms.free, ms.free_segs); #if ENABLE_SPIDERMONKEY extern int js_get_mem_usage(void); trace(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "Memory used by Spidermonkey: %d bytes", js_get_mem_usage()); #endif for(int i = 0; i < 33; i++) { trace(TRACE_NO_PROP, TRACE_ERROR, "MEMORY", "%2d: %8d %8d", i, ms.hist_used[i], ms.hist_free[i]); } }
void dumpAllocatedMemory() { nc::thread::ScopedLock< nc::thread::Mutex > lock( g_commonHeapMtex ); if( g_tlsfPool == 0 ) return; tlsf_walk_heap( g_tlsfPool, 0, 0 ); }