[m-rev.] [reuse] diff: cell cache statistics

Peter Ross peter.ross at miscrit.be
Mon Mar 19 17:29:38 AEDT 2001


Hi,


===================================================================


Estimated hours taken: 2
Branches: reuse

Collect statistics about compile time garbage collection.

compiler/mlds_to_c.m:
    For each delete_object instruction, record that a cell becomes available
    for reuse due to compile time gc.  While for each new_object check
    to see if there would have been a compile time gc'd cell available.

library/benchmarking.m:
    Add an option to report stats which outputs the cell cache
    statistics.

runtime/mercury_memory.c:
runtime/mercury_memory.h:
    Add functions to record statistics about compile time gc cell reuse.


Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.55.2.9
diff -u -r1.55.2.9 mlds_to_c.m
--- compiler/mlds_to_c.m	2001/03/18 16:56:51	1.55.2.9
+++ compiler/mlds_to_c.m	2001/03/19 06:19:12
@@ -2390,15 +2390,13 @@
 	%
 	% heap management
 	%
-mlds_output_atomic_stmt(_Indent, _FuncInfo, delete_object(_Lval, _Size), _) -->
-	[].
-	% Commented out until MR_compile_time_gc implemented.
-	% mlds_indent(Indent),
-	% io__write_string("MR_compile_time_gc(MR_strip_tag("),
-	% mlds_output_lval(Lval),
-	% io__write_string("), "),
-	% io__write_int(Size),
-	% io__write_string(");\n").
+mlds_output_atomic_stmt(Indent, _FuncInfo, delete_object(Lval, Size), _) -->
+	mlds_indent(Indent),
+	io__write_string("MR_compile_time_gc(MR_strip_tag("),
+	mlds_output_lval(Lval),
+	io__write_string("), "),
+	io__write_int(Size),
+	io__write_string(");\n").
 
 mlds_output_atomic_stmt(Indent, FuncInfo, NewObject, Context) -->
 	{ NewObject = new_object(Target, MaybeTag, Type, MaybeSize,
@@ -2406,7 +2404,6 @@
 	mlds_indent(Indent),
 	io__write_string("{\n"),
 
-	/* XXX measure how likely we are to reuse a cgc cell
 	mlds_indent(Context, Indent + 1),
 	io__write_string("MR_update_cell_cache_statistics("),
 	( { MaybeSize = yes(LSize) } ->
@@ -2416,7 +2413,6 @@
 		io__write_int(-1)
 	),
 	io__write_string(");\n"),
-	*/
 
 	{ FuncInfo = func_info(FuncName, _) },
 	mlds_maybe_output_heap_profile_instr(Context, Indent + 1, Args,
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.34.4.3
diff -u -r1.34.4.3 benchmarking.m
--- library/benchmarking.m	2001/03/18 17:45:08	1.34.4.3
+++ library/benchmarking.m	2001/03/19 06:19:27
@@ -259,6 +259,11 @@
 
 #endif /* PROFILE_MEMORY */
 
+	/*
+	** Cell cache statistics.
+	*/
+	MR_output_cell_cache_stats();
+
 	fprintf(stderr, ""]\\n"");
 }
 
Index: runtime/mercury_memory.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.c,v
retrieving revision 1.19.4.4
diff -u -r1.19.4.4 mercury_memory.c
--- runtime/mercury_memory.c	2001/02/07 14:33:52	1.19.4.4
+++ runtime/mercury_memory.c	2001/03/19 06:19:28
@@ -364,3 +364,83 @@
 }
 
 /*---------------------------------------------------------------------------*/
+
+/*
+** Compile time garbage collection code.
+** Currently this just records statistics.
+*/
+#define MR_MAX_CACHED_CELL_SIZE		10
+
+typedef struct s_cell_cache_stats
+{
+	int	length;
+	int 	hits;
+	int	misses;
+	int	sum_length;
+	int	max_length;
+} cell_cache_stats;
+
+static cell_cache_stats stats[MR_MAX_CACHED_CELL_SIZE + 1];
+
+void record_stats(size_t size);
+
+void MR_compile_time_gc(MR_Word cell, size_t size)
+{
+	if (size <= MR_MAX_CACHED_CELL_SIZE) {
+		record_stats(size);
+	}
+}
+
+void MR_update_cell_cache_statistics(size_t size)
+{
+	if (size <= MR_MAX_CACHED_CELL_SIZE) {
+		stats[size].sum_length += stats[size].length;
+
+		if (stats[size].length == 0) {
+			stats[size].misses++;
+		} else {
+			stats[size].length--;
+			stats[size].hits++;
+		}
+	}
+}
+
+void record_stats(size_t size)
+{
+	stats[size].length++;
+
+	if (stats[size].length > stats[size].max_length) {
+		stats[size].max_length = stats[size].length;
+	}
+}
+
+void MR_output_cell_cache_stats(void)
+{
+	int i = 0;
+	int hits, misses, total, sum_length, max_length;
+	float hit_proportion, average_cache_length;
+
+	printf("\n\n%6s %6s %6s %7s %7s %6s\n", "size", "avg",
+			"max", "hits", "total", "%");
+	for (i = 1; i <= MR_MAX_CACHED_CELL_SIZE; i++)
+	{
+		hits = stats[i].hits;
+		misses = stats[i].misses;
+		sum_length = stats[i].sum_length;
+		max_length = stats[i].max_length;
+		total = hits + misses;
+		if (total > 0) {
+			hit_proportion = hits / (float) total;
+			average_cache_length = sum_length / total;
+			
+		} else {
+			hit_proportion = 0.0;
+			average_cache_length = 0.0;
+		}
+		printf("%6d %6.2f %6d %7d/%7d %6.2f\n", i,
+				average_cache_length, max_length,
+				hits, total, 100 * hit_proportion);
+	}
+}
+
+/*---------------------------------------------------------------------------*/
Index: runtime/mercury_memory.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory.h,v
retrieving revision 1.12.2.2
diff -u -r1.12.2.2 mercury_memory.h
--- runtime/mercury_memory.h	2001/02/07 14:33:53	1.12.2.2
+++ runtime/mercury_memory.h	2001/03/19 06:19:29
@@ -189,4 +189,10 @@
 
 /*---------------------------------------------------------------------------*/
 
+void MR_compile_time_gc(MR_Word cell, size_t size);
+void MR_update_cell_cache_statistics(size_t size);
+void MR_output_cell_cache_stats(void);
+
+/*---------------------------------------------------------------------------*/
+
 #endif /* not MERCURY_MEMORY_H */

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list