+void endProfiling( void )
+{
+ endHeapProfiling();
+}
+#endif /* DEBUG_HEAP_PROF */
+
+/* --------------------------------------------------------------------------
+ * Initialize the heap profilier
+ * ----------------------------------------------------------------------- */
+nat
+initHeapProfiling(void)
+{
+ if (! RtsFlags.ProfFlags.doHeapProfile) {
+ return 0;
+ }
+
+#ifdef PROFILING
+ if (doingLDVProfiling() && doingRetainerProfiling()) {
+ prog_belch("cannot mix -hb and -hr");
+ stg_exit(1);
+ }
+#endif
+
+ // we only count eras if we're doing LDV profiling. Otherwise era
+ // is fixed at zero.
+#ifdef PROFILING
+ if (doingLDVProfiling()) {
+ era = 1;
+ } else
+#endif
+ {
+ era = 0;
+ }
+
+ { // max_era = 2^LDV_SHIFT
+ nat p;
+ max_era = 1;
+ for (p = 0; p < LDV_SHIFT; p++)
+ max_era *= 2;
+ }
+
+ n_censuses = 32;
+ censuses = stgMallocBytes(sizeof(Census) * n_censuses, "initHeapProfiling");
+
+ initEra( &censuses[era] );
+
+ fprintf(hp_file, "JOB \"%s", prog_argv[0]);
+
+#ifdef PROFILING
+ {
+ int count;
+ for(count = 1; count < prog_argc; count++)
+ fprintf(hp_file, " %s", prog_argv[count]);
+ fprintf(hp_file, " +RTS ");
+ for(count = 0; count < rts_argc; count++)
+ fprintf(hp_file, "%s ", rts_argv[count]);
+ fprintf(hp_file, "\n");
+ }
+#endif /* PROFILING */
+
+ fprintf(hp_file, "\"\n" );
+
+ fprintf(hp_file, "DATE \"%s\"\n", time_str());
+
+ fprintf(hp_file, "SAMPLE_UNIT \"seconds\"\n");
+ fprintf(hp_file, "VALUE_UNIT \"bytes\"\n");
+
+ fprintf(hp_file, "BEGIN_SAMPLE 0.00\n");
+ fprintf(hp_file, "END_SAMPLE 0.00\n");
+
+#ifdef DEBUG_HEAP_PROF
+ DEBUG_LoadSymbols(prog_argv[0]);
+#endif
+
+#ifdef PROFILING
+ if (doingRetainerProfiling()) {
+ initRetainerProfiling();
+ }
+#endif
+
+ return 0;
+}
+
+void
+endHeapProfiling(void)
+{
+ StgDouble seconds;
+
+ if (! RtsFlags.ProfFlags.doHeapProfile) {
+ return;
+ }
+
+#ifdef PROFILING
+ if (doingRetainerProfiling()) {
+ endRetainerProfiling();
+ }
+#endif
+
+#ifdef PROFILING
+ if (doingLDVProfiling()) {
+ nat t;
+ LdvCensusKillAll();
+ aggregateCensusInfo();
+ for (t = 1; t < era; t++) {
+ dumpCensus( &censuses[t] );
+ }
+ }
+#endif
+
+ seconds = mut_user_time();
+ fprintf(hp_file, "BEGIN_SAMPLE %0.2f\n", seconds);
+ fprintf(hp_file, "END_SAMPLE %0.2f\n", seconds);
+ fclose(hp_file);