|
From: <sv...@va...> - 2007-09-16 22:43:47
|
Author: njn
Date: 2007-09-16 23:43:41 +0100 (Sun, 16 Sep 2007)
New Revision: 6834
Log:
A few minor changes.
Modified:
branches/MASSIF2/massif/ms_main.c
branches/MASSIF2/massif/ms_print
Modified: branches/MASSIF2/massif/ms_main.c
===================================================================
--- branches/MASSIF2/massif/ms_main.c 2007-09-16 11:08:56 UTC (rev 6833)
+++ branches/MASSIF2/massif/ms_main.c 2007-09-16 22:43:41 UTC (rev 6834)
@@ -55,8 +55,7 @@
// #3: in-between
// - check every malloc, but not every new_mem_stack
//
-// Separate content from presentation by dumping all results to a file and
-// then post-processing with a separate program, a la Cachegrind?
+// Dumping the results to file:
// - work out the file format (Josef wants Callgrind format, Donna wants
// XML, Nick wants something easy to read in Perl)
// - allow truncation of long fnnames if the exact line number is
@@ -89,6 +88,8 @@
// - better sanity-checking should help this greatly
// 143062 cra massif crashes on app exit with signal 8 SIGFPE
// - occurs with no allocations -- ensure that case works
+// 144453 XXX
+// 146456 XXX
//
// Michael Meeks:
// - wants an interactive way to request a dump (callgrind_control-style)
@@ -110,6 +111,7 @@
// start-up and our first use of it. Could normalise versus our first
// use...
// - could conceivably remove XPts that have their szB reduced to zero.
+// - allow the output file name to be changed
//
// Docs:
// - need to explain that --alloc-fn changed slightly -- now if an entry
@@ -321,23 +323,12 @@
//--- Globals ---//
//------------------------------------------------------------//
-#define FILENAME_LEN 256
-
#define P VG_(printf)
-#define SPRINTF(zz_buf, fmt, args...) \
- do { Int len = VG_(sprintf)(zz_buf, fmt, ## args); \
- VG_(write)(fd, (void*)zz_buf, len); \
- } while (0)
-
-#define BUF_LEN 1024 // general purpose
-static Char buf [BUF_LEN];
-static Char buf2[BUF_LEN];
-
// Make these signed so things are more obvious if they go negative.
static SSizeT sigstacks_szB = 0; // Current signal stacks space sum
static SSizeT heap_szB = 0; // Live heap size
-static SSizeT peak_heap_szB = 0; // XXX: currently unused
+static SSizeT peak_heap_szB = 0; // XXX: currently unused
static SSizeT peak_snapshot_total_szB = 0;
static VgHashTable malloc_list = NULL; // HP_Chunks
@@ -345,7 +336,7 @@
static UInt n_heap_blocks = 0;
// Current directory at startup.
-static Char base_dir[VKI_PATH_MAX];
+static Char base_dir[VKI_PATH_MAX]; // XXX: currently unused
#define MAX_ALLOC_FNS 128 // includes the builtin ones
@@ -356,6 +347,12 @@
// operator new[](unsigned)
// operator new(unsigned, std::nothrow_t const&)
// operator new[](unsigned, std::nothrow_t const&)
+// [Dennis Lubert says these are also necessary on AMD64:
+// "operator new(unsigned long)",
+// "operator new[](unsigned long)",
+// "operator new(unsigned long, std::nothrow_t const&)",
+// "operator new[](unsigned long, std::nothrow_t const&)",
+// ]
// But someone might be interested in seeing them. If they're not, they can
// specify them with --alloc-fn.
static UInt n_alloc_fns = 6;
@@ -688,6 +685,9 @@
// Filter uninteresting entries out of the stack trace. n_ips is
// updated accordingly.
for (i = n_ips-1; i >= 0; i--) {
+ #define BUF_LEN 1024
+ Char buf[BUF_LEN];
+
if (VG_(get_fnname)(ips[i], buf, BUF_LEN)) {
// If it's a main-or-below-main function, we (may) want to
@@ -1388,8 +1388,11 @@
Int depth_str_len,
SizeT curr_heap_szB, SizeT curr_total_szB)
{
+ #define BUF_LEN 1024
Int i;
- Char* ip_desc, *perc;
+ Char* perc;
+ Char ip_desc_array[BUF_LEN];
+ Char* ip_desc = ip_desc_array;
SizeT printed_children_szB = 0;
Int n_sig_children;
Int n_insig_children;
@@ -1397,6 +1400,7 @@
// If the XPt has children, check that the sum of all their sizes equals
// the XPt's size.
+ // XXX: duplicates code from the sanity check?
if (xpt->n_children > 0) {
SizeT children_sum_szB = 0;
for (i = 0; i < xpt->n_children; i++) {
@@ -1425,7 +1429,7 @@
ip_desc =
"(heap allocation functions) malloc/new/new[], --alloc-fns, etc.";
} else {
- ip_desc = VG_(describe_IP)(xpt->ip-1, buf2, BUF_LEN);
+ ip_desc = VG_(describe_IP)(xpt->ip-1, ip_desc, BUF_LEN);
}
perc = make_perc(xpt->curr_szB, curr_total_szB);
P("%sn%d: %ld %s\n", depth_str, n_child_entries, xpt->curr_szB, ip_desc);
@@ -1490,6 +1494,7 @@
}
}
+// XXX: rename
static void write_detailed_snapshots(void)
{
Int i;
Modified: branches/MASSIF2/massif/ms_print
===================================================================
--- branches/MASSIF2/massif/ms_print 2007-09-16 11:08:56 UTC (rev 6833)
+++ branches/MASSIF2/massif/ms_print 2007-09-16 22:43:41 UTC (rev 6834)
@@ -118,7 +118,7 @@
# Input file name
my $input_file = undef;
-# Version number XXX
+# Version number
my $version = "XXX";
# Usage message.
@@ -227,33 +227,70 @@
return equals_num_line($line, $fieldname);
}
+sub is_significant_XPt($$)
+{
+ my ($xpt_szB, $total_szB) = @_;
+ ($xpt_szB <= $total_szB) or die;
+ return ( $xpt_szB * 100 / $total_szB >= $threshold ? 1 : 0 );
+}
+
# Forward declaration, because it's recursive.
sub read_heap_tree($$$$$);
+# Return pair: if the tree was significant, both are zero. If it was
+# insignificant, the first element is 1 and the second is the number of
+# bytes.
sub read_heap_tree($$$$$)
{
- # We precede this node's line with "$this_prefix.$arrow". We precede
- # any children of this node with "$this_prefix$child_midfix$arrow".
+ # Read the line and determine if it is significant.
my ($print, $this_prefix, $child_midfix, $arrow, $mem_total_B) = @_;
my $line = get_line();
(defined $line and $line =~ /^\s*n(\d+):\s*(\d+)(.*)$/)
or die("Line $.: expected a tree node line, got:\n$line\n");
- my $n = $1;
- my $bytes = $2;
- my $details = $3;
- my $perc = 100 * $bytes / $mem_total_B;
- printf("$this_prefix$arrow%05.2f%% (${bytes}B)$details\n", $perc)
- if $print;
- for (my $i = 0; $i < $n; $i++) {
- my $this_prefix2 = $this_prefix . $child_midfix;
+ my $n_children = $1;
+ my $bytes = $2;
+ my $details = $3;
+ my $perc = 100 * $bytes / $mem_total_B;
+ my $is_significant = is_significant_XPt($bytes, $mem_total_B);
+
+ # We precede this node's line with "$this_prefix.$arrow". We precede
+ # any children of this node with "$this_prefix$child_midfix$arrow".
+ if ($print && $is_significant) {
+ printf("$this_prefix$arrow%05.2f%% $is_significant(${bytes}B)$details\n", $perc);
+ }
+
+ # Now read all the children.
+ my $n_insig_children = 0;
+ my $total_insig_children_szB = 0;
+ my $this_prefix2 = $this_prefix . $child_midfix;
+ for (my $i = 0; $i < $n_children; $i++) {
# If child is the last sibling, the midfix is empty.
- my $child_midfix2 = ( $i+1 == $n ? " " : "| " );
- read_heap_tree($print, $this_prefix2, $child_midfix2, "->",
- $mem_total_B);
+ my $child_midfix2 = ( $i+1 == $n_children ? " " : "| " );
+ my ($is_child_insignificant, $child_insig_bytes) =
+ read_heap_tree($print, $this_prefix2, $child_midfix2, "->",
+ $mem_total_B);
+ $n_insig_children += $is_child_insignificant;
+ $total_insig_children_szB += $child_insig_bytes;
}
- # If this node has no children, print an extra empty line.
- if (0 == $n) {
- print("$this_prefix\n") if $print;
+
+ if ($is_significant) {
+ # If this was significant but any children were insignificant, print
+ # an "insignificant" line for them.
+ if ($print && $n_insig_children > 0) {
+ $perc = 100 * $total_insig_children_szB / $mem_total_B;
+ printf("$this_prefix2->%05.2f%% (${total_insig_children_szB}B) ... $n_insig_children insig...\n",
+ $perc);
+ print("$this_prefix2\n");
+ }
+
+ # If this node has no children, print an extra empty line.
+ if ($print && 0 == $n_children) {
+ print("$this_prefix\n");
+ }
+ return (0, 0);
+
+ } else {
+ return (1, $bytes);
}
}
@@ -343,7 +380,7 @@
# Row 0 ([0..GRAPH_X][0]) is the x-axis.
# Column 0 ([0][0..GRAPH_Y]) is the y-axis.
# The rest ([1][1]..[GRAPH_X][GRAPH_Y]) is the usable graph area.
- my $GRAPH_X = 72;
+ my $GRAPH_X = 72; # Make these command-line options
my $GRAPH_Y = 20;
my @graph;
my $x;
|