|
From: <sv...@va...> - 2007-09-17 07:15:16
|
Author: njn
Date: 2007-09-17 08:15:15 +0100 (Mon, 17 Sep 2007)
New Revision: 6846
Log:
Allow time to be measured either in milliseconds or bytes
allocated/deallocated on the heap. The latter will be very useful for
testing as it allows deterministic runs. There are still some places that
talk about 'ms' that should be parameterised.
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-17 06:43:58 UTC (rev 6845)
+++ branches/MASSIF2/massif/ms_main.c 2007-09-17 07:15:15 UTC (rev 6846)
@@ -266,7 +266,10 @@
typedef
struct {
- Int time_ms; // Int: must allow -1.
+ // Time is measured either in ms or bytes, depending on the
+ // --time-unit option. It's a Long because it can get very big with
+ // --time-unit=ms.
+ Long time; // Long: must allow -1.
SizeT total_szB; // Size of all allocations at that snapshot time.
SizeT heap_admin_szB;
SizeT heap_szB;
@@ -331,6 +334,11 @@
static SSizeT peak_heap_szB = 0; // XXX: currently unused
static SSizeT peak_snapshot_total_szB = 0;
+// Incremented every time memory is allocated/deallocated, by the
+// allocated/deallocated amount. An alternative unit of program progress to
+// time.
+static ULong total_allocs_deallocs_szB = 0;
+
static VgHashTable malloc_list = NULL; // HP_Chunks
static UInt n_heap_blocks = 0;
@@ -395,11 +403,14 @@
#define MAX_DEPTH 50
+typedef enum { TimeMS, TimeB } TimeUnit;
+
static Bool clo_heap = True;
static UInt clo_heap_admin = 8;
static Bool clo_stacks = True;
static Bool clo_depth = 8;
static UInt clo_threshold = 100; // 100 == 1%
+static UInt clo_time_unit = TimeMS;
static Bool ms_process_cmd_line_option(Char* arg)
{
@@ -411,6 +422,9 @@
else VG_NUM_CLO(arg, "--threshold", clo_threshold)
+ else if (VG_CLO_STREQ(arg, "--time-unit=ms")) clo_time_unit = TimeMS;
+ else if (VG_CLO_STREQ(arg, "--time-unit=B")) clo_time_unit = TimeB;
+
else if (VG_CLO_STREQN(11, arg, "--alloc-fn=")) {
VG_(OSetWord_Insert)(alloc_fns, (Word) & arg[11]);
}
@@ -432,6 +446,8 @@
" --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"
+" --time-unit=ms|B time unit, milliseconds or bytes\n"
+" alloc'd/dealloc'd on the heap [ms]\n"
);
VG_(replacement_malloc_print_usage)();
}
@@ -650,7 +666,7 @@
Bool should_hide_below_main = /*!VG_(clo_show_below_main)*/True;
// We ask for a few more IPs than clo_depth suggests we need. Then we
- // remove every entry that is an alloc-fns or above an alloc-fn, and
+ // remove every entry that is an alloc-fn or above an alloc-fn, and
// remove anything below main-or-below-main functions. Depending on the
// circumstances, we may need to redo it all, asking for more IPs.
// Details:
@@ -710,7 +726,8 @@
}
n_alloc_fns_removed = i+1;
- for (j = 0; j < n_ips; j++) { // Shuffle the rest down.
+ // Shuffle the rest down.
+ for (j = 0; j < n_ips; j++) {
ips[j] = ips[j + n_alloc_fns_removed];
}
n_ips -= n_alloc_fns_removed;
@@ -719,7 +736,7 @@
}
}
- // Must be at least one alloc function, unless client used
+ // There must be at least one alloc function, unless client used
// MALLOCLIKE_BLOCK.
if (!is_custom_malloc)
tl_assert2(n_alloc_fns_removed > 0,
@@ -736,7 +753,6 @@
enough_IPs_after_filtering)
{
return n_ips;
-
} else {
n_getXCon_redo++;
}
@@ -811,8 +827,8 @@
static Bool is_snapshot_in_use(Snapshot* snapshot)
{
- if (-1 == snapshot->time_ms) {
- // If .time_ms looks unused, check everything else is.
+ if (-1 == snapshot->time) {
+ // If .time looks unused, check everything else is.
tl_assert(snapshot->total_szB == 0);
tl_assert(snapshot->heap_admin_szB == 0);
tl_assert(snapshot->heap_szB == 0);
@@ -855,7 +871,7 @@
static void clear_snapshot(Snapshot* snapshot)
{
sanity_check_snapshot(snapshot);
- snapshot->time_ms = -1;
+ snapshot->time = -1;
snapshot->total_szB = 0;
snapshot->heap_admin_szB = 0;
snapshot->heap_szB = 0;
@@ -915,7 +931,7 @@
FIND_SNAPSHOT(1, j);
FIND_SNAPSHOT(j+1, jn);
while (jn < MAX_N_SNAPSHOTS) {
- Int timespan = snapshots[jn].time_ms - snapshots[jp].time_ms;
+ Int timespan = snapshots[jn].time - snapshots[jp].time;
tl_assert(timespan >= 0);
if (timespan < min_span) {
min_span = timespan;
@@ -957,18 +973,25 @@
// [XXX: is that still true?]
static void take_snapshot(void)
{
- static UInt interval_ms = 5;
- static UInt ms_prev_snapshot = 0;
- static UInt ms_next_snapshot = 0; // zero allows startup snapshot
+ static UInt time_interval = 5;
+ static UInt time_of_prev_snapshot = 0;
+ static UInt time_of_next_snapshot = 0; // zero allows startup snapshot
static Int n_snapshots_since_last_detailed = 0;
- Int time_ms, time_ms_since_prev;
+ Int time, time_since_prev, time_ms;
Snapshot* snapshot;
+ // For measuring how long the snapshot took (used with -v).
+ time_ms = VG_(read_millisecond_timer)();
+
+ // Get current time, in whatever time unit we're using.
+ if (clo_time_unit == TimeMS) time = VG_(read_millisecond_timer)();
+ else if (clo_time_unit == TimeB) time = total_allocs_deallocs_szB;
+ else tl_assert2(0, "bad --time-unit value");
+
// Only do a snapshot if it's time.
- time_ms = VG_(read_millisecond_timer)();
- time_ms_since_prev = time_ms - ms_prev_snapshot;
- if (time_ms < ms_next_snapshot) {
+ time_since_prev = time - time_of_prev_snapshot;
+ if (time < time_of_next_snapshot) {
n_fake_snapshots++;
return;
}
@@ -1009,7 +1032,7 @@
}
// Finish writing snapshot ------------------------------------------
- snapshot->time_ms = time_ms;
+ snapshot->time = time;
snapshot->total_szB =
snapshot->heap_szB + snapshot->heap_admin_szB + snapshot->stacks_szB;
@@ -1031,7 +1054,7 @@
// Halve the entries, if our snapshot table is full
if (MAX_N_SNAPSHOTS == next_snapshot) {
halve_snapshots();
- interval_ms *= 2;
+ time_interval *= 2;
}
// Take time for next snapshot from now, rather than when this snapshot
@@ -1039,11 +1062,11 @@
// operation, there's no point doing catch-up snapshots every allocation
// for a while -- that would just give N snapshots at almost the same time.
if (VG_(clo_verbosity) > 1) {
- VG_(message)(Vg_DebugMsg, "snapshot: %d ms (took %d ms)", time_ms,
+ VG_(message)(Vg_DebugMsg, "snapshot: %d %s (took %d ms)", time_ms,
VG_(read_millisecond_timer)() - time_ms );
}
- ms_prev_snapshot = time_ms;
- ms_next_snapshot = time_ms + interval_ms;
+ time_of_prev_snapshot = time;
+ time_of_next_snapshot = time + time_interval;
}
@@ -1078,6 +1101,9 @@
if (heap_szB > peak_heap_szB) {
peak_heap_szB = heap_szB;
}
+
+ if (heap_szB_delta < 0) total_allocs_deallocs_szB -= heap_szB_delta;
+ if (heap_szB_delta > 0) total_allocs_deallocs_szB += heap_szB_delta;
}
static
@@ -1466,7 +1492,8 @@
P("#--------------------------------\n");
P("snapshot=%d\n", snapshot_n);
P("#--------------------------------\n");
- P("time_ms=%lu\n", snapshot->time_ms);
+ // XXX: shouldn't print 'time_ms' now that time can be measured in bytes.
+ P("time_ms=%lu\n", snapshot->time);
P("mem_total_B=%lu\n", snapshot->total_szB);
P("mem_heap_B=%lu\n", snapshot->heap_szB);
P("mem_heap_admin_B=%lu\n", snapshot->heap_admin_szB);
Modified: branches/MASSIF2/massif/ms_print
===================================================================
--- branches/MASSIF2/massif/ms_print 2007-09-17 06:43:58 UTC (rev 6845)
+++ branches/MASSIF2/massif/ms_print 2007-09-17 07:15:15 UTC (rev 6846)
@@ -257,7 +257,7 @@
# 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);
+ printf("$this_prefix$arrow%05.2f%% (${bytes}B)$details\n", $perc);
}
# Now read all the children.
@@ -488,7 +488,8 @@
#-------------------------------------------------------------------------
print("\n");
for (my $i = 0; $i < $n_snapshots; $i++) {
- # XXX adjust the column widths dynamically
+ # XXX: adjust the column widths dynamically
+ # XXX: assuming ms as the time-unit
printf(" snapshot %3d: t = %12s ms, size = %12s bytes\n",
$snapshot_nums[$i], commify($time_mss[$i]),
commify($mem_total_Bs[$i]));
@@ -533,6 +534,7 @@
# Print snapshot header.
printf("=================================\n");
+ # XXX: assuming ms as the time-unit
printf("== snapshot $snapshot_num (%s ms)\n", commify($time_ms));
printf("=================================\n");
printf("Total memory usage: %12s bytes\n", commify($mem_total_B));
|