Author: njn
Date: 2007-09-23 02:14:25 +0100 (Sun, 23 Sep 2007)
New Revision: 6904

Log:
Got realloc working, added a test for it.

Added:
   branches/MASSIF2/massif/tests/realloc.c
   branches/MASSIF2/massif/tests/realloc.post.exp
   branches/MASSIF2/massif/tests/realloc.stderr.exp
   branches/MASSIF2/massif/tests/realloc.vgtest
Modified:
   branches/MASSIF2/massif/ms_main.c
   branches/MASSIF2/massif/ms_print
   branches/MASSIF2/massif/tests/Makefile.am
   branches/MASSIF2/massif/tests/culling1.stderr.exp
   branches/MASSIF2/massif/tests/culling2.stderr.exp


Modified: branches/MASSIF2/massif/ms_main.c
===================================================================
--- branches/MASSIF2/massif/ms_main.c   2007-09-23 00:55:20 UTC (rev 6903)
+++ branches/MASSIF2/massif/ms_main.c   2007-09-23 01:14:25 UTC (rev 6904)
@@ -31,7 +31,7 @@
 // XXX:
 //---------------------------------------------------------------------------
 // Todo:
-// - do a test for realloc -- I think no snapshots are being taken for it.
+// - do a graph-drawing test
 // - do tests with complicated stack traces -- big ones, ones that require
 //   XCon_redo, ones that exceed --depth, etc.
 // - test what happens when alloc-fns cover an entire trace
@@ -236,6 +236,7 @@
 static UInt n_dupd_xpts_freed      = 0;
 static UInt n_allocs               = 0;
 static UInt n_zero_allocs          = 0;
+static UInt n_reallocs             = 0;
 static UInt n_frees                = 0;
 static UInt n_xpt_init_expansions  = 0;
 static UInt n_xpt_later_expansions = 0;
@@ -1282,6 +1283,9 @@
    SizeT     old_size;
    XPt      *old_where, *new_where;
    
+   // Update statistics
+   n_reallocs++;
+
    // Remove the old block
    hc = VG_(HT_remove)(malloc_list, (UWord)p_old);
    if (hc == NULL) {
@@ -1329,6 +1333,9 @@
    // than growing it, and this way simplifies the growing case.
    VG_(HT_add_node)(malloc_list, hc);
 
+   // Do a snapshot!
+   take_snapshot("realloc");
+
    return p_new;
 }
  
@@ -1666,6 +1673,7 @@
       VERB("zeroallocs:           %u (%d%%)",                     
          n_zero_allocs,                                      
          ( n_allocs ? n_zero_allocs * 100 / n_allocs : 0 )); 
