for review: enhancement for profiling

Thomas Charles CONWAY conway at cs.mu.oz.au
Tue Jul 22 14:21:34 AEST 1997


Hi

For whovever (petdr? fjh?) to review:
-- 
ZZ:wq!
^X^C
Thomas Conway               				      conway at cs.mu.oz.au
AD DEUM ET VINUM	  			      Every sword has two edges.


Enhance the runtime support for profiling so that the profiling data
gets written out if the program terminates through a call to exit
rather than by main terminating. This enables profiling to work with
the Tcl/Tk and OpenGL stuff (for example).

runtime/prof.c
	Register a function for writing out profiling info with atexit.
	Make the functions for writing out the profiling info check to
	see if it has been written out yet, and return straight away if
	it has.

cvs diff: Diffing .
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/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
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/graphics
cvs diff: Diffing extras/graphics/Togl-1.2
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/prof.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/prof.c,v
retrieving revision 1.29
diff -u -r1.29 prof.c
--- prof.c	1997/02/12 02:16:08	1.29
+++ prof.c	1997/07/21 04:32:03
@@ -101,12 +101,20 @@
 #ifdef PROFILE_CALLS
 static	FILE	 	*declfptr = NULL;
 static	prof_call_node	*addr_pair_table[CALL_TABLE_SIZE] = {NULL};
+static	bool		addr_pair_table_written = FALSE;
+static	bool		profiling_on = FALSE;
 #endif
 
 #ifdef PROFILE_TIME
 static	prof_time_node	*addr_table[TIME_TABLE_SIZE] = {NULL};
+static	bool		addr_table_written = FALSE;
 #endif
 
+/*
+** Local function declarations
+*/
+static	void prof_finish(void);
+
 /* ======================================================================== */
 
 #ifndef HAVE_STRERROR
@@ -168,6 +176,18 @@
 	}
 }
 
+static void
+checked_atexit(void (*func)(void))
+{
+	errno = 0;
+	if (atexit(func) != 0) {
+		fprintf(stderr,
+			"Mercury runtime: error in call to atexit %s\n",
+			strerror(errno));
+		exit(1);
+	}
+}
+
 #endif /* defined(PROFILE_TIME) || defined(PROFILE_CALLS) */
 
 #ifdef	PROFILE_TIME
@@ -245,6 +265,10 @@
 	fprintf(fptr, "%d %d\n", HZ, CLOCK_TICKS);
 	checked_fclose(fptr, "Prof.Counts");
 
+	checked_atexit(prof_finish);
+
+	profiling_on = TRUE;
+
 	itime.it_value.tv_sec = 0;
 	itime.it_value.tv_usec = (long) (USEC / HZ) * CLOCK_TICKS; 
 	itime.it_interval.tv_sec = 0;
@@ -252,6 +276,7 @@
 
 	checked_signal(SIGPROF, prof_time_profile);
 	checked_setitimer(ITIMER_PROF, &itime);
+
 }
 
 #endif /* PROFILE_TIME */
@@ -369,6 +394,9 @@
 {
 	struct itimerval itime;
 
+	if (profiling_on == FALSE)
+		return;
+
 	itime.it_value.tv_sec = 0;
 	itime.it_value.tv_usec = 0;
 	itime.it_interval.tv_sec = 0;
@@ -397,12 +425,17 @@
 	FILE		*fptr;
 	int		i;
 
+	if (addr_pair_table_written == TRUE)
+		return;
+
 	fptr = checked_fopen("Prof.CallPair", "create", "w");
 	for (i = 0; i < CALL_TABLE_SIZE ; i++) {
 		print_addr_pair_node(fptr, addr_pair_table[i]);
 	}
 
 	checked_fclose(fptr, "Prof.CallPair");
+
+	addr_pair_table_written = TRUE;
 }
 
 static void
@@ -460,12 +493,17 @@
 	FILE *fptr;
 	int  i;
 
+	if (addr_table_written == TRUE)
+		return;
+
 	fptr = checked_fopen("Prof.Counts", "append to", "a");
 	for (i = 0; i < TIME_TABLE_SIZE ; i++) {
 		print_time_node(fptr, addr_table[i]);
 	}
 
 	checked_fclose(fptr, "Prof.Counts");
+
+	addr_table_written = TRUE;
 }
 
 static void
@@ -481,3 +519,17 @@
 }
 
 #endif /* PROFILE_TIME */
+
+void prof_finish()
+{
+
+#ifdef PROFILE_TIME
+	prof_turn_off_time_profiling();
+	prof_output_addr_table();
+#endif
+
+#ifdef PROFILE_CALLS
+	prof_output_addr_pair_table();
+#endif
+}
+
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/diff
cvs diff: Diffing scripts
cvs diff: Diffing tools
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list