[m-rev.] diff: mdb command "stats io_tabling"

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Aug 1 12:39:35 AEST 2005


Provide a mechanism for gathering statistics about which predicates occur most
frequently in the I/O action table.

Instead of adding a new mdb command, consolidate three existing mdb commands
(proc_stats, label_stats and var_name_stats) into a single "stats" command,
and add a new variant for stats on I/O tabling.

doc/mdb_categories:
doc/user_guide.texi:
	Document the changes in mdb commands.

runtime/mercury_trace_base.[ch]:
	Add a new function for printing stats on the predicate in the I/O
	action table.
	
	Add headers to each section of this file.

runtime/mercury_hash_table.[ch]:
	Remove the const qualifier from the return type of the lookup function,
	since mercury_trace_base.c now needs to modify a looked-up record.

	Move the documentation on the functions in this module to the header
	file.

trace/mercury_trace_internal.c:
	Merge the three previous mdb commands into one, and add the new
	alternative.

trace/mercury_trace_tables.c:
	Minor change in formatting.

trace/mercury_trace_tables.c:
	Minor style fix.

tests/debugger/completion.{inp,exp}:
tests/debugger/mdb_command_test.inp:
	Change these test cases to account for the disappearance of the
	three old mdb commands and the appearance of the new one.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
Index: doc/mdb_categories
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/mdb_categories,v
retrieving revision 1.27
diff -u -b -r1.27 mdb_categories
--- doc/mdb_categories	11 Jul 2005 07:30:25 -0000	1.27
+++ doc/mdb_categories	1 Aug 2005 02:31:34 -0000
@@ -82,9 +82,8 @@
              of the Mercury implementation. The developer commands are
              `flag', `subgoal', `consumer', `gen_stack', `cut_stack,
              `pneg_stack', `mm_stacks', `nondet_stack', `stack_regs',
-             `all_regs', `debug_vars', `proc_stats', `label_stats',
-             `var_name_stats', `print_optionals', `unhide_events', `dd_dd',
-             `table', `type_ctor', `class_decl', `all_type_ctors' and
-             `all_class_decls'.
+             `all_regs', `debug_vars', `stats', `print_optionals',
+             `unhide_events', `dd_dd', `table', `type_ctor', `class_decl',
+             `all_type_ctors' and `all_class_decls'.
 
 end
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.447
diff -u -b -r1.447 user_guide.texi
--- doc/user_guide.texi	28 Jul 2005 06:44:08 -0000	1.447
+++ doc/user_guide.texi	30 Jul 2005 14:52:35 -0000
@@ -3788,31 +3788,25 @@
 Prints the values of the variables used by the debugger
 to record event numbers, call sequence numbers and call depths.
 @sp 1
- at item proc_stats
- at kindex proc_stats (mdb command)
-Prints statistics about proc layout structures in the program.
+ at item stats [-f @var{filename}] @var{subject}
+ at kindex stats (mdb command)
+Prints statistics about the given subject to standard output,
+unless the @samp{-f} or @samp{--filename} option is given,
+in which case it prints the statistic to @var{filename}.
 @sp 1
- at item proc_stats @var{filename}
-Prints statistics about proc layout structures in the program
-to the file @var{filename}.
+ at var{subject} can be @samp{procs},
+which asks for statistics about proc layout structures in the program.
 @sp 1
- at item label_stats
- at kindex label_stats (mdb command)
-Prints statistics about label layout structures in the program.
+ at var{subject} can be @samp{labels},
+which asks for statistics about label layout structures in the program.
 @sp 1
- at item label_stats @var{filename}
-Prints statistics about label layout structures in the program
-to the file @var{filename}.
- at sp 1
- at item var_name_stats
- at kindex var_name_stats (mdb command)
-Prints statistics about the memory requirements of variable names
+ at var{subject} can be @samp{var_names},
+which asks for statistics about the space occupied by variable names
 in the layout structures in the program.
 @sp 1
- at item var_name_stats @var{filename}
-Prints statistics about the memory requirements of variable names
-in the layout structures in the program
-to the file @var{filename}.
+ at var{subject} can be @samp{io_tabling},
+which asks for statistics about the number of times
+each predicate appears in the I/O action table.
 @sp 1
 @item print_optionals
 @kindex print_optionals (mdb command)
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_hash_table.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_hash_table.c,v
retrieving revision 1.7
diff -u -b -r1.7 mercury_hash_table.c
--- runtime/mercury_hash_table.c	24 Nov 2004 05:06:52 -0000	1.7
+++ runtime/mercury_hash_table.c	30 Jul 2005 14:15:04 -0000
@@ -20,10 +20,6 @@
 #include	"mercury_dlist.h"
 #include	"mercury_hash_table.h"
 
