[m-dev.] for review: fix problem with mtc output filename
Ian MacLarty
maclarty at csse.unimelb.edu.au
Wed Sep 13 23:37:06 AEST 2006
Estimated hours taken: 1
Branches: main, 0.13
Fix a problem with the automatically generated trace counts file name.
The filename contained the name of the invoked program with "/" replaced by
":". Using ":" is a problem on Windows because it is not allowed in windows
filenames. Instead we now use "_".
Allow the user to specify their own trace counts file name with an extra option
to mtc.
runtime/mercury_trace_base.c:
When dumping trace counts, first check if the user gave a filename to
be used and if they did use that, otherwise generate a filename, but
use "_" instead of ":".
runtime/mercury_trace_base.h:
Add MR_trace_counts_file for recording a user defined trace counts
file name.
runtime/mercury_wrapper.c:
Process the --tc-output-file MERCURY_OPTIONS option that allows the
user to give their own trace counts file name.
scripts/mtc:
Add an -o option to allow the user to give their own file name.
Also add a --help option.
tests/debugger/declarative/Mmakefile:
Make the dice test use the --tc-output-file option.
Index: runtime/mercury_trace_base.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.c,v
retrieving revision 1.73
diff -u -r1.73 mercury_trace_base.c
--- runtime/mercury_trace_base.c 22 Aug 2006 09:41:16 -0000 1.73
+++ runtime/mercury_trace_base.c 13 Sep 2006 07:38:42 -0000
@@ -45,11 +45,12 @@
void (*MR_trace_shutdown)(void) = NULL;
+MR_bool MR_trace_count_enabled = MR_FALSE;
MR_bool MR_coverage_test_enabled = MR_FALSE;
+char *MR_trace_counts_file = NULL;
MR_bool MR_debug_ever_enabled = MR_FALSE;
MR_bool MR_debug_enabled = MR_FALSE;
-MR_bool MR_trace_count_enabled = MR_FALSE;
MR_bool MR_trace_func_enabled = MR_FALSE;
MR_Code *(*volatile MR_selected_trace_func_ptr)(
const MR_Label_Layout *);
@@ -258,16 +259,25 @@
char *name;
char *s;
- /* 100 bytes must be enough for the process id, dots and '\0' */
- len = strlen(MERCURY_TRACE_COUNTS_PREFIX) + strlen(MR_progname) + 100;
- name = MR_malloc(len);
- snprintf(name, len, ".%s.%s.%d", MERCURY_TRACE_COUNTS_PREFIX, MR_progname,
- getpid());
-
- /* make sure name is an acceptable filename */
- for (s = name; *s != '\0'; s++) {
- if (*s == '/') {
- *s = ':';
+ if (MR_trace_counts_file) {
+ name = MR_trace_counts_file;
+ } else {
+ /*
+ ** If no trace counts file name is provided, then we generate
+ ** a file name.
+ */
+
+ /* 100 bytes must be enough for the process id, dots and '\0' */
+ len = strlen(MERCURY_TRACE_COUNTS_PREFIX) + strlen(MR_progname) + 100;
+ name = MR_malloc(len);
+ snprintf(name, len, ".%s.%s.%d", MERCURY_TRACE_COUNTS_PREFIX,
+ MR_progname, getpid());
+
+ /* make sure name is an acceptable filename */
+ for (s = name; *s != '\0'; s++) {
+ if (*s == '/') {
+ *s = '_';
+ }
}
}
Index: runtime/mercury_trace_base.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_trace_base.h,v
retrieving revision 1.52
diff -u -r1.52 mercury_trace_base.h
--- runtime/mercury_trace_base.h 8 Feb 2006 21:54:30 -0000 1.52
+++ runtime/mercury_trace_base.h 13 Sep 2006 06:49:50 -0000
@@ -213,6 +213,13 @@
extern MR_bool MR_trace_count_enabled;
/*
+** MR_trace_counts_file records the filename to use when dumping trace counts.
+** It may be NULL, in which case a unique file name will be generated.
+*/
+
+extern char *MR_trace_counts_file;
+
+/*
** MR_trace checks whether MR_trace_func_enabled is true, and return
** immediately if it is not.
**
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.165
diff -u -r1.165 mercury_wrapper.c
--- runtime/mercury_wrapper.c 28 Aug 2006 10:13:14 -0000 1.165
+++ runtime/mercury_wrapper.c 13 Sep 2006 06:37:19 -0000
@@ -1042,6 +1042,7 @@
MR_TABLING_STATISTICS_OPT,
MR_TRACE_COUNT_OPT,
MR_COVERAGE_TEST_OPT,
+ MR_TRACE_COUNT_FILE,
MR_MEM_USAGE_REPORT
};
@@ -1112,6 +1113,7 @@
{ "tabling-statistics", 0, 0, MR_TABLING_STATISTICS_OPT },
{ "trace-count", 0, 0, MR_TRACE_COUNT_OPT },
{ "coverage-test", 0, 0, MR_COVERAGE_TEST_OPT },
+ { "tc-output-file", 1, 0, MR_TRACE_COUNT_FILE },
{ "mem-usage-report", 0, 0, MR_MEM_USAGE_REPORT },
/* This needs to be kept at the end. */
@@ -1502,6 +1504,10 @@
MR_trace_count_enabled = MR_TRUE;
break;
+ case MR_TRACE_COUNT_FILE:
+ MR_trace_counts_file = MR_copy_string(MR_optarg);
+ break;
+
case MR_MEM_USAGE_REPORT:
mem_usage_report = MR_TRUE;
break;
Index: scripts/mtc
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mtc,v
retrieving revision 1.1
diff -u -r1.1 mtc
--- scripts/mtc 17 Mar 2005 02:29:44 -0000 1.1
+++ scripts/mtc 13 Sep 2006 07:50:28 -0000
@@ -10,7 +10,7 @@
# that the manpage still looks OK.
Help="\
Name: mtc - gathering trace counts from Mercury programs
-Usage: mtc <executable> [<args>]...
+Usage: mtc [options] <executable> [<args>]...
Description:
\`mtc' invokes the specified command \`<executable> <args>...'.
If that command is a Mercury program that was compiled with debugging
@@ -21,10 +21,21 @@
Otherwise, mtc will execute the command line as if the mtc prefix
weren't there.
+Options:
+ -o <file-name>, --output-file <file-name>
+ Save the generated trace counts to <file-name>. If this
+ option is not given then a filename is automatically
+ generated.
+
+ --help
+ Display this message.
+
Environment variables:
MERCURY_OPTIONS.
"
+output_file=""
+
#-----------------------------------------------------------------------------#
#
# process the command line options
@@ -35,6 +46,24 @@
exit 1 ;;
esac
+while : ; do
+ case "$1" in
+ --help)
+ echo "$Help"
+ exit 0 ;;
+ -o|--output-file)
+ output_file="$2";
+ shift; shift ;;
+ --)
+ shift; break ;;
+ -*)
+ echo "$0: unknown option \`$1'" 1>&2
+ exit 1 ;;
+ *)
+ break ;;
+ esac
+done
+
#-----------------------------------------------------------------------------#
#
# Set the environment variables used by the Mercury runtime to the
@@ -42,7 +71,13 @@
# and then finally use $invoke_cmd to invoke the command.
#
-enable_trace_count_opt="--trace-count"
+case $output_file in
+ "") enable_trace_count_opt="--trace-count"
+ ;;
+ *) enable_trace_count_opt="--trace-count --tc-output-file $output_file"
+ ;;
+esac
+
MERCURY_OPTIONS="$MERCURY_OPTIONS $enable_trace_count_opt"
export MERCURY_OPTIONS
exec "$@"
Index: tests/debugger/declarative/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/Mmakefile,v
retrieving revision 1.95
diff -u -r1.95 Mmakefile
--- tests/debugger/declarative/Mmakefile 22 Aug 2006 02:33:51 -0000 1.95
+++ tests/debugger/declarative/Mmakefile 13 Sep 2006 07:31:10 -0000
@@ -285,13 +285,13 @@
dice.pass: dice
/bin/rm -f .mercury_trace_counts.*dice.*
- MERCURY_OPTIONS=--trace-count ./dice 1 2 3 4 && \
- mv .mercury_trace_counts.*dice.* dice.pass
+ MERCURY_OPTIONS="--trace-count --tc-output-file dice.pass" \
+ ./dice 1 2 3 4
dice.fail: dice
/bin/rm -f .mercury_trace_counts.*dice.*
- MERCURY_OPTIONS=--trace-count ./dice 4 1 2 3 && \
- mv .mercury_trace_counts.*dice.* dice.fail
+ MERCURY_OPTIONS="--trace-count --tc-output-file dice.fail" \
+ ./dice 4 1 2 3
dice.out: dice dice.inp dice.pass dice.fail
$(MDB_STD) ./dice 4 1 2 3 < dice.inp > dice.out 2>&1
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions: mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the developers
mailing list