]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
- Make other integer CLO macros more correct, as I did for VG_NUM_CLO in the
authorNicholas Nethercote <njn@valgrind.org>
Sun, 11 Nov 2007 22:15:58 +0000 (22:15 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sun, 11 Nov 2007 22:15:58 +0000 (22:15 +0000)
  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

12 files changed:
include/pub_tool_options.h
massif/ms_main.c
massif/tests/peak2.post.exp
massif/tests/peak2.vgtest
massif/tests/thresholds_10_0.post.exp
massif/tests/thresholds_10_0.vgtest
massif/tests/thresholds_10_10.post.exp
massif/tests/thresholds_10_10.vgtest
massif/tests/thresholds_5_0.post.exp
massif/tests/thresholds_5_0.vgtest
massif/tests/thresholds_5_10.post.exp
massif/tests/thresholds_5_10.vgtest

index e39526047a398a1852434567722e020f589b2b98..364206dfd88bd5296d42c7c45de4d76185a3fa2a 100644 (file)
    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)) { \
index 0f8aba81bf97e070d9eb1cc8a4359fe296cb50a7..103d27e8c89d61738d015ba633642c1dff260282 100644 (file)
 // 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=<number>          depth of contexts [30]\n"
 "    --alloc-fn=<name>         specify <fn> as an alloc function [empty]\n"
-"    --threshold=<n>           significance threshold, in 100ths of a percent\n"
-"                              (eg. <n>=100 shows nodes covering >= 1%% of\n"
-"                               total size, <n>=0 shows all nodes) [100]\n"
-"    --peak-inaccuracy=<n>     closeness of recorded peak to true peak,\n"
-"                               in 100ths of a percent\n"
+"    --threshold=<m.n>         significance threshold, as a percentage [1.0]\n"
+"    --peak-inaccuracy=<m.n>   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=<N>       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) {
index e3e5a599ab32f02f78a2c6d69159511fdabcafd6..736850cfc12f4dcf978529b60da805eebc612fcb 100644 (file)
@@ -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
 --------------------------------------------------------------------------------
 
index a14b8be21054fbb1a690e330d47c9eff2bd8b64c..a5b24c52cef803541cb10517ffe6a89676ec3504 100644 (file)
@@ -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
index e52eeb849942e0b67114a9ac4034b9100890c14a..bef6f8afc9e5a656033208f8e76b02879206be0f 100644 (file)
@@ -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
 --------------------------------------------------------------------------------
 
index 2b6239dd134f029dc5295cdbbede6e6663100c3d..c2b8b43897b110ef8a7315179daee6bb16325edb 100644 (file)
@@ -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
index c12ff2c595cddc0dbe78d70c0c6b3301bbb3e152..75186076afec36516d81278b9e1adcc9d38736d8 100644 (file)
@@ -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
 --------------------------------------------------------------------------------
 
index 40f05355d3bf46c0e2e0a405041b3200902fa186..e829b08df5c1829c350200041076598ec2f39d51 100644 (file)
@@ -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
index 570d7ebc9285740b49d65e729a18b59d16e8de72..6ce9bdec17074a3a4f6d5e9163d498b8db25537d 100644 (file)
@@ -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
 --------------------------------------------------------------------------------
 
index 32b5f9ce150c8160c71bd841b0f1dce37ebb6490..b313c358fbdddd9ddfa9214ce453e85100e3ce3b 100644 (file)
@@ -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
index 67a3e3ac1d272be45e1c59e723fc78cdea3be0ad..5101a4276a965ce5b12bed6887fec1be89a144b6 100644 (file)
@@ -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
 --------------------------------------------------------------------------------
 
index c7b076a3e57d090e5371c0d6685cf81bb01a2fca..615af847e37965c265b9fed4e602e33223dd1471 100644 (file)
@@ -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