[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / runtime / profiling / CostCentre.lc
index 01a801d..2d084c2 100644 (file)
@@ -18,10 +18,6 @@ CC_DECLARE(CC_IDLE, "IDLE", "IDLE", "IDLE", CC_IS_BORING,/*not static*/);
 # endif
 \end{code}
 
-The current cost centre. It is initially set to "MAIN" by main.
-We have to be careful when doing so, as an initial @SET_CCC(CC_MAIN)@
-would try to increment some @sub_scc_count@ of the @CCC@ (nothing!).
-
 \begin{code}
 CostCentre CCC; /* _not_ initialised */
 
@@ -43,9 +39,9 @@ Cost centres which are always required:
 \begin{code}
 #if defined(PROFILING)
 
-CC_DECLARE(CC_OVERHEAD,  "OVERHEAD_of", "PROFILING", "MAIN", CC_IS_CAF,/*not static*/);
-CC_DECLARE(CC_SUBSUMED,  "SUBSUMED",    "MAIN",      "MAIN", CC_IS_SUBSUMED,/*not static*/);
-CC_DECLARE(CC_DONTZuCARE,"DONT_CARE",   "MAIN",      "MAIN", CC_IS_BORING,/*not static*/);
+CC_DECLARE(CC_OVERHEAD,  "OVERHEAD_of", "PROFILING", "PROFILING", CC_IS_CAF,      /*not static*/);
+CC_DECLARE(CC_SUBSUMED,  "SUBSUMED",    "MAIN",      "MAIN",      CC_IS_SUBSUMED, /*not static*/);
+CC_DECLARE(CC_DONTZuCARE,"DONT_CARE",   "MAIN",      "MAIN",      CC_IS_BORING,   /*not static*/);
 #endif
 \end{code}
 
@@ -79,15 +75,6 @@ init_cc_profiling(rts_argc, rts_argv, prog_argv)
     char *rts_argv[], *prog_argv[];
 {
     I_ arg, ch;
-#ifndef PAR
-    char *select_cc = 0;
-    char *select_mod = 0;
-    char *select_grp = 0;
-    char *select_descr = 0;
-    char *select_type = 0;
-    char *select_kind = 0;
-    char *left, *right;
-#endif
 
     prog_argv_save = prog_argv;
     rts_argv_save = rts_argv;
@@ -150,9 +137,7 @@ init_cc_profiling(rts_argc, rts_argv, prog_argv)
     }
 
 #if defined(PROFILING)
-    if (heap_profile_init(select_cc, select_mod, select_grp,
-                         select_descr, select_type, select_kind,
-                         prog_argv))
+    if (heap_profile_init(prog_argv))
        return 1;
 #endif
     
@@ -185,9 +170,7 @@ cc_register()
     REGISTER_CC(CC_DONTZuCARE);        /* register cost centre CC_DONT_CARE Right??? ToDo */
 #endif
 
-    /* as per SET_CCC macro, without the sub_scc_count++ bit */
-    CCC = (CostCentre)STATIC_CC_REF(CC_MAIN);
-    CCC->scc_count++;
+    SET_CCC_RTS(CC_MAIN,0,1);   /* without the sub_scc_count++ */
 
 #if defined(PROFILING)
 /*  always register -- if we do not, we get warnings (WDP 94/12) */
@@ -228,6 +211,23 @@ cc_to_ignore (CostCentre cc)
 #   endif /* PROFILING */
 }
 
+rtsBool
+have_interesting_groups(CostCentre cc)
+{
+    char* interesting_group = NULL;
+
+    for (; cc != REGISTERED_END; cc = cc->registered) {
+       if (! cc_to_ignore(cc) && strcmp(cc->module,cc->group) != 0) {
+           if (interesting_group && strcmp(cc->group, interesting_group) != 0) {
+               return(rtsTrue);
+           } else {
+               interesting_group = cc->group;
+           }
+       }
+    }
+    return(rtsFalse);
+}
+
 void
 report_cc_profiling(final)
   I_ final;
@@ -236,16 +236,24 @@ report_cc_profiling(final)
     CostCentre cc;
     I_ count;
     char temp[128]; /* sigh: magic constant */