-/*
-**	Initialize a table.
-*/
-
 void 
 MR_ht_init_table(MR_Hash_Table *table)
 {
@@ -36,12 +32,7 @@
 	}
 }
 
-/*
-**	Look up and return the entry corresponding to the key
-**	in a table.
-*/
-
-const void *
+void *
 MR_ht_lookup_table(const MR_Hash_Table *table, const void *key)
 {
 	MR_Dlist	*ptr;
@@ -61,18 +52,13 @@
 		if (MR_tableequal(table)(key,
 			MR_tablekey(table)(MR_dlist_data(ptr))))
 		{
-			return MR_dlist_data(ptr);
+			return (void *) MR_dlist_data(ptr);
 		}
 	}
 
 	return NULL;
 }
 
-/*
-**	Insert a new entry into the table.
-**	Return whether it was there before.
-*/
-
 const void *
 MR_ht_insert_table(const MR_Hash_Table *table, void *entry)
 {
@@ -103,10 +89,6 @@
 	return NULL;
 }
 
-/*
-**	Return all table entries in a list.
-*/
-
 MR_Dlist *
 MR_ht_get_all_entries(const MR_Hash_Table *table)
 {
@@ -121,10 +103,6 @@
 	return list;
 }
 
-/*
-**	Process all table entries with the specified function.
-*/
-
 void
 MR_ht_process_all_entries(const MR_Hash_Table *table, void f(const void *))
 {
@@ -137,11 +115,6 @@
 		}
 	}
 }
-
-/*
-**	Convert a string to a positive int. The return value
-**	mod the table size is a good hash value.
-*/
 
 int 
 MR_ht_str_to_int(const char *cs)
Index: runtime/mercury_hash_table.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_hash_table.h,v
retrieving revision 1.5
diff -u -b -r1.5 mercury_hash_table.h
--- runtime/mercury_hash_table.h	24 Nov 2004 05:06:52 -0000	1.5
+++ runtime/mercury_hash_table.h	30 Jul 2005 14:13:07 -0000
@@ -7,9 +7,14 @@
 /*
 ** Defines the interface to the hash table module.
 **
+** This file supplies data manipulation routines to other modules;
+** it does not store any data itself. Its routines are generic,
+** applicable to the storage of any kind of data structure with
+** a primary key and a hash function on it.
+**
 ** Note that this module has nothing to do with the implementation
 ** of the "tabling" pragmas such as `pragma memo' -- the implementation
-** of those features uses Tries, not hash tables, and is defined
+** of those features mostly uses Tries, not hash tables, and is defined
 ** in mercury_tabling.h.
 */
 
@@ -28,24 +33,61 @@
 						     /* applied to two keys */
 } MR_Hash_Table;
 
-#define	MR_init_hash_table(t)		MR_ht_init_table(&t)
-#define	MR_lookup_hash_table(t, k)	MR_ht_lookup_table(&t, (const void *) k)
-#define	MR_insert_hash_table(t, e)	MR_ht_insert_table(&t, (void *) e)
-#define	MR_get_all_entries(t)		MR_ht_get_all_entries(&t)
-#define	MR_process_all_entries(t, f)	MR_ht_process_all_entries(&t, f)
-#define	MR_str_to_int(val)		MR_ht_str_to_int(val)
-
 #define	MR_tablekey(table)		(*(table->MR_ht_key))
 #define	MR_tablehash(table)		(*(table->MR_ht_hash))
 #define	MR_tableequal(table)		(*(table->MR_ht_equal))
 
+/*
+** Initialize a table.
+*/
+
 extern	void		MR_ht_init_table(MR_Hash_Table *);
