+ return offset;
+}
+
+static StgThreadID previous_tid = 0;
+
+static void
+send_ThreadId(StgTSO *current_tso) {
+ // This assumes that there is no real thread 0.
+ StgThreadID tid = (current_tso == 0) ? 0 : current_tso->id;
+ if (tid != previous_tid) {
+ previous_tid = tid;
+ // How do we print StgWord32's without a cast?
+ fprintf(rixFile,"Thread Switch %d\n",(unsigned int)tid);
+ }
+}
+
+/*
+ * Called on *every* exception thrown
+ */
+void
+hs_hpc_event(char *msg,StgTSO *current_tso) {
+ // Assumes that we have had at least *one* tick first.
+ // All exceptions before the first tick are not reported.
+ // The only time this might be an issue is in bootstrapping code,
+ // so this is a feature.
+
+ // This is called on *every* exception, even when Hpc is not enabled.
+
+ if (rixFile != NULL) {
+ assert(hpc_inited != 0);
+ send_ThreadId(current_tso);
+ fprintf(rixFile,"%s\n",msg);
+ }
+}
+
+/* Called on every tick, dynamically to our file record of program execution
+ */
+
+void
+hs_hpc_tick(int globIx, StgTSO *current_tso) {
+#if DEBUG_HPC && DEBUG
+ printf("hs_hpc_tick(%d)\n",globIx);
+#endif
+ assert(hpc_inited != 0);
+ if (rixFile != NULL) {
+ send_ThreadId(current_tso);
+ fprintf(rixFile,"%d\n",globIx);
+ }
+
+#if DEBUG_HPC
+ printf("end: hs_hpc_tick\n");
+#endif
+