[m-rev.] Re: for review: user-friendly representation of streams

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 25 20:31:47 AEST 2002


On 25-Sep-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> 
> - The changes to library/benchmarking.m are not mentioned
>   in the log message.

Sorry, that one was my mistake.  I missed part of this change.
Here's the rest of this change.

I have no new comments about this part, but some of my comments about
the earlier part also apply here.

----------

library/benchmarking.m:
library/table_builtin.m:
runtime/mercury_tabling.[ch]:
	Change the predicates that report stats to return them as strings.

Index: library/table_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/table_builtin.m,v
retrieving revision 1.22
diff -u -b -r1.22 table_builtin.m
--- library/table_builtin.m	12 Sep 2002 10:00:51 -0000	1.22
+++ library/table_builtin.m	13 Sep 2002 03:44:11 -0000
@@ -1138,8 +1138,8 @@
 :- impure pred table_create_ans_block(ml_subgoal_table_node::in, int::in,
 	ml_answer_block::out) is det.
 
-	% Report statistics on the operation of the tabling system to stderr.
-:- impure pred table_report_statistics is det.
+	% Return statistics on the operation of the tabling system.
+:- impure pred table_report_statistics(string::out) is det.
 
 %-----------------------------------------------------------------------------%
 
@@ -1393,8 +1393,14 @@
 	error(Message).
 
 :- pragma foreign_proc("C",
-	table_report_statistics, [will_not_call_mercury], "
-	MR_table_report_statistics(stderr);
+	table_report_statistics(Stats::out),
+	[will_not_call_mercury],
+"
+	MR_String	Stats0;
+
+	Stats0 = MR_table_report_statistics();
+	MR_make_aligned_string_copy(Stats, Stats0);
+	MR_free(Stats0);
 ").
 
 
@@ -1530,7 +1536,7 @@
 	impure private_builtin__imp,
 	private_builtin__sorry("table_create_ans_block").
 
-table_report_statistics :-
+table_report_statistics(_) :-
 	% This version is only used for back-ends for which there is no
 	% matching foreign_proc version.
 	impure private_builtin__imp,
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_tabling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.c,v
retrieving revision 1.52
diff -u -b -r1.52 mercury_tabling.c
--- runtime/mercury_tabling.c	1 Aug 2002 11:52:27 -0000	1.52
+++ runtime/mercury_tabling.c	26 Aug 2002 08:19:42 -0000
@@ -993,41 +993,68 @@
 
 /*---------------------------------------------------------------------------*/
 
-void
-MR_table_report_statistics(FILE *fp)
+#define MR_BUF_SIZE 1024
+
+MR_String
+MR_table_report_statistics(void)
 {
-        fprintf(fp, "hash table search statistics:\n");
+    char    buf1[MR_BUF_SIZE];
+    char    buf2[MR_BUF_SIZE];
+    char    buf3[MR_BUF_SIZE];
+    char    buf4[MR_BUF_SIZE];
+    char    buf5[MR_BUF_SIZE];
+    char    *buf;
+
+    buf = MR_malloc(MR_BUF_SIZE);
+    if (buf == NULL) {
+        MR_fatal_error("MR_table_report_statistics: out of memory");
+    }
 
 #ifdef  MR_TABLE_STATISTICS
+    snprintf(buf1, MR_BUF_SIZE,
+        "hash table search statistics:\n");
+
         if (MR_table_hash_lookups == 0) {
-                fprintf(fp, "no successful searches\n");
+        snprintf(buf2, MR_BUF_SIZE,
+            "no successful searches\n");
         } else {
-                fprintf(fp, "successful   %6d, "
-                                "with an average of %6.3f comparisons\n",
+        snprintf(buf2, MR_BUF_SIZE,
+            "successful   %6d, with an average of %6.3f comparisons\n",
                         MR_table_hash_lookups,
                         (float) MR_table_hash_lookup_probes /
                                 (float) MR_table_hash_lookups);
         }
 
         if (MR_table_hash_inserts == 0) {
-                fprintf(fp, "no unsuccessful searches\n");
+        snprintf(buf3, MR_BUF_SIZE,
+            "no unsuccessful searches\n");
         } else {
-                fprintf(fp, "unsuccessful %6d, "
-                                "with an average of %6.3f comparisons\n",
+        snprintf(buf3, MR_BUF_SIZE,
+            "unsuccessful %6d, with an average of %6.3f comparisons\n",
                         MR_table_hash_inserts,
                         (float) MR_table_hash_insert_probes /
                                 (float) MR_table_hash_inserts);
         }
 
-        fprintf(fp, "rehash operations: %d, per search: %6.3f%%\n",
+    snprintf(buf4, MR_BUF_SIZE,
+        "rehash operations: %d, per search: %6.3f%%\n",
                         MR_table_hash_resizes,
                         (float) (100 * MR_table_hash_resizes) /
                         (float) (MR_table_hash_lookups
                                  + MR_table_hash_inserts));
-        fprintf(fp, "chunk allocations: %d\n", MR_table_hash_allocs);
+    snprintf(buf5, MR_BUF_SIZE,
+        "chunk allocations: %d\n", MR_table_hash_allocs);
+
+    snprintf(buf, MR_BUF_SIZE,
+        "%s%s%s%s%s",
+        buf1, buf2, buf3, buf4, buf5);
+
 #else
-        fprintf(fp, "not enabled\n");
+    snprintf(buf, MR_BUF_SIZE,
+        "hash table search statistics not enabled\n");
 #endif
+
+    return buf;
 }
 
 /*---------------------------------------------------------------------------*/
Index: runtime/mercury_tabling.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.h,v
retrieving revision 1.28
diff -u -b -r1.28 mercury_tabling.h
--- runtime/mercury_tabling.h	18 Feb 2002 07:01:21 -0000	1.28
+++ runtime/mercury_tabling.h	26 Aug 2002 08:12:22 -0000
@@ -330,11 +330,12 @@
 				MR_TypeInfo type_info, MR_Word data_value);
 
 /*
-** This function prints statistics about the operation of tabling, if the
-** collection of such statistics is enabled, on the given stream.
+** This function returns statistics about the operation of tabling, if the
+** collection of such statistics is enabled. The string should be freed with
+** MR_free after use.
 */
 
-extern	void		MR_table_report_statistics(FILE *fp);
+extern	MR_String	MR_table_report_statistics(void);
 
 /*---------------------------------------------------------------------------*/
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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