-extern	const void	*MR_ht_lookup_table(const MR_Hash_Table *,
+
+/*
+** Look up and return the entry corresponding to the key in a table.
+*/
+
+extern	void		*MR_ht_lookup_table(const MR_Hash_Table *,
 				const void *);
+
+/*
+** Try to insert a new entry into the table. If the table already had an entry
+** with the same key, return the entry that was there before and do not insert
+** the new entry. If the entry is new, return NULL.
+*/
+
 extern	const void	*MR_ht_insert_table(const MR_Hash_Table *, void *);
+
+/*
+** Return all table entries in a list.
+*/
+
 extern	MR_Dlist	*MR_ht_get_all_entries(const MR_Hash_Table *);
+
+/*
+** Process all table entries with the specified function.
+*/
+
 extern	void		MR_ht_process_all_entries(const MR_Hash_Table *,
 				void f(const void *));
+
+/*
+** Convert a string to a positive int. The return value mod the table size
+** is a good hash value.
+*/
+
 extern	int		MR_ht_str_to_int(const char *);
+
+/*
+** These wrappers around calls to the above functions can avoid the need for
+** explicit address-of operators and casts.
+*/
+
+#define	MR_init_hash_table(t)		MR_ht_init_table(&t)
+#define	MR_lookup_hash_table(t, k)	MR_ht_lookup_table(&t, (const void *) k)
+#define	MR_insert_hash_table(t, e)	MR_ht_insert_table(&t, (void *) e)
+#define	MR_get_all_entries(t)		MR_ht_get_all_entries(&t)
+#define	MR_process_all_entries(t, f)	MR_ht_process_all_entries(&t, f)
+#define	MR_str_to_int(val)		MR_ht_str_to_int(val)
 
 #endif /* not MERCURY_HASH_TABLE_H */
Index: runtime/mercury_trace_base.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.67
diff -u -b -r1.67 mercury_trace_base.c
--- runtime/mercury_trace_base.c	29 Apr 2005 01:03:17 -0000	1.67
+++ runtime/mercury_trace_base.c	30 Jul 2005 14:41:23 -0000
@@ -123,6 +123,11 @@
                         MR_Hash_Table *table_ptr, MR_bool *init_ptr,
                         int *next_ptr);
 
+/**************************************************************************/
+/*
+** This section of this file deals with the actions executed at trace events.
+*/
+
 MR_Code *
 MR_trace(const MR_Label_Layout *layout)
 {
@@ -335,19 +340,16 @@
                     id = &proc->MR_sle_user;
                     if (proc != prev_proc) {
                         fprintf(fp, "proc ");
-                        MR_trace_write_quoted_atom(fp,
-                            id->MR_user_def_module);
+                        MR_trace_write_quoted_atom(fp, id->MR_user_def_module);
                         fprintf(fp, " %c ",
                             ( id->MR_user_pred_or_func == MR_PREDICATE
                                 ? 'p' : 'f'));
                         MR_trace_write_quoted_atom(fp,
                             id->MR_user_decl_module);
                         fputc(' ', fp);
-                        MR_trace_write_quoted_atom(fp,
-                            id->MR_user_name);
+                        MR_trace_write_quoted_atom(fp, id->MR_user_name);
                         fprintf(fp, " %d %d\n",
-                            id->MR_user_arity,
-                            id->MR_user_mode);
+                            id->MR_user_arity, id->MR_user_mode);
                     }
 
                     port = label->MR_sll_port;
@@ -437,6 +439,12 @@
     fputc('\'', fp);
 }
 
+/**************************************************************************/
+/*
+** This section of this file deals with the actions executed at the start
+** and end of execution.
+*/
+
 #ifdef  MR_TABLE_DEBUG
 MR_bool MR_saved_tabledebug;
 #endif
@@ -528,6 +536,13 @@
     MR_update_trace_func_enabled();
 }
 
+/**************************************************************************/
+/*
+** This section of this file deals with the standardization of event and
+** call sequence numbers. We use standardized event and call numbers to
+** reduce the number of .exp files we need to create for debugger test cases.
+*/
+
 #define MR_STANDARD_HASH_TABLE_SIZE 1024
 
 typedef struct {
@@ -612,6 +627,12 @@
         &MR_init_call_num_hash, &MR_next_std_call_num);
 }
 
+/**************************************************************************/
+/*
+** This section of this file reports on trace events so far, for use
+** in messages about abnormal program termination.
+*/
+
 char    *MR_trace_report_msg = NULL;
 
 void
@@ -686,6 +707,11 @@
     }
 }
 
+/**************************************************************************/
+/*
+** This section of this file deals with I/O actions.
+*/
+
 MR_bool
 MR_trace_get_action(int action_number, MR_ConstString *proc_name_ptr,
     MR_Word *is_func_ptr, MR_Word *arg_list_ptr)
@@ -750,6 +776,11 @@
     return MR_TRUE;
 }
 
+/**************************************************************************/
+/*
+** This section of this file deals with switching debugging on and off.
+*/
+
 void
 MR_turn_off_debug(MR_SavedDebugState *saved_state,
     MR_bool include_counter_vars)
