for review: bug fix for memory profiling

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Apr 8 18:54:56 AEST 1998


library/benchmarking.m:
	Fix a bug which caused the "10 most expensive procedures/types since
	the last report" to be computed not on the basis of the number of
	words allocated since the last report, but on the number of words
	allocated so far in all of the execution.

	Fix a bug that could result in divide by zero if two reports have
	no intervening memory allocations.

Zoltan.

Index: benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.12
diff -u -u -r1.12 benchmarking.m
--- benchmarking.m	1998/02/02 02:49:57	1.12
+++ benchmarking.m	1998/04/08 07:50:38
@@ -318,9 +318,9 @@
 
 /*
 ** Insert an entry into the table of the top `table_size' entries.
-** Entries are ranked according to their words_at_period_end.
+** Entries are ranked according to their words_since_period_start.
 ** (This is an arbitrary choice; we might equally well choose
-** to order them by cells_at_period_end.  I prefer words.)
+** to order them by cells_since_period_start. I prefer words (zs).)
 ** Entries that are not in the top `table_size' are discarded.
 */
 static int
@@ -329,8 +329,8 @@
 {
 	int slot;
 
-	/* ignore entries whose counts are zero */
-	if (new_entry->counter.words_at_period_end <= 0.0) {
+	/* ignore entries whose counts are zero (allowing for rounding) */
+	if (new_entry->counter.words_since_period_start < 1.0) {
 		return next_slot;
 	}
 
@@ -341,8 +341,8 @@
 	** entry which ranks higher that the new entry.
 	*/
 	slot = next_slot;
-	while (slot > 0 && table[slot - 1].counter.words_at_period_end <
-				new_entry->counter.words_at_period_end)
+	while (slot > 0 && table[slot - 1].counter.words_since_period_start <
+				new_entry->counter.words_since_period_start)
 	{
 		slot--;
 	}
@@ -354,13 +354,13 @@
 	** (unless it is already at the end of the table).
 	*/
 	if (slot < table_size) {
-		int i;
 #if 0
 /*
 ** The following code is disabled because it causes gcc (2.7.2) internal
 ** errors (``fixed or forbidden register spilled'') on x86 machines when
 ** using gcc global register variables.
 */
+		int i;
 		for (i = table_size - 1; i > slot; i--) {
 			table[i] = table[i - 1];
 		}
@@ -442,6 +442,20 @@
 {
 	int		i;
 	const char	*name;
+
+	if (complete) {
+		if (ML_overall_counter.cells_at_period_end < 1.0
+		||  ML_overall_counter.words_at_period_end < 1.0) {
+			fprintf(stderr, ""no allocations to report\n"");
+			return;
+		}
+	} else {
+		if (ML_overall_counter.cells_since_period_start < 1.0
+		||  ML_overall_counter.words_since_period_start < 1.0) {
+			fprintf(stderr, ""no allocations to report\n"");
+			return;
+		}
+	}
 
 	if (num_entries > MAX_REPORT_LINES && !complete) {
 		num_entries = MAX_REPORT_LINES;



More information about the developers mailing list