[m-dev.] for review: make profiling handle control-c

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 15 17:08:16 AEDT 2001


On 15-Jan-2001, Thomas Conway <conway at cs.mu.OZ.AU> wrote:
> On Mon, Jan 15, 2001 at 04:12:08PM EST, Anthony Lee SENYARD wrote:
> > That is odd.  I tried to do this (compile in profiling grade, run for a
> > while then hit ctrl-c) on roy and no profiling information was generated.
> > I asked Tyson and he indicated that ctrl-c and exceptions were not handled
> > by the profiler.

Tyson is right.

> If you're using asm_fast.gc.prof then it should be happening - to
> check, you could use -g in your MLFLAGS to prevent the executable
> from being stripped, and use gdb to check that `checked_atexit' is
> begin called.

Functions registered with atexit() are not called if the
program exits because of an unhandled SIGINT signal.

The following patch should handle it.

----------

Estimated hours taken: 0.5

runtime/mercury_prof.c:
	If profiling is enabled, register a SIGINT signal handler,
	so that we call MR_prof_finish() if we get a control-C.

Workspace: /home/hg/fjh/mercury
Index: runtime/mercury_prof.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_prof.c,v
retrieving revision 1.14
diff -u -d -r1.14 mercury_prof.c
--- runtime/mercury_prof.c	2000/11/23 02:00:36	1.14
+++ runtime/mercury_prof.c	2001/01/15 06:06:16
@@ -28,9 +28,9 @@
 #include        "mercury_std.h"
 #include	"mercury_timing.h"
 
-#if defined(PROFILE_TIME)
+#include	<signal.h>		/* for SIGINT */
 
-#include	<signal.h>
+#if defined(PROFILE_TIME)
 
 #ifdef HAVE_SYS_TIME
 #include	<sys/time.h>
@@ -137,6 +137,9 @@
 		MR_memprof_record *node);
 #endif
 
+#if defined(PROFILE_TIME) || defined(PROFILE_CALLS) || defined(PROFILE_MEMORY)
+  static void prof_handle_sigint(void);
+#endif
 
 /* ======================================================================== */
 
@@ -607,8 +610,21 @@
 
 #if defined(PROFILE_TIME) || defined(PROFILE_CALLS) || defined(PROFILE_MEMORY)
 	checked_atexit(MR_prof_finish);
+  #ifdef SIGINT
+	MR_setup_signal(SIGINT, prof_handle_sigint, FALSE,
+		"Mercury runtime: cannot install signal handler");
+  #endif
 #endif
 }
+
+#if defined(PROFILE_TIME) || defined(PROFILE_CALLS) || defined(PROFILE_MEMORY)
+static void
+prof_handle_sigint(void)
+{
+  /* exit() will call MR_prof_finish(), which we registered with atexit(). */
+  exit(1);
+}
+#endif
 
 void
 MR_prof_finish(void)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list