@@ -793,6 +824,11 @@
     }
 }
 
+/**************************************************************************/
+/*
+** This section of this file deals with recording the value of an exception.
+*/
+
 static  MR_Word     MR_trace_exception_value = (MR_Word) NULL;
 
 void
@@ -807,6 +843,12 @@
     return MR_trace_exception_value;
 }
 
+/**************************************************************************/
+/*
+** This section of this file deals with measuring the distribution of events
+** across depths.
+*/
+
 #ifdef  MR_TRACE_HISTOGRAM
 
 void
@@ -828,7 +870,156 @@
 
 #endif  /* MR_TRACE_HISTOGRAM */
 
+/**************************************************************************/
+/*
+** This section of this file deals with statistics about which procedures
+** are respondible for what fraction of I/O table entries.
+*/
+
+#define MR_IO_TABLE_STATS_HASH_TABLE_SIZE 1024
+
+typedef struct {
+    const MR_Proc_Layout    *MR_io_tabling_stats_proc;
+    MR_Unsigned             MR_io_tabling_stats_count;
+} MR_IO_Table_Stats_Hash_Record;
+
+static const void *
+MR_get_proc_layout(const void *record)
+{
+    return (const void *)
+        ((MR_IO_Table_Stats_Hash_Record *) record)->MR_io_tabling_stats_proc;
+}
+
+static int
+MR_hash_proc_layout(const void *proc)
+{
+    return (((MR_Unsigned) proc) >> 5) % MR_STANDARD_HASH_TABLE_SIZE;
+}
+
+static MR_bool
+MR_equal_proc_layout(const void *proc1, const void *proc2)
+{
+    return (const MR_Proc_Layout *) proc1 == (const MR_Proc_Layout *) proc2;
+}
+
+static MR_Hash_Table MR_io_tabling_stats_table = {
+    MR_IO_TABLE_STATS_HASH_TABLE_SIZE, NULL,
+    MR_get_proc_layout, MR_hash_proc_layout, MR_equal_proc_layout
+};
+
+static  int                             MR_io_tabling_stats_sort_arena_next;
+static  MR_IO_Table_Stats_Hash_Record   *MR_io_tabling_stats_sort_arena;
+
+static  void    MR_add_to_sort_arena(const void *addr);
+static  int     MR_compare_in_sort_arena(const void *addr1, const void *addr2);
+
+static void
+MR_add_to_sort_arena(const void *addr)
+{
+    const MR_IO_Table_Stats_Hash_Record *record;
+    int                                 next;
+
+    record = (const MR_IO_Table_Stats_Hash_Record *) addr;
+    next = MR_io_tabling_stats_sort_arena_next;
+    MR_io_tabling_stats_sort_arena[next].MR_io_tabling_stats_proc =
+        record->MR_io_tabling_stats_proc;
+    MR_io_tabling_stats_sort_arena[next].MR_io_tabling_stats_count =
+        record->MR_io_tabling_stats_count;
+    MR_io_tabling_stats_sort_arena_next++;
+}
+
+static int
+MR_compare_in_sort_arena(const void *addr1, const void *addr2)
+{
+    const MR_IO_Table_Stats_Hash_Record *record1;
+    const MR_IO_Table_Stats_Hash_Record *record2;
+
+    record1 = (const MR_IO_Table_Stats_Hash_Record *) addr1;
+    record2 = (const MR_IO_Table_Stats_Hash_Record *) addr2;
+    return record2->MR_io_tabling_stats_count - 
+        record1->MR_io_tabling_stats_count;
+}
+
+void
+MR_io_tabling_stats(FILE *fp)
+{
+    const MR_Table_Io_Decl          *table_io_decl;
+    const MR_Proc_Layout            *proc_layout;
+    MR_ConstString                  proc_name;
+    int                             arity;
+    MR_Word                         is_func;
+    int                             hv;
+    MR_TrieNode                     answer_block_trie;
+    MR_Word                         *answer_block;
+    MR_Hash_Table                   hash_table;
+    MR_IO_Table_Stats_Hash_Record   *hash_record;
+    MR_IO_Table_Stats_Hash_Record   *record;
+    int                             num_entries;
+    int                             count;
+    int                             i;
+
+    /*
+    ** Create a fresh new hash table, separate the table created by
+    ** any previous call to this function.
+    */
+    hash_table = MR_io_tabling_stats_table;
+    MR_init_hash_table(hash_table);
+    num_entries = 0;
+
+    for (i = MR_io_tabling_start; i < MR_io_tabling_counter_hwm; i++) {
+        MR_DEBUG_NEW_TABLE_START_INT(answer_block_trie,
+            (MR_TrieNode) &MR_io_tabling_pointer,
+            MR_io_tabling_start, i);
+        answer_block = answer_block_trie->MR_answerblock;
+
+        if (answer_block == NULL) {
+            continue;
+        }
+
+        table_io_decl = (const MR_Table_Io_Decl *) answer_block[0];
+        proc_layout = table_io_decl->MR_table_io_decl_proc;
+
+        hash_record = MR_lookup_hash_table(hash_table, proc_layout);
+        if (hash_record == NULL) {
+            hash_record = MR_GC_NEW(MR_IO_Table_Stats_Hash_Record);
+            hash_record->MR_io_tabling_stats_proc = proc_layout;
+            hash_record->MR_io_tabling_stats_count = 1;
+            (void) MR_insert_hash_table(hash_table, hash_record);
+            num_entries++;
+        } else {
+            hash_record->MR_io_tabling_stats_count++;
+        }
+    }
+
+    MR_io_tabling_stats_sort_arena =
+        MR_GC_NEW_ARRAY(MR_IO_Table_Stats_Hash_Record, num_entries);
+    MR_io_tabling_stats_sort_arena_next = 0;
+    MR_process_all_entries(hash_table, MR_add_to_sort_arena);
+
+    if (MR_io_tabling_stats_sort_arena_next != num_entries) {
+        MR_fatal_error("MR_io_tabling_stats: num_entries mismatch");
+    }
+
+    qsort(MR_io_tabling_stats_sort_arena, num_entries,
+        sizeof(MR_IO_Table_Stats_Hash_Record), MR_compare_in_sort_arena);
+
+    for (i = 0; i < num_entries; i++) {
+        record = &MR_io_tabling_stats_sort_arena[i];
+        proc_layout = record->MR_io_tabling_stats_proc;
+        count = record->MR_io_tabling_stats_count;
+        MR_generate_proc_name_from_layout(proc_layout, &proc_name, &arity,
+            &is_func);
+
+        fprintf(fp, "%8d %4s %s/%d\n", count, (is_func ? "func" : "pred"),
+            proc_name, arity);
+    }
+}
+
+/**************************************************************************/
 /*
+** This section of this file maps proc layouts to materialized procedure
+** body representations.
+**
 ** We record information about procedure representations in a hash table
 ** that is indexed by the proc layout address.
 **
@@ -851,9 +1042,9 @@
 static  MR_bool             equal_proc_layouts(const void *addr1,
                                 const void *addr2);
 
-static  MR_Hash_Table       proc_rep_table = {PROC_REP_TABLE_SIZE, NULL,
+static  MR_Hash_Table       proc_rep_table = { PROC_REP_TABLE_SIZE, NULL,
                                 proc_layout_rep_key, hash_proc_layout_addr,
-                                equal_proc_layouts};
+                                equal_proc_layouts };
 
 static void
 MR_do_init_proc_rep_table(void)
@@ -940,6 +1131,13 @@
     return ((const MR_Proc_Layout *) addr1) ==
         ((const MR_Proc_Layout *) addr2);
 }
+
+/**************************************************************************/
+/*
+** This section of this file provides the code that generated redo events.
+** Its labels are pointed to by the temp frames pushed onto the nondet stack
+** by model_non procedures when they exit.
+*/
 
 #ifndef MR_HIGHLEVEL_CODE
 
