From: Nicholas Nethercote Date: Sun, 13 Mar 2005 06:10:20 +0000 (+0000) Subject: Make MAC_(print_malloc_stats) local by moving it and associated stuff to X-Git-Tag: svn/VALGRIND_3_0_0~982 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58fb32879ed52b0e05fe911885c911a2bd484700;p=thirdparty%2Fvalgrind.git Make MAC_(print_malloc_stats) local by moving it and associated stuff to mac_needs.c. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3336 --- diff --git a/memcheck/mac_malloc_wrappers.c b/memcheck/mac_malloc_wrappers.c index 7ee1c0fb93..63f7eba91d 100644 --- a/memcheck/mac_malloc_wrappers.c +++ b/memcheck/mac_malloc_wrappers.c @@ -526,46 +526,6 @@ void MAC_(mempool_free)(Addr pool, Addr addr) die_and_free_mem ( tid, mc, prev_chunk, mp->rzB ); } -typedef - struct { - UInt nblocks; - SizeT nbytes; - } - MallocStats; - -static void malloc_stats_count_chunk(VgHashNode* node, void* d) { - MAC_Chunk* mc = (MAC_Chunk*)node; - MallocStats *ms = (MallocStats *)d; - - ms->nblocks ++; - ms->nbytes += mc->size; -} - -void MAC_(print_malloc_stats) ( void ) -{ - MallocStats ms; - - ms.nblocks = 0; - ms.nbytes = 0; - - /* Mmm... more lexical scoping */ - if (VG_(clo_verbosity) == 0) - return; - - /* Count memory still in use. */ - VG_(HT_apply_to_all_nodes)(MAC_(malloc_list), malloc_stats_count_chunk, &ms); - - VG_(message)(Vg_UserMsg, - "malloc/free: in use at exit: %d bytes in %d blocks.", - ms.nbytes, ms.nblocks); - VG_(message)(Vg_UserMsg, - "malloc/free: %d allocs, %d frees, %u bytes allocated.", - cmalloc_n_mallocs, - cmalloc_n_frees, cmalloc_bs_mallocd); - if (VG_(clo_verbosity) > 1) - VG_(message)(Vg_UserMsg, ""); -} - /*--------------------------------------------------------------------*/ /*--- end mac_malloc_wrappers.c ---*/ /*--------------------------------------------------------------------*/ diff --git a/memcheck/mac_needs.c b/memcheck/mac_needs.c index 28a828e65d..745d03fb9d 100644 --- a/memcheck/mac_needs.c +++ b/memcheck/mac_needs.c @@ -828,6 +828,50 @@ static void done_prof_mem ( void ) { } #endif +/*------------------------------------------------------------*/ +/*--- Statistics printing ---*/ +/*------------------------------------------------------------*/ + +typedef + struct { + UInt nblocks; + SizeT nbytes; + } + MallocStats; + +static void malloc_stats_count_chunk(VgHashNode* node, void* d) { + MAC_Chunk* mc = (MAC_Chunk*)node; + MallocStats *ms = (MallocStats *)d; + + ms->nblocks ++; + ms->nbytes += mc->size; +} + +static void print_malloc_stats ( void ) +{ + MallocStats ms; + + ms.nblocks = 0; + ms.nbytes = 0; + + /* Mmm... more lexical scoping */ + if (VG_(clo_verbosity) == 0) + return; + + /* Count memory still in use. */ + VG_(HT_apply_to_all_nodes)(MAC_(malloc_list), malloc_stats_count_chunk, &ms); + + VG_(message)(Vg_UserMsg, + "malloc/free: in use at exit: %d bytes in %d blocks.", + ms.nbytes, ms.nblocks); + VG_(message)(Vg_UserMsg, + "malloc/free: %d allocs, %d frees, %u bytes allocated.", + cmalloc_n_mallocs, + cmalloc_n_frees, cmalloc_bs_mallocd); + if (VG_(clo_verbosity) > 1) + VG_(message)(Vg_UserMsg, ""); +} + /*------------------------------------------------------------*/ /*--- Common initialisation + finalisation ---*/ /*------------------------------------------------------------*/ @@ -841,7 +885,7 @@ void MAC_(common_pre_clo_init)(void) void MAC_(common_fini)(void (*leak_check)(LeakCheckMode mode)) { - MAC_(print_malloc_stats)(); + print_malloc_stats(); if (VG_(clo_verbosity) == 1) { if (MAC_(clo_leak_check) == LC_Off) diff --git a/memcheck/mac_shared.h b/memcheck/mac_shared.h index 190fda44be..2f6ad58b7b 100644 --- a/memcheck/mac_shared.h +++ b/memcheck/mac_shared.h @@ -370,8 +370,6 @@ extern void MAC_(common_fini) ( void (*leak_check)(LeakCheckMode mode) ) extern Bool MAC_(handle_common_client_requests) ( ThreadId tid, UWord* arg_block, UWord* ret ); -extern void MAC_(print_malloc_stats) ( void ); - /* For leak checking */ extern void MAC_(pp_LeakError)(void* vl, UInt n_this_record, UInt n_total_records);