static int check_call_status(lua_State *L, int status) { if (status) { const char *msg = lua_tostring(L, -1); lua_pop(L, 1); if (msg == NULL) msg = "unknown error"; am_log0("%s", msg); } return status; }
static void log_pool_stats(const char *name, am_pool *pool) { am_log0( "%-6s: %6u %6u %10u %10u %10u %6d %10uk %10uk %10uk %4.0f%%", name, (unsigned)pool->cellsize, (unsigned)pool->blocksize, (unsigned)pool->stats.nallocs, (unsigned)pool->stats.nfrees, (unsigned)pool->stats.hwm_cells, pool->num_blocks, (unsigned)pool->stats.allocsz / 1024, (unsigned)pool->stats.freesz / 1024, (unsigned)pool->stats.hwm_sz / 1024, (double)pool->stats.allocsz / (double)(pool->stats.nallocs * pool->cellsize) * 100.0); }
void am_destroy_allocator(am_allocator *allocator) { #ifdef AM_PRINT_ALLOC_STATS am_log0("%s", "Allocation stats:"); am_log0( "%-6s %6s %6s %10s %10s %10s %6s %10s %10s %10s %4s ", "", "cellsz", "blksz", "nallocs", "nfrees", "hwm", "blks", "allock", "freesk", " hwmk", "util"); log_pool_stats("tiny", &allocator->tiny_pool); log_pool_stats("small", &allocator->small_pool); log_pool_stats("medium", &allocator->medium_pool); am_log0( "%-6s: %6s %6s %10u %10u %10u %6s %10uk %10uk %10uk %4s", "large", "-", "-", (unsigned)allocator->heap_stats.nallocs, (unsigned)allocator->heap_stats.nfrees, (unsigned)allocator->heap_stats.hwm_cells, "-", (unsigned)allocator->heap_stats.allocsz / 1024, (unsigned)allocator->heap_stats.freesz / 1024, (unsigned)allocator->heap_stats.hwm_sz / 1024, "-"); #endif free_pool_blocks(&allocator->tiny_pool); free_pool_blocks(&allocator->small_pool); free_pool_blocks(&allocator->medium_pool); delete allocator; }