whitespace
[ghc-hetmet.git] / rts / RtsStartup.c
index 67430dc..c2f765a 100644 (file)
@@ -6,13 +6,14 @@
  *
  * ---------------------------------------------------------------------------*/
 
-#include "PosixSource.h"
+// PAPI uses caddr_t, which is not POSIX
+// #include "PosixSource.h"
+
 #include "Rts.h"
 #include "RtsAPI.h"
 #include "RtsUtils.h"
 #include "RtsFlags.h"  
 #include "OSThreads.h"
-#include "Storage.h"    /* initStorage, exitStorage */
 #include "Schedule.h"   /* initScheduler */
 #include "Stats.h"      /* initStats */
 #include "STM.h"        /* initSTM */
@@ -30,6 +31,7 @@
 #include "Trace.h"
 #include "RtsTypeable.h"
 #include "Stable.h"
+#include "Hpc.h"
 
 #if defined(RTS_GTK_FRONTPANEL)
 #include "FrontPanel.h"
 #include <signal.h>
 #endif
 
+#if USE_PAPI
+#include "Papi.h"
+#endif
+
 // Count of how many outstanding hs_init()s there have been.
 static int hs_init_count = 0;
 
@@ -152,7 +158,32 @@ hs_init(int *argc, char **argv[])
     argv++; argc--;
 #endif
 
+    /* Initialise the performance tracking library */
+#ifdef USE_PAPI
+    {
+       int ver;
+       if ((ver = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
+           if (ver > 0) {
+               errorBelch("PAPI_library_init: wrong version: %x", ver);
+               stg_exit(EXIT_FAILURE);
+           } else {
+               sysErrorBelch("PAPI_library_init");
+               stg_exit(EXIT_FAILURE);
+           }
+       }
+    }
+#ifdef THREADED_RTS
+    {
+       int err;
+       if ((err = PAPI_thread_init(osThreadId)) < 0) {
+           barf("PAPI_thread_init: %d",err);
+       }
+    }
+#endif
+#endif
+
     /* Set the RTS flags to default values. */
+
     initRtsFlagsDefaults();
 
     /* Call the user hook to reset defaults, if present */