Index: runtime/mercury_trace_base.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_trace_base.h,v
retrieving revision 1.48
diff -u -b -r1.48 mercury_trace_base.h
--- runtime/mercury_trace_base.h	29 Apr 2005 01:03:17 -0000	1.48
+++ runtime/mercury_trace_base.h	30 Jul 2005 04:33:59 -0000
@@ -488,6 +488,8 @@
 
 #endif	/* MR_TRACE_HISTOGRAM */
 
+extern	void	MR_io_tabling_stats(FILE *fp);
+
 /*
 ** These two functions work on a table that maps proc layout structures
 ** to the Mercury terms representing the bodies of those procedures.
@@ -532,6 +534,7 @@
 ** When using the heap pointer, we need to restore it, in case it is
 ** transient.
 */
+
 #define MR_TRACE_USE_HP(STATEMENTS) do {				\
 		MR_restore_transient_registers();			\
 		STATEMENTS;						\
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
Index: tests/debugger/completion.exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/completion.exp,v
retrieving revision 1.28
diff -u -b -r1.28 completion.exp
--- tests/debugger/completion.exp	11 Jul 2005 07:30:28 -0000	1.28
+++ tests/debugger/completion.exp	31 Jul 2005 07:10:40 -0000
@@ -3,44 +3,44 @@
 Command echo enabled.
 mdb> register --quiet
 mdb> 