-    W_ total_ticks   = 0, total_alloc   = 0, total_allocs   = 0;
-    W_ ignored_ticks = 0, ignored_alloc = 0, ignored_allocs = 0;
+    W_ total_ticks, ignored_ticks;
+    W_ total_alloc = 0, total_allocs = 0;
+    rtsBool do_groups = rtsFalse;
 #ifdef PAR
-    I_ final_ticks = 0;                                /*No. ticks in last sample*/
+    I_ final_ticks;                            /*No. ticks in last sample*/
 #endif
 
     if (!RTSflags.CcFlags.doCostCentres)
        return;
 
     blockVtAlrmSignal();
+    /* To avoid inconsistency, initialise the tick variables
+       after having blocked out VTALRM */
+    total_ticks = 0;
+    ignored_ticks = 0;
+#ifdef PAR
+    final_ticks = 0;
+#endif
 
     if (serial_file) {
        StgFloat seconds = (previous_ticks + current_ticks) / (StgFloat) TICK_FREQUENCY;
@@ -301,12 +309,12 @@ report_cc_profiling(final)
 
        if ( cc_to_ignore(cc) ) { /* reporting these just confuses users... */
            ignored_ticks  += cc->prev_ticks;
-           ignored_alloc  += cc->mem_alloc;
-           ignored_allocs += cc->mem_allocs;
        } else {
            total_ticks  += cc->prev_ticks;
            total_alloc  += cc->mem_alloc;
+#if defined(PROFILING_DETAIL_COUNTS)
            total_allocs += cc->mem_allocs;
+#endif
        }
     }
 
@@ -343,21 +351,33 @@ report_cc_profiling(final)
        fprintf(prof_file, " %s", prog_argv_save[count]);
     fprintf(prof_file, "\n\n");
 
+
     fprintf(prof_file, "\ttotal time  = %11.2f secs   (%lu ticks @ %d ms)\n",
-      total_ticks / (StgFloat) TICK_FREQUENCY, total_ticks, TICK_MILLISECS);
-    fprintf(prof_file, "\ttotal alloc = %11s bytes  (%lu closures)  (excludes profiling overheads)\n",
-      ullong_format_string((ullong) total_alloc * sizeof(W_), temp, rtsTrue/*commas*/), total_allocs);
+           total_ticks / (StgFloat) TICK_FREQUENCY, total_ticks, TICK_MILLISECS);
+    fprintf(prof_file, "\ttotal alloc = %11s bytes",
+           ullong_format_string((ullong) total_alloc * sizeof(W_), temp, rtsTrue/*commas*/));
     /* ToDo: 64-bit error! */
-    fprintf(prof_file, "\n");
+
+#if defined(PROFILING_DETAIL_COUNTS)
+    fprintf(prof_file, "  (%lu closures)", total_allocs);
+#endif
+    fprintf(prof_file, "  (excludes profiling overheads)\n\n");
+
 
     fprintf(prof_file, "%-16.16s %-11.11s", "COST CENTRE", "MODULE");
-/* ToDo:group
-    fprintf(prof_file, " %-11.11s", "GROUP");
-*/
-    fprintf(prof_file, " %5s %5s %6s %6s", "scc", "subcc", "%time", "%alloc");
 