+      VERB("reallocs:             %u", n_reallocs);                     
       VERB("frees:                %u", n_frees);
       VERB("XPts:                 %u", n_xpts);
       VERB("top-XPts:             %u (%d%%)",                     

Modified: branches/MASSIF2/massif/ms_print
===================================================================
--- branches/MASSIF2/massif/ms_print    2007-09-23 00:55:20 UTC (rev 6903)
+++ branches/MASSIF2/massif/ms_print    2007-09-23 01:14:25 UTC (rev 6904)
@@ -30,6 +30,8 @@
 use warnings;
 use strict;
 
+# XXX: need to label axes with the unit
+
 #----------------------------------------------------------------------------
 # Global variables, main data structures
 #----------------------------------------------------------------------------

Modified: branches/MASSIF2/massif/tests/Makefile.am
===================================================================
--- branches/MASSIF2/massif/tests/Makefile.am   2007-09-23 00:55:20 UTC (rev 
6903)
+++ branches/MASSIF2/massif/tests/Makefile.am   2007-09-23 01:14:25 UTC (rev 
6904)
@@ -13,6 +13,7 @@
         culling2.stderr.exp culling2.vgtest \
        long-time.post.exp long-time.stderr.exp long-time.vgtest \
        null.post.exp null.stderr.exp null.vgtest \
+       realloc.post.exp realloc.stderr.exp realloc.vgtest \
        thresholds_0_0.post.exp   thresholds_0_0.stderr.exp   
thresholds_0_0.vgtest \
        thresholds_0_10.post.exp  thresholds_0_10.stderr.exp  
thresholds_0_10.vgtest \
        thresholds_10_0.post.exp  thresholds_10_0.stderr.exp  
thresholds_10_0.vgtest \
@@ -32,6 +33,7 @@
        culling1 culling2 \
        long-time \
        null \
+       realloc \
        thresholds \
        zero
 

Modified: branches/MASSIF2/massif/tests/culling1.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/culling1.stderr.exp   2007-09-23 00:55:20 UTC 
(rev 6903)
+++ branches/MASSIF2/massif/tests/culling1.stderr.exp   2007-09-23 01:14:25 UTC 
(rev 6904)
@@ -363,6 +363,7 @@
 Massif: New time interval = 40 (between snapshots 0 and 1)
 Massif: allocs:               200
 Massif: zeroallocs:           0 (0%)
+Massif: reallocs:             0
 Massif: frees:                0
 Massif: XPts:                 2
 Massif: top-XPts:             1 (50%)

Modified: branches/MASSIF2/massif/tests/culling2.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/culling2.stderr.exp   2007-09-23 00:55:20 UTC 
(rev 6903)
+++ branches/MASSIF2/massif/tests/culling2.stderr.exp   2007-09-23 01:14:25 UTC 
(rev 6904)
@@ -516,6 +516,7 @@
 Massif: New time interval = 284 (between snapshots 1 and 2)
 Massif: allocs:               200
 Massif: zeroallocs:           1 (0%)
+Massif: reallocs:             0
 Massif: frees:                0
 Massif: XPts:                 2
 Massif: top-XPts:             1 (50%)

Added: branches/MASSIF2/massif/tests/realloc.c
===================================================================
--- branches/MASSIF2/massif/tests/realloc.c                             (rev 0)
+++ branches/MASSIF2/massif/tests/realloc.c     2007-09-23 01:14:25 UTC (rev 
6904)
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+
+int main(void)
+{
+   int* x = realloc(NULL, 100);  // equivalent to malloc(100), and ends up
+                                 // calling Valgrind's (and Massif's) malloc
+
+   x = realloc(x, 100);          // same size
+
+   x = realloc(x, 50);           // smaller
+
+   x = realloc(x, 150);          // bigger
+
+   realloc(x+10, 200);           // bogus realloc
+
+   x = realloc(x, 0);            // equivalent to free(x), and ends up
+                                 // calling Valgrind's (and Massif's) free
+   return 0;
+}

Added: branches/MASSIF2/massif/tests/realloc.post.exp
===================================================================
--- branches/MASSIF2/massif/tests/realloc.post.exp                              
(rev 0)
+++ branches/MASSIF2/massif/tests/realloc.post.exp      2007-09-23 01:14:25 UTC 
(rev 6904)
@@ -0,0 +1,41 @@
+--------------------------------------------------------------------------------
+Command:            ./realloc
+Massif arguments:   --stacks=no --heap-admin=0 --time-unit=B
+ms_print arguments: massif.out
+--------------------------------------------------------------------------------
+
+
+150 |                                            :                           
+    |                                            :                           
+    |                                            :                           
+    |                                            :                           
+    |                                            :                           
+    |                                            :                           
+    |                                            :                           
+    |                 :                          :                           
+    |                 :                          :                           
+    |                 :                          :                           
+    |                 :                          :                           
+    |                 :                          :                           
+    |                 :                          :                           
+    |                 :        .                 :                           
+    |                 :        :                 :                           
+    |                 :        :                 :                           
+    |                 :        :                 :                           
+    |                 :        :                 :                           
+    |                 :        :                 :                           
+    |                 :        :                 :                           
+  0 +------------------------------------------------------------------------
+
+
+Number of snapshots: 6
+ Detailed snapshots: []
+--------------------------------------------------------------------------------
+  n        time(B)         total(B)   useful-heap(B) admin-heap(B)    stacks(B)
+--------------------------------------------------------------------------------
+  0              0                0                0             0            0
+  1            100              100              100             0            0
+  2            100              100              100             0            0
+  3            150               50               50             0            0
+  4            250              150              150             0            0
+  5            400                0                0             0            0

Added: branches/MASSIF2/massif/tests/realloc.stderr.exp
===================================================================
--- branches/MASSIF2/massif/tests/realloc.stderr.exp                            
(rev 0)
+++ branches/MASSIF2/massif/tests/realloc.stderr.exp    2007-09-23 01:14:25 UTC 
(rev 6904)
@@ -0,0 +1,27 @@
+Massif: alloc-fns:
+Massif:   1: calloc
+Massif:   2: realloc
+Massif:   3: memalign
+Massif:   4: __builtin_new
+Massif:   5: __builtin_vec_new
+Massif:   6: malloc
+Massif: startup snapshot   0 (t = 0 B)
+Massif:   alloc snapshot   1 (t = 100 B)
+Massif: realloc snapshot   2 (t = 100 B)
+Massif: realloc snapshot   3 (t = 150 B)
+Massif: realloc snapshot   4 (t = 250 B)
+Massif: dealloc snapshot   5 (t = 400 B)
+Massif: allocs:               1
+Massif: zeroallocs:           0 (0%)
+Massif: reallocs:             4
+Massif: frees:                1
+Massif: XPts:                 5
+Massif: top-XPts:             4 (80%)
+Massif: dup'd XPts:           0
+Massif: dup'd/freed XPts:     0
+Massif: XPt-init-expansions:  1
+Massif: XPt-later-expansions: 0
+Massif: skipped snapshots:    0
+Massif: real snapshots:       6
+Massif: cullings:             0
+Massif: XCon_redos:           0

Added: branches/MASSIF2/massif/tests/realloc.vgtest
===================================================================
--- branches/MASSIF2/massif/tests/realloc.vgtest                                
(rev 0)
+++ branches/MASSIF2/massif/tests/realloc.vgtest        2007-09-23 01:14:25 UTC 
(rev 6904)
@@ -0,0 +1,5 @@
+prog: realloc
+vgopts: -v --stacks=no --heap-admin=0 --time-unit=B
+stderr_filter: filter_verbose
+post: perl ../../massif/ms_print massif.out
+cleanup: rm massif.out


-------------------------------------------------------------------------
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

Reply via email to