-?                    enable               procedures
-P                    exception            query
-alias                excp                 quit
-all_class_decls      f                    r
-all_procedures       finish               register
-all_regs             flag                 retry
-all_type_ctors       forward              return
-b                    g                    s
-break                gen_stack            save
-break_print          goal_paths           save_to_file
-browse               goto                 scope
-c                    h                    scroll
-cc_query             held_vars            set
-class_decl           help                 source
-clear_histogram      histogram_all        stack
-condition            histogram_exp        stack_default_limit
-consumer             hold                 stack_regs
-context              ignore               step
-continue             io_query             subgoal
-current              label_stats          table
-cut_stack            level                table_io
-d                    maxdepth             term_size
-dd                   mindepth             trust
-dd_dd                mm_stacks            trusted
-debug_vars           mmc_options          type_ctor
-delete               modules              unalias
-dice                 next                 unhide_events
-diff                 nondet_stack         untrust
-disable              p                    up
-document             pneg_stack           v
-document_category    print                var_details
-down                 print_optionals      var_name_stats
-e                    printlevel           vars
-echo                 proc_stats           view
+?                    enable               quit
+P                    exception            r
+alias                excp                 register
+all_class_decls      f                    retry
+all_procedures       finish               return
+all_regs             flag                 s
+all_type_ctors       forward              save
+b                    g                    save_to_file
+break                gen_stack            scope
+break_print          goal_paths           scroll
+browse               goto                 set
+c                    h                    source
+cc_query             held_vars            stack
+class_decl           help                 stack_default_limit
+clear_histogram      histogram_all        stack_regs
+condition            histogram_exp        stats
+consumer             hold                 step
+context              ignore               subgoal
+continue             io_query             table
+current              level                table_io
+cut_stack            maxdepth             term_size
+d                    mindepth             trust
+dd                   mm_stacks            trusted
+dd_dd                mmc_options          type_ctor
+debug_vars           modules              unalias
+delete               next                 unhide_events
+dice                 nondet_stack         untrust
+diff                 p                    up
+disable              pneg_stack           v
+document             print                var_details
+document_category    print_optionals      vars
+down                 printlevel           view
+e                    procedures           
+echo                 query                
 h              help           histogram_exp  
 held_vars      histogram_all  hold           
-var_details     var_name_stats  vars            view
-var_details     var_name_stats  vars            
+var_details  vars         view         
+var_details  vars         
  help vars 
 vars
      Prints the names of all the known variables in the current
@@ -55,7 +55,6 @@
 stack --detailed 
    0       1       1    1 pred completion.main/2-0 (det) (completion.m:13) (empty)
 mdb> 
-proc_stats  procedures  
 completion            completion.sub2       
 completion.sub1       completion.sub2.sub3  
 completion.sub1       completion.sub2       completion.sub2.sub3
Index: tests/debugger/completion.inp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/completion.inp,v
retrieving revision 1.10
diff -u -b -r1.10 completion.inp
--- tests/debugger/completion.inp	11 Jul 2005 07:30:28 -0000	1.10
+++ tests/debugger/completion.inp	31 Jul 2005 01:46:15 -0000
@@ -2,8 +2,8 @@
 register --quiet
 @ h at elp@v at a@s@
 p --f@@D@
-sta@ @
-proc at e@complet at .@1
+stac@ @
+proc at complet@. at 1
 set --f at fo@p@
 una at ex@
 b za@
Index: tests/debugger/mdb_command_test.inp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/mdb_command_test.inp,v
retrieving revision 1.43
diff -u -b -r1.43 mdb_command_test.inp
--- tests/debugger/mdb_command_test.inp	29 Jul 2005 01:56:58 -0000	1.43
+++ tests/debugger/mdb_command_test.inp	31 Jul 2005 16:37:22 -0000
@@ -82,9 +82,7 @@
 stack_regs           xyzzy xyzzy xyzzy xyzzy xyzzy
 all_regs             xyzzy xyzzy xyzzy xyzzy xyzzy
 debug_vars           xyzzy xyzzy xyzzy xyzzy xyzzy
