[MLton-devel] Profiling for NetBSD

Jesper Louis Andersen jlouis@mongers.org
Sun, 5 Oct 2003 17:13:22 +0200


The following patch to the GC enables profiling for NetBSD. But of
course the situation is that NetBSD uses their own kind of signal
context which you have to get the eip reg out from. 

I still have a couple of problems with it. First off running

  mlprof tak mlmon.out

doesnt work (we get an exec error for tak), but

  mlprof ./tak mlmon.out

does work.

Second, using the newest compiled mlprof errors with:

  sarah$ /home/jlouis/projects/mlton-rebuild/build/bin/mlprof ./tak \
       mlmon.out

  Error in ./tak: unexpected end of show-prof data

Whereas the older version of mlprof succeeds:

  sarah$ mlprof ./tak mlmon.out
  5.22 seconds of CPU time (0.00 seconds GC)
    function     cur 
  ------------- -----
  Tak.tak1.tak2 76.4%
  Tak.tak1.tak2 23.6%

Now, is there a profiling regression so exercise the code? I expect it
is rather hard to do an <prof>.ok file for a profile run, but...

And now for something completely different (the code):

--- ../../mlton-cvs/mlton/runtime/gc.c	Sun Sep 21 02:19:08 2003
+++ gc.c	Sun Oct  5 15:57:25 2003
@@ -3641,7 +3641,7 @@
 		profileWriteCount (s, p, fd, i + s->sourcesSize);
 }
 
-#if (defined (__linux__) || defined (__FreeBSD__) || defined (__sun__))
+#if (defined (__linux__) || defined (__FreeBSD__) || defined (__sun__) || defined (__NetBSD__))
 
 #ifndef EIP
 #define EIP	14
@@ -3652,7 +3652,13 @@
 /*
  * Called on each SIGPROF interrupt.
  */
+#if (defined (__linux__) || defined (__FreeBSD__) || defined (__sun__))
 static void catcher (int sig, siginfo_t *sip, ucontext_t *ucp) {
+#elif (defined (__NetBSD__))
+static void catcher (int sig, int code, struct sigcontext *ucp) {
+#else
+#error nondefined here
+#endif
 	uint frameIndex;
 	pointer pc;
 	GC_state s;
@@ -3665,6 +3671,8 @@
 	pc = (pointer) ucp->uc_mcontext.mc_eip;
 #elif (defined (__sun__))
 	pc = (pointer) ucp->uc_mcontext.gregs[REG_PC];
+#elif (defined (__NetBSD__))
+	pc = (pointer) ucp->sc_eip;
 #else
 #error pc not defined
 #endif
@@ -3761,14 +3769,20 @@
 	catcherState = s;
 	sa.sa_handler = (void (*)(int))catcher;
 	sigemptyset (&sa.sa_mask);
+#if (defined (__linux__) || defined(__FreeBSD__) || defined(__sun__))
 	sa.sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
+#elif (defined (__NetBSD__))
+	sa.sa_flags = SA_ONSTACK | SA_RESTART;
+#else
+#error sa_flags not set
+#endif
 	unless (sigaction (SIGPROF, &sa, NULL) == 0)
 		diee ("sigaction() failed");
 	/* Start the SIGPROF timer. */
 	setProfTimer (10000);
 }
 
-#elif (defined (__CYGWIN__) || defined (__NetBSD__))
+#elif (defined (__CYGWIN__))
 
 /* No time profiling on Cygwin. 
  * There is a check in mlton/main/main.sml to make sure that time profiling is

-- 
j. 



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel