Author: njn Date: 2007-09-27 00:01:39 +0100 (Thu, 27 Sep 2007) New Revision: 6918
Log: When --stacks=yes, try taking snapshots on every stack alloc/dealloc. Modified: branches/MASSIF2/massif/ms_main.c branches/MASSIF2/massif/tests/culling1.stderr.exp branches/MASSIF2/massif/tests/culling2.stderr.exp branches/MASSIF2/massif/tests/realloc.stderr.exp Modified: branches/MASSIF2/massif/ms_main.c =================================================================== --- branches/MASSIF2/massif/ms_main.c 2007-09-26 22:49:48 UTC (rev 6917) +++ branches/MASSIF2/massif/ms_main.c 2007-09-26 23:01:39 UTC (rev 6918) @@ -31,9 +31,10 @@ // XXX: //--------------------------------------------------------------------------- // Todo: -// - disable --stacks, unless/until I do it fully and properly -- ie. -// track every stack alloc/dealloc -- necessary if peak-taking is to be -// accurate. Stacks stuff is hard to regtest, unfortunately. +// - -v: give more detail on each snapshot -- sizes, etc +// - -v: print number of skipped snapshots after each one is taken +// - Add ability to draw multiple graphs, eg. heap-only, stack-only, total. +// Give each graph a title. // - do peak-taking. // - make file format more generic. Obstacles: // - unit prefixes are not generic @@ -249,6 +250,8 @@ static UInt n_zero_allocs = 0; static UInt n_reallocs = 0; static UInt n_frees = 0; +static UInt n_stack_allocs = 0; +static UInt n_stack_frees = 0; static UInt n_xpt_init_expansions = 0; static UInt n_xpt_later_expansions = 0; static UInt n_getXCon_redo = 0; @@ -1417,18 +1420,42 @@ //------------------------------------------------------------// -//--- Tracked events ---// +//--- Stacks ---// //------------------------------------------------------------// +static void update_stack_stats(SSizeT stack_szB_len) +{ + total_allocs_deallocs_szB += stack_szB_len; +} + +static void new_mem_stack(Addr a, SizeT len) +{ + n_stack_allocs++; + update_stack_stats(len); + maybe_take_snapshot("stk-new"); +} + +static void die_mem_stack(Addr a, SizeT len) +{ + n_stack_frees++; + update_stack_stats(len); + maybe_take_snapshot("stk-die"); +} + + static void new_mem_stack_signal(Addr a, SizeT len) { sigstacks_szB += len; + update_stack_stats(len); + maybe_take_snapshot("sig-new"); } static void die_mem_stack_signal(Addr a, SizeT len) { tl_assert(sigstacks_szB >= len); sigstacks_szB -= len; + update_stack_stats(len); + maybe_take_snapshot("sig-die"); } @@ -1475,9 +1502,11 @@ static Bool is_first_SB = True; if (is_first_SB) { - // Do an initial sample for t = 0. We use 'maybe_take_snapshot' - // instead of 'take_snapshot' to get its internal static variables - // initialised. + // Do an initial sample to guarantee that we have at least one. + // We use 'maybe_take_snapshot' instead of 'take_snapshot' to ensure + // 'maybe_take_snapshot's internal static variables are initialised. + // However, with --stacks=yes this snapshot may not actually be the + // first one, surprisingly enough. maybe_take_snapshot("startup"); is_first_SB = False; } @@ -1703,6 +1732,8 @@ ( n_allocs ? n_zero_allocs * 100 / n_allocs : 0 )); VERB("reallocs: %u", n_reallocs); VERB("frees: %u", n_frees); + VERB("stack allocs: %u", n_stack_allocs); + VERB("stack frees: %u", n_stack_frees); VERB("XPts: %u", n_xpts); VERB("top-XPts: %u (%d%%)", alloc_xpt->n_children, @@ -1737,6 +1768,15 @@ } } + if (clo_stacks) { + // Events to track + VG_(track_new_mem_stack) ( new_mem_stack ); + VG_(track_die_mem_stack) ( die_mem_stack ); + + VG_(track_new_mem_stack_signal)( new_mem_stack_signal ); + VG_(track_die_mem_stack_signal)( die_mem_stack_signal ); + } + // We don't take a snapshot now, because there's still some core // initialisation to do, in which case we have an artificial gap. // Instead we do it when the first translation occurs. See @@ -1777,10 +1817,6 @@ ms_realloc, 0 ); - // Events to track - VG_(track_new_mem_stack_signal)( new_mem_stack_signal ); - VG_(track_die_mem_stack_signal)( die_mem_stack_signal ); - // HP_Chunks malloc_list = VG_(HT_construct)( 80021 ); // prime, big Modified: branches/MASSIF2/massif/tests/culling1.stderr.exp =================================================================== --- branches/MASSIF2/massif/tests/culling1.stderr.exp 2007-09-26 22:49:48 UTC (rev 6917) +++ branches/MASSIF2/massif/tests/culling1.stderr.exp 2007-09-26 23:01:39 UTC (rev 6918) @@ -365,6 +365,8 @@ Massif: zeroallocs: 0 (0%) Massif: reallocs: 0 Massif: frees: 0 +Massif: stack allocs: 0 +Massif: stack frees: 0 Massif: XPts: 2 Massif: top-XPts: 1 (50%) Massif: dup'd XPts: 30 Modified: branches/MASSIF2/massif/tests/culling2.stderr.exp =================================================================== --- branches/MASSIF2/massif/tests/culling2.stderr.exp 2007-09-26 22:49:48 UTC (rev 6917) +++ branches/MASSIF2/massif/tests/culling2.stderr.exp 2007-09-26 23:01:39 UTC (rev 6918) @@ -518,6 +518,8 @@ Massif: zeroallocs: 1 (0%) Massif: reallocs: 0 Massif: frees: 0 +Massif: stack allocs: 0 +Massif: stack frees: 0 Massif: XPts: 2 Massif: top-XPts: 1 (50%) Massif: dup'd XPts: 40 Modified: branches/MASSIF2/massif/tests/realloc.stderr.exp =================================================================== --- branches/MASSIF2/massif/tests/realloc.stderr.exp 2007-09-26 22:49:48 UTC (rev 6917) +++ branches/MASSIF2/massif/tests/realloc.stderr.exp 2007-09-26 23:01:39 UTC (rev 6918) @@ -15,6 +15,8 @@ Massif: zeroallocs: 0 (0%) Massif: reallocs: 4 Massif: frees: 1 +Massif: stack allocs: 0 +Massif: stack frees: 0 Massif: XPts: 5 Massif: top-XPts: 4 (80%) Massif: dup'd XPts: 0 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Valgrind-developers mailing list Valgrind-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-developers