diff: mprof_merge_runs

Fergus Henderson fjh at cs.mu.oz.au
Sun Oct 12 02:10:09 AEST 1997


Hi,

Anyone want to review this one?

scripts/mprof_merge_runs:
	New file.  A script for merging multiple runs into a single
	profile.

scripts/Mmakefile:
	Add mprof_merge_runs to the list of scripts.

doc/Mmakefile:
	Add mprof_merge_runs to the list of things which need manpages.
	(The manpage will be created automatically by `make_manpage'.)

doc/user_guide.texi:
	Document the use of mprof_merge_runs.

cvs diff -N doc/Mmakefile doc/user_guide.texi scripts/Mmakefile scripts/mprof_merge_runs
Index: doc/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/mercury/doc/Mmakefile,v
retrieving revision 1.5
diff -u -r1.5 Mmakefile
--- Mmakefile	1997/07/27 15:05:39	1.5
+++ Mmakefile	1997/10/10 04:45:58
@@ -75,7 +75,7 @@
 	library_1.html faq_1.html transition_guide_1.html
 
 .PHONY: manpages
-manpages: c2init.1 mmc.1 mgnuc.1 ml.1 mmake.1 msc.1 mprof.1
+manpages: c2init.1 mmc.1 mgnuc.1 ml.1 mmake.1 msc.1 mprof.1 mprof_merge_runs.1
 
 #-----------------------------------------------------------------------------#
 
Index: doc/user_guide.texi
===================================================================
RCS file: /home/staff/zs/imp/mercury/doc/user_guide.texi,v
retrieving revision 1.100
diff -u -r1.100 user_guide.texi
--- user_guide.texi	1997/10/09 09:39:41	1.100
+++ user_guide.texi	1997/10/10 05:24:17
@@ -919,9 +919,9 @@
 records the number of times that execution was in each procedure
 when a profiling interrupt occurred.)
 
-It would be nice if there was a way to combine profiling data from
-multiple runs of the same program, but unfortunately there is not yet
-any way to do that.
+It is also possible to combine profiling results from multiple runs of
+your program.  You can do by running your program several times, and
+typing @samp{mprof_merge_counts} after each run.
 
 Due to a known timing-related bug in our code, you may occasionally get
 segmentation violations when running your program with time profiling enabled.
Index: scripts/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/mercury/scripts/Mmakefile,v
retrieving revision 1.3
diff -u -r1.3 Mmakefile
--- Mmakefile	1997/07/27 15:09:28	1.3
+++ Mmakefile	1997/10/10 04:45:11
@@ -14,7 +14,7 @@
 
 #-----------------------------------------------------------------------------#
 
-SCRIPTS = mmake mmc mod2c c2init mgnuc ml mprof mint \
+SCRIPTS = mmake mmc mod2c c2init mgnuc ml mprof mprof_merge_runs mint \
 	  sicstus_conv mtags vpath_find mercury_update_interface \
 	  mkfifo_using_mknod
 NUPROLOG_SCRIPTS = mnc mnl mnp
@@ -31,6 +31,10 @@
 
 .PHONY: all
 all: $(SCRIPTS) $(NUPROLOG_SCRIPTS) $(SICSTUS_SCRIPTS) Mmake.vars
+
+#-----------------------------------------------------------------------------#
+
+ml mgnuc: init_grade_options.sh-subr parse_grade_options.sh-subr
 
 #-----------------------------------------------------------------------------#
 
Index: scripts/mprof_merge_runs
===================================================================
RCS file: mprof_merge_runs
diff -N mprof_merge_runs
--- /dev/null	Sun Oct 12 01:32:39 1997
+++ mprof_merge_runs	Sun Oct 12 02:06:15 1997
@@ -0,0 +1,148 @@
+#! /bin/sh
+# @configure_input@
+#---------------------------------------------------------------------------#
+# Copyright (C) 1997 University of Melbourne.
+# This file may only be copied under the terms of the GNU General
+# Public License - see the file COPYING in the Mercury distribution.
+#---------------------------------------------------------------------------#
+#
+# mprof_merge_counts - 
+#
+# Merges the profiling counts from different runs of a profiled program.
+#
+# Usage: see below.
+
+Help="\
+Name: mprof_merge_runs - Mercury Profiling utility
+
+Description:
+	mprof_merge_runs merges the profiling data from different
+	runs of a profiled Mercury program, for use by \`mprof'.
+
+Usage:
+	# compile with profiling enabled
+	mc --profiling my_program	
+
+	# collect the profiling data
+	./my_program  args for first run
+	mprof_merge_runs
+	./my_program  args for second run
+	mprof_merge_runs
+	./my_program  args for third run
+	mprof_merge_runs
+
+	# display the profile
+	mprof -c | more
+
+Note:
+	If you just want to run your program N times with the same arguments,
+	a simpler way of achieving this is to instead use the \`-r<N>'
+	(\"repeat N times\") option to the Mercury runtime, which you can
+	pass by setting the environment variable MERCURY_OPTIONS, e.g.
+	with the following command:
+
+		env MERCURY_OPTIONS="-r100" ./my_program
+
+Options:
+	-h, --help
+		Print this help message."
+
+while true; do
+    case "$1" in
+	-h|--help|"-?")
+		echo "$Help"
+		exit 0
+		;;
+	--)
+		shift
+		break ;;
+	*)
+		break ;;
+    esac
+done
+
+case $# in
+	0) ;;
+	*) echo "$Help" 1>&2; exit 1 ;;
+esac
+
+#
+# The Prof.Counts file format is as follows:
+#	clock-frequency	tick-rate
+#	address1 count1
+#	address2 count2
+#	...
+#	addressN countN
+#
+# To merge two different count files, we just need to
+# add up the counts for each address.
+#
+touch Prof.Counts.total &&
+awk '
+	FNR == 1 { clock = $1; rate = $2; }
+	FNR != 1 { counts[$1] += $2; }
+	END {
+		printf("%d %d\n", clock, rate); 
+		for (addr in counts) {
+			printf("%d %d\n", addr, counts[addr]);
+		}
+	}
+' Prof.Counts.total Prof.Counts > Prof.Counts.newtotal &&
+#
+# The Prof.CallPair file format is as follows:
+#	caller1 callee1 count1
+#	caller2 callee2 count2
+#	...
+#	callerN calleeN countN
+#
+# To merge two different count files, we just need to
+# add up the counts for each pair of addresses.
+#
+touch Prof.CallPair.total &&
+awk '
+	{ pair_counts[$1 " " $2] += $3; }
+	END {
+		for (addrpair in pair_counts) {
+			printf("%s %d\n", addrpair, pair_counts[addr]);
+		}
+	}
+' Prof.CallPair.total Prof.CallPair > Prof.CallPair.newtotal &&
+#
+# The Prof.Decl file format is as follows:
+#	addr1 name1
+#	addr2 name2
+#	...
+#	addrN nameN
+#
+# To merge two different Prof.Decl files, we need to
+# add up the counts for each pair of addresses.
+#
+touch Prof.Decl.total &&
+: > Prof.Decl.warnings &&
+awk '
+	{ 
+		addr = $1; nm = $2;
+		if (name[addr] == "") {
+			name[addr] = nm;
+		} else {
+			if (name[addr] != nm) {
+				printf("Warning: multiple names for address %s: %s and %s.\n", addr, name[addr], nm) >> "Prof.Decl.warnings" ;
+				printf "Name %s ignored.", nm >> "Prof.Decl.warnings" ;
+			}
+		}
+	}
+	END {
+		for (addr in name) {
+			printf("%s %s\n", addr, name[addr]);
+		}
+	}
+' Prof.Decl.total Prof.Decl > Prof.Decl.newtotal &&
+cat Prof.Decl.warnings >& 2 &&
+rm -f Prof.Decl.warnings &&
+mv Prof.Counts.newtotal Prof.Counts.total &&
+mv Prof.CallPair.newtotal Prof.CallPair.total &&
+mv Prof.Decl.newtotal Prof.Decl.total &&
+cp Prof.Counts.total Prof.Counts &&
+cp Prof.CallPair.total Prof.CallPair &&
+cp Prof.Decl.total Prof.Decl &&
+exit 0


-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list