From: Nicholas Nethercote Date: Sun, 11 Nov 2007 22:15:58 +0000 (+0000) Subject: - Make other integer CLO macros more correct, as I did for VG_NUM_CLO in the X-Git-Tag: svn/VALGRIND_3_3_0~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8e2d6e14516c20c585a50dd574017e32eb2b3b4;p=thirdparty%2Fvalgrind.git - Make other integer CLO macros more correct, as I did for VG_NUM_CLO in the last commit. - Add a VG_DBL_CLO for fractional arguments. - Make Massif's --threshold and --peak-inaccuracy arguments fractional. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7150 --- diff --git a/include/pub_tool_options.h b/include/pub_tool_options.h index e39526047a..364206dfd8 100644 --- a/include/pub_tool_options.h +++ b/include/pub_tool_options.h @@ -63,17 +63,35 @@ on 64-bit platforms. */ #define VG_NUMW_CLO(qq_arg, qq_option, qq_var) \ if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \ - (qq_var) = (Word)VG_(atoll)( &qq_arg[ VG_(strlen)(qq_option)+1 ] ); \ + Char* s; \ + Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\ + (qq_var) = n; \ + /* Check for non-numeralness */ \ + if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \ } /* Bounded integer arg */ #define VG_BNUM_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \ if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \ - (qq_var) = (Int)VG_(atoll)( &qq_arg[ VG_(strlen)(qq_option)+1 ] ); \ + Char* s; \ + Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\ + (qq_var) = n; \ + /* Check for non-numeralness, or overflow */ \ + if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \ if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \ if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \ } +/* Double arg */ +#define VG_DBL_CLO(qq_arg, qq_option, qq_var) \ + if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \ + Char* s; \ + double n = VG_(strtod)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\ + (qq_var) = n; \ + /* Check for non-numeralness */ \ + if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \ + } + /* Bool arg whose value is denoted by the exact presence of the given string. */ #define VG_XACT_CLO(qq_arg, qq_option, qq_var) \ if (VG_CLO_STREQ(qq_arg, qq_option)) { \ diff --git a/massif/ms_main.c b/massif/ms_main.c index 0f8aba81bf..103d27e8c8 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -31,11 +31,11 @@ // XXX: //--------------------------------------------------------------------------- // Todo -- critical for release: +// - write documentation +// - address/close all the bug reports below (after writing docs) // - do a graph-drawing test // - write a good basic test that shows how the tool works, suitable for // documentation -// - write documentation -// - make --threshold and --peak-inaccuracy fractional // - do filename properly, clean up Valgrind-wide log file naming mess. // Expected behaviour: // - Main log file: @@ -412,14 +412,14 @@ static Bool clo_heap = True; // a UInt, but this caused problems on 64-bit machines when it was // multiplied by a small negative number and then promoted to a // word-sized type -- it ended up with a value of 4.2 billion. Sigh. -static SizeT clo_heap_admin = 8; -static Bool clo_stacks = False; -static UInt clo_depth = 30; -static UInt clo_threshold = 100; // 100 == 1% -static UInt clo_peak_inaccuracy = 100; // 100 == 1% -static UInt clo_time_unit = TimeMS; -static UInt clo_detailed_freq = 10; -static UInt clo_max_snapshots = 100; +static SizeT clo_heap_admin = 8; +static Bool clo_stacks = False; +static UInt clo_depth = 30; +static double clo_threshold = 1.0; // percentage +static double clo_peak_inaccuracy = 1.0; // percentage +static UInt clo_time_unit = TimeMS; +static UInt clo_detailed_freq = 10; +static UInt clo_max_snapshots = 100; static XArray* args_for_massif; @@ -435,11 +435,9 @@ static Bool ms_process_cmd_line_option(Char* arg) else VG_NUM_CLO(arg, "--heap-admin", clo_heap_admin) else VG_NUM_CLO(arg, "--depth", clo_depth) - // XXX: use a fractional number, so no division by 100 - else VG_NUM_CLO(arg, "--threshold", clo_threshold) + else VG_DBL_CLO(arg, "--threshold", clo_threshold) - // XXX: use a fractional number, so no division by 100 - else VG_NUM_CLO(arg, "--peak-inaccuracy", clo_peak_inaccuracy) + else VG_DBL_CLO(arg, "--peak-inaccuracy", clo_peak_inaccuracy) else VG_NUM_CLO(arg, "--detailed-freq", clo_detailed_freq) else VG_NUM_CLO(arg, "--max-snapshots", clo_max_snapshots) @@ -467,11 +465,8 @@ static void ms_print_usage(void) " --stacks=no|yes profile stack(s) [no]\n" " --depth= depth of contexts [30]\n" " --alloc-fn= specify as an alloc function [empty]\n" -" --threshold= significance threshold, in 100ths of a percent\n" -" (eg. =100 shows nodes covering >= 1%% of\n" -" total size, =0 shows all nodes) [100]\n" -" --peak-inaccuracy= closeness of recorded peak to true peak,\n" -" in 100ths of a percent\n" +" --threshold= significance threshold, as a percentage [1.0]\n" +" --peak-inaccuracy= maximum peak inaccuracy, as a percentage [1.0]\n" " --time-unit=ms|B time unit, milliseconds or bytes\n" " alloc'd/dealloc'd on the heap [ms]\n" " --detailed-freq= every Nth snapshot should be detailed [10]\n" @@ -687,7 +682,7 @@ static SXPt* dup_XTree(XPt* xpt, SizeT total_szB) if (total_szB == 0 && clo_threshold != 0) { sig_child_threshold_szB = 1; } else { - sig_child_threshold_szB = (((ULong)total_szB) * clo_threshold) / 10000ULL; + sig_child_threshold_szB = (SizeT)((total_szB * clo_threshold) / 100); } // How many children are significant? And do we need an aggregate SXPt? @@ -1347,7 +1342,7 @@ maybe_take_snapshot(SnapshotKind kind, Char* what) // because many peaks remain peak only for a short time. SizeT total_szB = heap_szB + heap_extra_szB + stacks_szB; SizeT excess_szB_for_new_peak = - (((ULong)peak_snapshot_total_szB) * clo_peak_inaccuracy) / 10000ULL; + (SizeT)((peak_snapshot_total_szB * clo_peak_inaccuracy) / 100); if (total_szB <= peak_snapshot_total_szB + excess_szB_for_new_peak) { return; } @@ -1922,7 +1917,7 @@ static void pp_snapshot_SXPt(Int fd, SXPt* sxpt, Int depth, Char* depth_str, perc = make_perc(sxpt->szB, snapshot_total_szB); FP("%sn0: %lu in %d place%s below massif's threshold (%s)\n", depth_str, sxpt->szB, sxpt->Insig.n_xpts, s, - make_perc(clo_threshold, 10000)); + make_perc((ULong)clo_threshold, 100)); break; } @@ -2067,8 +2062,8 @@ static void ms_post_clo_init(void) VG_(message)(Vg_UserMsg, "--depth must be between 1 and %d", MAX_DEPTH); VG_(err_bad_option)("--depth"); } - if (clo_threshold < 0 || clo_threshold > 10000) { - VG_(message)(Vg_UserMsg, "--threshold must be between 0 and 10000"); + if (clo_threshold < 0 || clo_threshold > 100) { + VG_(message)(Vg_UserMsg, "--threshold must be between 0.0 and 100.0"); VG_(err_bad_option)("--threshold"); } if (clo_detailed_freq < 1 || clo_detailed_freq > 10000) { diff --git a/massif/tests/peak2.post.exp b/massif/tests/peak2.post.exp index e3e5a599ab..736850cfc1 100644 --- a/massif/tests/peak2.post.exp +++ b/massif/tests/peak2.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./peak -Massif arguments: --stacks=no --time-unit=B --peak-inaccuracy=1000 --heap-admin=64 +Massif arguments: --stacks=no --time-unit=B --peak-inaccuracy=10.0 --heap-admin=64 ms_print arguments: massif.out -------------------------------------------------------------------------------- diff --git a/massif/tests/peak2.vgtest b/massif/tests/peak2.vgtest index a14b8be210..a5b24c52ce 100644 --- a/massif/tests/peak2.vgtest +++ b/massif/tests/peak2.vgtest @@ -1,5 +1,5 @@ prog: peak -vgopts: --stacks=no --time-unit=B -v -v --peak-inaccuracy=1000 --heap-admin=64 +vgopts: --stacks=no --time-unit=B -v -v --peak-inaccuracy=10.0 --heap-admin=64 stderr_filter: filter_verbose post: perl ../../massif/ms_print massif.out | ../../tests/filter_addresses cleanup: rm massif.out diff --git a/massif/tests/thresholds_10_0.post.exp b/massif/tests/thresholds_10_0.post.exp index e52eeb8499..bef6f8afc9 100644 --- a/massif/tests/thresholds_10_0.post.exp +++ b/massif/tests/thresholds_10_0.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./thresholds -Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=1000 +Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=10 ms_print arguments: massif.out --threshold=0 -------------------------------------------------------------------------------- diff --git a/massif/tests/thresholds_10_0.vgtest b/massif/tests/thresholds_10_0.vgtest index 2b6239dd13..c2b8b43897 100644 --- a/massif/tests/thresholds_10_0.vgtest +++ b/massif/tests/thresholds_10_0.vgtest @@ -1,4 +1,4 @@ prog: thresholds -vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=1000 +vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=10 post: perl ../../massif/ms_print massif.out --threshold=0 | ../../tests/filter_addresses cleanup: rm massif.out diff --git a/massif/tests/thresholds_10_10.post.exp b/massif/tests/thresholds_10_10.post.exp index c12ff2c595..75186076af 100644 --- a/massif/tests/thresholds_10_10.post.exp +++ b/massif/tests/thresholds_10_10.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./thresholds -Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=1000 +Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=10 ms_print arguments: massif.out --threshold=10 -------------------------------------------------------------------------------- diff --git a/massif/tests/thresholds_10_10.vgtest b/massif/tests/thresholds_10_10.vgtest index 40f05355d3..e829b08df5 100644 --- a/massif/tests/thresholds_10_10.vgtest +++ b/massif/tests/thresholds_10_10.vgtest @@ -1,4 +1,4 @@ prog: thresholds -vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=1000 +vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=10 post: perl ../../massif/ms_print massif.out --threshold=10 | ../../tests/filter_addresses cleanup: rm massif.out diff --git a/massif/tests/thresholds_5_0.post.exp b/massif/tests/thresholds_5_0.post.exp index 570d7ebc92..6ce9bdec17 100644 --- a/massif/tests/thresholds_5_0.post.exp +++ b/massif/tests/thresholds_5_0.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./thresholds -Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=500 +Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=5 ms_print arguments: massif.out --threshold=0 -------------------------------------------------------------------------------- diff --git a/massif/tests/thresholds_5_0.vgtest b/massif/tests/thresholds_5_0.vgtest index 32b5f9ce15..b313c358fb 100644 --- a/massif/tests/thresholds_5_0.vgtest +++ b/massif/tests/thresholds_5_0.vgtest @@ -1,4 +1,4 @@ prog: thresholds -vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=500 +vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=5 post: perl ../../massif/ms_print massif.out --threshold=0 | ../../tests/filter_addresses cleanup: rm massif.out diff --git a/massif/tests/thresholds_5_10.post.exp b/massif/tests/thresholds_5_10.post.exp index 67a3e3ac1d..5101a4276a 100644 --- a/massif/tests/thresholds_5_10.post.exp +++ b/massif/tests/thresholds_5_10.post.exp @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- Command: ./thresholds -Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=500 +Massif arguments: --stacks=no --time-unit=B --heap-admin=0 --threshold=5 ms_print arguments: massif.out --threshold=10 -------------------------------------------------------------------------------- diff --git a/massif/tests/thresholds_5_10.vgtest b/massif/tests/thresholds_5_10.vgtest index c7b076a3e5..615af847e3 100644 --- a/massif/tests/thresholds_5_10.vgtest +++ b/massif/tests/thresholds_5_10.vgtest @@ -1,4 +1,4 @@ prog: thresholds -vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=500 +vgopts: --stacks=no --time-unit=B --heap-admin=0 --threshold=5 post: perl ../../massif/ms_print massif.out --threshold=10 | ../../tests/filter_addresses cleanup: rm massif.out