-    if (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE)
-       fprintf(prof_file, " %11s  %13s %8s %8s %8s (%5s %8s)", "cafcc", "thunks", "funcs", "PAPs", "closures", "ticks", "bytes");
+    do_groups = have_interesting_groups(Registered_CC);
+    if (do_groups) fprintf(prof_file, " %-11.11s", "GROUP");
+
+    fprintf(prof_file, "%8s %6s %6s %8s %5s %5s", "scc", "%time", "%alloc", "inner", "cafs", "dicts");
+
+    if (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE) {
+       fprintf(prof_file, "  %5s %9s", "ticks", "bytes");
+#if defined(PROFILING_DETAIL_COUNTS)
+       fprintf(prof_file, "  %8s %8s %8s %8s %8s %8s %8s",
+               "closures", "thunks", "funcs", "PAPs", "subfuns", "subcafs", "cafssub");
+#endif
+    }
     fprintf(prof_file, "\n\n");
 
     for (cc = Registered_CC; cc != REGISTERED_END; cc = cc->registered) {
@@ -368,28 +388,33 @@ report_cc_profiling(final)
        if ( (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_ALL
                /* force printing of *all* cost centres if -P -P */ )
 
-         || ( ! cc_to_ignore(cc)
-           && (cc->scc_count || cc->sub_scc_count || cc->prev_ticks || cc->mem_alloc
-               || (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE
-                   && (cc->thunk_count || cc->function_count || cc->pap_count
-                    || cc->cafcc_count || cc->sub_cafcc_count))))
-          ) {
-
+            || ( ! cc_to_ignore(cc)
+                 && (cc->scc_count || cc->sub_scc_count || cc->prev_ticks || cc->mem_alloc
+                     || (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE
+                         && (cc->sub_cafcc_count || cc->sub_dictcc_count
+#if defined(PROFILING_DETAIL_COUNTS)
+                             || cc->thunk_count || cc->function_count || cc->pap_count
+#endif
+          ))))) {
            fprintf(prof_file, "%-16.16s %-11.11s", cc->label, cc->module);
-/* ToDo:group
-           fprintf(prof_file, " %-11.11s",cc->group);
-*/
-           fprintf(prof_file, " %5ld %5ld  %5.1f  %5.1f",
-             cc->scc_count, cc->sub_scc_count,
-             total_ticks == 0 ? 0.0 : (cc->prev_ticks / (StgFloat) total_ticks * 100),
-             total_alloc == 0 ? 0.0 : (cc->mem_alloc / (StgFloat) total_alloc * 100));
-
-           if (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE)
-               fprintf(prof_file, " %8ld %-8ld %8ld %8ld %8ld %8ld (%5ld %8ld)",
-                       cc->cafcc_count, cc->sub_cafcc_count,
-                       cc->thunk_count, cc->function_count, cc->pap_count,
-                       cc->mem_allocs,
-                       cc->prev_ticks, cc->mem_alloc*sizeof(W_));
+           if (do_groups) fprintf(prof_file, " %-11.11s",cc->group);
+
+           fprintf(prof_file, "%8ld  %5.1f  %5.1f %8ld %5ld %5ld",
+                   cc->scc_count, 
+                   total_ticks == 0 ? 0.0 : (cc->prev_ticks / (StgFloat) total_ticks * 100),
+                   total_alloc == 0 ? 0.0 : (cc->mem_alloc / (StgFloat) total_alloc * 100),
+                   cc->sub_scc_count, cc->sub_cafcc_count, cc->sub_dictcc_count);
+
+           if (RTSflags.CcFlags.doCostCentres >= COST_CENTRES_VERBOSE) {
+               fprintf(prof_file, "  %5ld %9ld", cc->prev_ticks, cc->mem_alloc*sizeof(W_));
+#if defined(PROFILING_DETAIL_COUNTS)
+               fprintf(prof_file, "  %8ld %8ld %8ld %8ld %8ld %8ld %8ld",
+                       cc->mem_allocs, cc->thunk_count,
+                       cc->function_count, cc->pap_count,
+                       cc->subsumed_fun_count, cc->subsumed_caf_count,
+                       cc->caffun_subsumed);
+#endif
+           }
            fprintf(prof_file, "\n");
        }
     }
@@ -452,11 +477,6 @@ cc_gt_time(CostCentre cc1, CostCentre cc2)
     else if (cc1->mem_alloc < cc2->mem_alloc)       /* time equal; alloc less */
        return 0;
 
-    if (cc1->thunk_count > cc2->thunk_count)        /* time & alloc equal: cmp enters */
-       return 1;
-    else if (cc1->thunk_count < cc2->thunk_count)
-       return 0;
-
     return (cc_lt_label(cc1, cc2));                 /* all data equal: cmp labels */
 }
 
@@ -480,11 +500,6 @@ cc_gt_alloc(CostCentre cc1, CostCentre cc2)
     else if (cc1->prev_ticks < cc2->prev_ticks)     /* alloc equal; time less */ 
         return 0;
 
-    if (cc1->thunk_count > cc2->thunk_count)        /* alloc & time: cmp enters */
-       return 1;
-    else if (cc1->thunk_count < cc2->thunk_count)
-       return 0;
-
     return (cc_lt_label(cc1, cc2));                 /* all data equal: cmp labels */
 }