-proc_stats           xyzzy xyzzy xyzzy xyzzy xyzzy
-label_stats          xyzzy xyzzy xyzzy xyzzy xyzzy
-var_name_stats       xyzzy xyzzy xyzzy xyzzy xyzzy
+stats                xyzzy xyzzy xyzzy xyzzy xyzzy
 print_optionals      xyzzy xyzzy xyzzy xyzzy xyzzy
 unhide_events        xyzzy xyzzy xyzzy xyzzy xyzzy
 dd_dd                xyzzy xyzzy xyzzy xyzzy xyzzy
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.208
diff -u -b -r1.208 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	31 Jul 2005 05:14:59 -0000	1.208
+++ trace/mercury_trace_internal.c	1 Aug 2005 02:15:54 -0000
@@ -507,9 +507,7 @@
 static  MR_TraceCmdFunc MR_trace_cmd_all_regs;
 static  MR_TraceCmdFunc MR_trace_cmd_debug_vars;
 static  MR_TraceCmdFunc MR_trace_cmd_table_io;
-static  MR_TraceCmdFunc MR_trace_cmd_proc_stats;
-static  MR_TraceCmdFunc MR_trace_cmd_label_stats;
-static  MR_TraceCmdFunc MR_trace_cmd_var_name_stats;
+static  MR_TraceCmdFunc MR_trace_cmd_stats;
 static  MR_TraceCmdFunc MR_trace_cmd_proc_body;
 static  MR_TraceCmdFunc MR_trace_cmd_print_optionals;
 static  MR_TraceCmdFunc MR_trace_cmd_unhide_events;
@@ -606,6 +604,8 @@
                         MR_bool *search_mode_was_set, MR_bool *new_session,
                         char ***words, int *word_count, const char *cat,
                         const char *item);
+static  MR_bool     MR_trace_options_stats(char **filename, char ***words,
+                        int *word_count, const char *cat, const char *item);
 static  MR_bool     MR_trace_options_type_ctor(MR_bool *print_rep,
                         MR_bool *print_functors, char ***words,
                         int *word_count, const char *cat, const char *item);
@@ -4375,81 +4375,55 @@
 }
 
 static MR_Next
-MR_trace_cmd_proc_stats(char **words, int word_count, MR_Trace_Cmd_Info *cmd,
+MR_trace_cmd_stats(char **words, int word_count, MR_Trace_Cmd_Info *cmd,
     MR_Event_Info *event_info, MR_Event_Details *event_details,
     MR_Code **jumpaddr)
 {
-    if (word_count == 1) {
-        MR_proc_layout_stats(MR_mdb_out);
-    } else if (word_count == 2) {
+    char    *filename;
         FILE    *fp;
+    MR_bool should_close;
 
-        fp = fopen(words[1], "w");
-        if (fp == NULL) {
-            fflush(MR_mdb_out);
-            fprintf(MR_mdb_err, "mdb: error opening `%s': %s.\n",
-                words[1], strerror(errno));
+    filename = NULL;
+    if (! MR_trace_options_stats(&filename,
+        &words, &word_count, "developer", "type_ctor"))
+    {
+        /* the usage message has already been printed */
             return KEEP_INTERACTING;
         }
 
-        MR_proc_layout_stats(fp);
-        (void) fclose(fp);
-    } else {
-        MR_trace_usage("developer", "proc_stats");
+    if (word_count != 2) {
+        MR_trace_usage("developer", "stats");
     }
 
-    return KEEP_INTERACTING;
-}
-
-static MR_Next
-MR_trace_cmd_label_stats(char **words, int word_count, MR_Trace_Cmd_Info *cmd,
-    MR_Event_Info *event_info, MR_Event_Details *event_details,
-    MR_Code **jumpaddr)
-{
-    if (word_count == 1) {
-        MR_label_layout_stats(MR_mdb_out);
-    } else if (word_count == 2) {
-        FILE    *fp;
-
-        fp = fopen(words[1], "w");
+    if (filename != NULL) {
+        fp = fopen(filename, "w");
         if (fp == NULL) {
             fflush(MR_mdb_out);
             fprintf(MR_mdb_err, "mdb: error opening `%s': %s.\n",
-                words[1], strerror(errno));
+                filename, strerror(errno));
             return KEEP_INTERACTING;
         }
 
-        MR_label_layout_stats(fp);
-        (void) fclose(fp);
+        should_close = MR_TRUE;
     } else {
-        MR_trace_usage("developer", "label_stats");
+        fp = MR_mdb_out;
+        should_close = MR_FALSE;
     }
 
-    return KEEP_INTERACTING;
-}
-
-static MR_Next
-MR_trace_cmd_var_name_stats(char **words, int word_count,
-    MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
-    MR_Event_Details *event_details, MR_Code **jumpaddr)
-{
-    if (word_count == 1) {
-        MR_var_name_stats(MR_mdb_out);
-    } else if (word_count == 2) {
-        FILE    *fp;
-
-        fp = fopen(words[1], "w");
-        if (fp == NULL) {
-            fflush(MR_mdb_out);
-            fprintf(MR_mdb_err, "mdb: error opening `%s': %s.\n",
-                words[1], strerror(errno));
-            return KEEP_INTERACTING;
+    if (MR_streq(words[1], "procs")) {
+        MR_proc_layout_stats(fp);
+    } else if (MR_streq(words[1], "labels")) {
+        MR_label_layout_stats(fp);
+    } else if (MR_streq(words[1], "var_names")) {
+        MR_var_name_stats(fp);
+    } else if (MR_streq(words[1], "io_tabling")) {
+        MR_io_tabling_stats(fp);
+    } else {
+        MR_trace_usage("developer", "stats");
         }
 
-        MR_var_name_stats(fp);
+    if (should_close) {
         (void) fclose(fp);
-    } else {
-        MR_trace_usage("developer", "var_name_stats");
     }
 
     return KEEP_INTERACTING;
@@ -7273,6 +7247,39 @@
     return MR_TRUE;
 }
 
+static struct MR_option MR_trace_stats_opts[] =
+{
+    { "file",      MR_required_argument,    NULL,   'f' },
+    { NULL,        MR_no_argument,          NULL,   0 }
+};
+
+static MR_bool
+MR_trace_options_stats(char **filename,
+    char ***words, int *word_count, const char *cat, const char *item)
+{
+    int c;
+
+    MR_optind = 0;
+    while ((c = MR_getopt_long(*word_count, *words, "f:",
+        MR_trace_stats_opts, NULL)) != EOF)
+    {
+        switch (c) {
+
+            case 'f':
+                *filename = MR_optarg;
+                break;
+
+            default:
+                MR_trace_usage(cat, item);
+                return MR_FALSE;
+        }
+    }
+
+    *words = *words + MR_optind - 1;
+    *word_count = *word_count - MR_optind + 1;
+    return MR_TRUE;
+}
+
 static struct MR_option MR_trace_type_ctor_opts[] =
 {
     { "print-rep",      MR_no_argument,     NULL,   'r' },
@@ -8240,6 +8247,9 @@
 static const char *const    MR_trace_quit_cmd_args[] =
     { "-y", NULL };
 
+static const char *const    MR_trace_stats_cmd_args[] =
+    { "procs", "labels", "var_names", "io_tabling", NULL };
+
 static const MR_Trace_Command_Info  MR_trace_command_infos[] =
 {
     /*
@@ -8414,12 +8424,8 @@
         NULL, MR_trace_null_completer },
     { "developer", "debug_vars", MR_trace_cmd_debug_vars,
         NULL, MR_trace_null_completer },
-    { "developer", "proc_stats", MR_trace_cmd_proc_stats,
-        NULL, MR_trace_filename_completer },
-    { "developer", "label_stats", MR_trace_cmd_label_stats,
-        NULL, MR_trace_filename_completer },
-    { "developer", "var_name_stats", MR_trace_cmd_var_name_stats,
-        NULL, MR_trace_filename_completer },
+    { "developer", "stats", MR_trace_cmd_stats,
+        MR_trace_stats_cmd_args, MR_trace_filename_completer },
     { "developer", "print_optionals", MR_trace_cmd_print_optionals,
         MR_trace_on_off_args, MR_trace_null_completer },
     { "developer", "unhide_events", MR_trace_cmd_unhide_events,
Index: trace/mercury_trace_tables.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_tables.c,v
retrieving revision 1.35
diff -u -b -r1.35 mercury_trace_tables.c
--- trace/mercury_trace_tables.c	28 Jul 2005 07:03:35 -0000	1.35
+++ trace/mercury_trace_tables.c	30 Jul 2005 04:25:12 -0000
@@ -1154,8 +1154,7 @@
                 label_num < file_layout->MR_mfl_label_count;
                 label_num++)
             {
-                label_layout = file_layout->
-                    MR_mfl_label_layout[label_num];
+                label_layout = file_layout->MR_mfl_label_layout[label_num];
 
                 total++;
                 if (0 <= label_layout->MR_sll_port &&
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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