[project @ 2001-07-02 18:05:10 by rrt]
[ghc-hetmet.git] / ghc / rts / Stats.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Stats.c,v 1.28 2001/07/02 18:05:10 rrt Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Statistics and timing-related functions.
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #define NON_POSIX_SOURCE
11
12 #include "Rts.h"
13 #include "RtsFlags.h"
14 #include "RtsUtils.h"
15 #include "StoragePriv.h"
16 #include "MBlock.h"
17 #include "Schedule.h"
18 #include "Stats.h"
19 #include "ParTicky.h"                       // ToDo: move into Rts.h
20
21 #ifdef HAVE_UNISTD_H
22 #include <unistd.h>
23 #endif
24
25 #ifndef mingw32_TARGET_OS
26 # ifdef HAVE_SYS_TIMES_H
27 #  include <sys/times.h>
28 # endif
29 #endif
30
31 #ifdef HAVE_SYS_TIME_H
32 #include <sys/time.h>
33 #endif
34
35 #ifdef __CYGWIN32__
36 # ifdef HAVE_TIME_H
37 #  include <time.h>
38 # endif
39 #endif
40
41 #if ! irix_TARGET_OS && ! defined(mingw32_TARGET_OS)
42 # if defined(HAVE_SYS_RESOURCE_H)
43 #  include <sys/resource.h>
44 # endif
45 #endif
46
47 #ifdef HAVE_SYS_TIMEB_H
48 #include <sys/timeb.h>
49 #endif
50
51 #if HAVE_STDLIB_H
52 #include <stdlib.h>
53 #endif
54
55 #if HAVE_WINDOWS_H
56 #include <windows.h>
57 #endif
58
59 #if defined(PAR) || !(!defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS))
60 #include <sys/resource.h>
61 #endif
62
63 /* huh? */
64 #define BIG_STRING_LEN              512
65
66 /* We're not trying to be terribly accurate here, using the 
67  * basic times() function to get a resolution of about 100ths of a 
68  * second, depending on the OS.  A long int will do fine for holding
69  * these values.
70  */
71 #define TICK_TYPE long int
72 #define TICK_TO_DBL(t) ((double)(t) / TicksPerSecond)
73
74 static int TicksPerSecond = 0;
75
76 static TICK_TYPE ElapsedTimeStart = 0;
77 static TICK_TYPE CurrentElapsedTime = 0;
78 static TICK_TYPE CurrentUserTime    = 0;
79
80 static TICK_TYPE InitUserTime     = 0;
81 static TICK_TYPE InitElapsedTime  = 0;
82 static TICK_TYPE InitElapsedStamp = 0;
83
84 static TICK_TYPE MutUserTime      = 0;
85 static TICK_TYPE MutElapsedTime   = 0;
86 static TICK_TYPE MutElapsedStamp  = 0;
87
88 static TICK_TYPE ExitUserTime     = 0;
89 static TICK_TYPE ExitElapsedTime  = 0;
90
91 static ullong GC_tot_alloc        = 0;
92 static ullong GC_tot_copied       = 0;
93
94 static TICK_TYPE GC_start_time,  GC_tot_time = 0;  /* User GC Time */
95 static TICK_TYPE GCe_start_time, GCe_tot_time = 0; /* Elapsed GC time */
96
97 lnat MaxResidency = 0;     /* in words; for stats only */
98 lnat AvgResidency = 0;
99 lnat ResidencySamples = 0; /* for stats only */
100
101 static lnat GC_start_faults = 0, GC_end_faults = 0;
102
103 static TICK_TYPE *GC_coll_times;
104
105 static void  getTimes(void);
106 static nat   pageFaults(void);
107
108 /* elapsedtime() -- The current elapsed time in seconds */
109
110 #if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
111 #define NS_PER_SEC 10000000LL
112 /* Convert FILETIMEs into secs since the Epoch (Jan1-1970) */
113 #define FT2longlong(ll,ft)    \
114     (ll)=(ft).dwHighDateTime; \
115     (ll) <<= 32;              \
116     (ll) |= (ft).dwLowDateTime; \
117     (ll) /= (unsigned long long) (NS_PER_SEC / CLOCKS_PER_SEC)
118 #endif
119
120 #if defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
121 /* cygwin32 or mingw32 version */
122 static void
123 getTimes(void)
124 {
125     FILETIME creationTime, exitTime, kernelTime, userTime;
126     long long int kT, uT;
127  
128     /* ToDo: pin down elapsed times to just the OS thread(s) that
129        are evaluating/managing Haskell code.
130     */
131     if (!GetProcessTimes (GetCurrentProcess(), &creationTime,
132                           &exitTime, &kernelTime, &userTime)) {
133         /* Probably on a Win95 box..*/
134         return;
135     }
136
137     FT2longlong(kT,kernelTime);
138     FT2longlong(uT,userTime);
139     CurrentElapsedTime = uT + kT;
140     CurrentUserTime = uT;
141 }
142
143 #else /* !win32 */
144
145 static void
146 getTimes(void)
147 {
148
149 # if !defined(HAVE_TIMES)
150     /* We will #ifdef around the fprintf for machines
151        we *know* are unsupported. (WDP 94/05)
152     */
153     fprintf(stderr, "NOTE: `getTimes' does nothing!\n");
154     return 0.0;
155
156 # else /* not stumped */
157     struct tms t;
158     clock_t r = times(&t);
159
160     CurrentElapsedTime = r;
161     CurrentUserTime = t.tms_utime;
162 #endif
163
164 }
165 #endif /* !win32 */
166
167 /* mut_user_time_during_GC() and mut_user_time()
168  *
169  * The former function can be used to get the current mutator time
170  * *during* a GC, i.e. between stat_startGC and stat_endGC.  This is
171  * used in the heap profiler for accurately time stamping the heap
172  * sample.  
173  *
174  * ATTENTION: mut_user_time_during_GC() relies on GC_start_time being 
175  *            defined in stat_startGC() - to minimise system calls, 
176  *            GC_start_time is, however, only defined when really needed (check
177  *            stat_startGC() for details)
178  */
179 double
180 mut_user_time_during_GC(void)
181 {
182   return TICK_TO_DBL(GC_start_time - GC_tot_time);
183 }
184
185 double
186 mut_user_time(void)
187 {
188     getTimes();
189     return TICK_TO_DBL(CurrentUserTime - GC_tot_time);
190 }
191
192 static nat
193 pageFaults(void)
194 {
195   /* ToDo (on NT): better, get this via the performance data
196      that's stored in the registry. */
197 # if !defined(HAVE_GETRUSAGE) || irix_TARGET_OS || defined(mingw32_TARGET_OS) || defined(cygwin32_TARGET_OS)
198     return 0;
199 # else
200     struct rusage t;
201
202     getrusage(RUSAGE_SELF, &t);
203     return(t.ru_majflt);
204 # endif
205 }
206
207 void
208 initStats(void)
209 {
210     nat i;
211     FILE *sf = RtsFlags.GcFlags.statsFile;
212   
213     if (RtsFlags.GcFlags.giveStats >= VERBOSE_GC_STATS) {
214         fprintf(sf, "    Alloc    Collect    Live    GC    GC     TOT     TOT  Page Flts\n");
215         fprintf(sf, "    bytes     bytes     bytes  user  elap    user    elap\n");
216     }
217     GC_coll_times = 
218         (TICK_TYPE *)stgMallocBytes(
219             sizeof(TICK_TYPE)*RtsFlags.GcFlags.generations,
220             "initStats");
221     for (i = 0; i < RtsFlags.GcFlags.generations; i++) {
222         GC_coll_times[i] = 0;
223     }
224 }    
225
226 /* -----------------------------------------------------------------------------
227    Initialisation time...
228    -------------------------------------------------------------------------- */
229
230 void
231 stat_startInit(void)
232 {
233     /* Determine TicksPerSecond ... */
234 #if defined(CLK_TCK)            /* defined by POSIX */
235     TicksPerSecond = CLK_TCK;
236
237 #elif defined(HAVE_SYSCONF)
238     long ticks;
239
240     ticks = sysconf(_SC_CLK_TCK);
241     if ( ticks == -1 ) {
242         fprintf(stderr, "stat_init: bad call to 'sysconf'!\n");
243         stg_exit(EXIT_FAILURE);
244     }
245     TicksPerSecond = ticks;
246
247 /* no "sysconf" or CLK_TCK; had better guess */
248 #elif defined(HZ)
249     TicksPerSecond = HZ;
250
251 #elif defined(CLOCKS_PER_SEC)
252     TicksPerSecond = CLOCKS_PER_SEC;
253
254 #else /* had better guess wildly */
255     /* We will #ifdef around the fprintf for machines
256        we *know* are unsupported. (WDP 94/05)
257     */
258     fprintf(stderr, "NOTE: Guessing `TicksPerSecond = 60'!\n");
259     TicksPerSecond = 60;
260 #endif
261
262     getTimes();
263     ElapsedTimeStart = CurrentElapsedTime;
264 }
265
266 void 
267 stat_endInit(void)
268 {
269     getTimes();
270     InitUserTime = CurrentUserTime;
271     InitElapsedStamp = CurrentElapsedTime; 
272     if (ElapsedTimeStart > CurrentElapsedTime) {
273         InitElapsedTime = 0;
274     } else {
275         InitElapsedTime = CurrentElapsedTime - ElapsedTimeStart;
276     }
277 }
278
279 /* -----------------------------------------------------------------------------
280    stat_startExit and stat_endExit
281    
282    These two measure the time taken in shutdownHaskell().
283    -------------------------------------------------------------------------- */
284
285 void
286 stat_startExit(void)
287 {
288     getTimes();
289     MutElapsedStamp = CurrentElapsedTime;
290     MutElapsedTime = CurrentElapsedTime - GCe_tot_time - InitElapsedStamp;
291     if (MutElapsedTime < 0) { MutElapsedTime = 0; }     /* sometimes -0.00 */
292     
293     /* for SMP, we don't know the mutator time yet, we have to inspect
294      * all the running threads to find out, and they haven't stopped
295      * yet.  So we just timestamp MutUserTime at this point so we can
296      * calculate the EXIT time.  The real MutUserTime is calculated
297      * in stat_exit below.
298      */
299 #ifdef SMP
300     MutUserTime = CurrentUserTime;
301 #else
302     MutUserTime = CurrentUserTime - GC_tot_time - InitUserTime;
303     if (MutUserTime < 0) { MutUserTime = 0; }
304 #endif
305 }
306
307 void
308 stat_endExit(void)
309 {
310     getTimes();
311 #ifdef SMP
312     ExitUserTime = CurrentUserTime - MutUserTime;
313 #else
314     ExitUserTime = CurrentUserTime - MutUserTime - GC_tot_time - InitUserTime;
315 #endif
316     ExitElapsedTime = CurrentElapsedTime - MutElapsedStamp;
317     if (ExitUserTime < 0) {
318         ExitUserTime = 0;
319     }
320     if (ExitElapsedTime < 0) {
321         ExitElapsedTime = 0;
322     }
323 }
324
325 /* -----------------------------------------------------------------------------
326    Called at the beginning of each GC
327    -------------------------------------------------------------------------- */
328
329 static nat rub_bell = 0;
330
331 /*  initialise global variables needed during GC
332  *
333  *  * GC_start_time is read in mut_user_time_during_GC(), which in turn is 
334  *    needed if either PROFILING or DEBUGing is enabled
335  */
336 void
337 stat_startGC(void)
338 {
339     nat bell = RtsFlags.GcFlags.ringBell;
340
341     if (bell) {
342         if (bell > 1) {
343             fprintf(stderr, " GC ");
344             rub_bell = 1;
345         } else {
346             fprintf(stderr, "\007");
347         }
348     }
349
350 #if defined(PROFILING) || defined(DEBUG)
351     getTimes();
352     GC_start_time = CurrentUserTime;  /* needed in mut_user_time_during_GC() */
353 #endif
354
355     if (RtsFlags.GcFlags.giveStats != NO_GC_STATS) {
356 #if !defined(PROFILING) && !defined(DEBUG)
357         getTimes();
358         GC_start_time = CurrentUserTime;
359 #endif
360         GCe_start_time = CurrentElapsedTime;
361         if (RtsFlags.GcFlags.giveStats) {
362             GC_start_faults = pageFaults();
363         }
364     }
365 }
366
367 /* -----------------------------------------------------------------------------
368    Called at the end of each GC
369    -------------------------------------------------------------------------- */
370
371 void
372 stat_endGC(lnat alloc, lnat collect, lnat live, lnat copied, lnat gen)
373 {
374     FILE *sf = RtsFlags.GcFlags.statsFile;
375
376     if (RtsFlags.GcFlags.giveStats != NO_GC_STATS) {
377         TICK_TYPE time, etime, gc_time, gc_etime;
378         
379         getTimes();
380         time     = CurrentUserTime;
381         etime    = CurrentElapsedTime;
382         gc_time  = time - GC_start_time;
383         gc_etime = etime - GCe_start_time;
384         
385         if (RtsFlags.GcFlags.giveStats == VERBOSE_GC_STATS && sf != NULL) {
386             nat faults = pageFaults();
387             
388             fprintf(sf, "%9ld %9ld %9ld",
389                     alloc*sizeof(W_), collect*sizeof(W_), live*sizeof(W_));
390             fprintf(sf, " %5.2f %5.2f %7.2f %7.2f %4ld %4ld  (Gen: %2ld)\n", 
391                     TICK_TO_DBL(gc_time),
392                     TICK_TO_DBL(gc_etime),
393                     TICK_TO_DBL(time),
394                     TICK_TO_DBL(etime - ElapsedTimeStart),
395                     faults - GC_start_faults,
396                     GC_start_faults - GC_end_faults,
397                     gen);
398
399             GC_end_faults = faults;
400             fflush(sf);
401         }
402
403         GC_coll_times[gen] += gc_time;
404
405         GC_tot_copied += (ullong) copied;
406         GC_tot_alloc  += (ullong) alloc;
407         GC_tot_time   += gc_time;
408         GCe_tot_time  += gc_etime;
409         
410 #ifdef SMP
411         {
412             nat i;
413             pthread_t me = pthread_self();
414
415             for (i = 0; i < RtsFlags.ParFlags.nNodes; i++) {
416                 if (me == task_ids[i].id) {
417                     task_ids[i].gc_time += gc_time;
418                     task_ids[i].gc_etime += gc_etime;
419                     break;
420                 }
421             }
422         }
423 #endif
424
425         if (gen == RtsFlags.GcFlags.generations-1) { /* major GC? */
426             if (live > MaxResidency) {
427                 MaxResidency = live;
428             }
429             ResidencySamples++;
430             AvgResidency += live;
431         }
432     }
433
434     if (rub_bell) {
435         fprintf(stderr, "\b\b\b  \b\b\b");
436         rub_bell = 0;
437     }
438 }
439
440 /* -----------------------------------------------------------------------------
441    stat_workerStop
442
443    Called under SMP when a worker thread finishes.  We drop the timing
444    stats for this thread into the task_ids struct for that thread.
445    -------------------------------------------------------------------------- */
446
447 #ifdef SMP
448 void
449 stat_workerStop(void)
450 {
451     nat i;
452     pthread_t me = pthread_self();
453
454     for (i = 0; i < RtsFlags.ParFlags.nNodes; i++) {
455         if (task_ids[i].id == me) {
456             task_ids[i].mut_time = usertime() - task_ids[i].gc_time;
457             task_ids[i].mut_etime = elapsedtime()
458                 - GCe_tot_time
459                 - task_ids[i].elapsedtimestart;
460             if (task_ids[i].mut_time < 0.0)  { task_ids[i].mut_time = 0.0;  }
461             if (task_ids[i].mut_etime < 0.0) { task_ids[i].mut_etime = 0.0; }
462         }
463     }
464 }
465 #endif
466
467 /* -----------------------------------------------------------------------------
468    Called at the end of execution
469
470    NOTE: number of allocations is not entirely accurate: it doesn't
471    take into account the few bytes at the end of the heap that
472    were left unused when the heap-check failed.
473    -------------------------------------------------------------------------- */
474
475 void
476 stat_exit(int alloc)
477 {
478     FILE *sf = RtsFlags.GcFlags.statsFile;
479     
480     if (RtsFlags.GcFlags.giveStats != NO_GC_STATS) {
481
482         char temp[BIG_STRING_LEN];
483         TICK_TYPE time;
484         TICK_TYPE etime;
485         nat g, total_collections = 0;
486
487         getTimes();
488         time = CurrentUserTime;
489         etime = CurrentElapsedTime - ElapsedTimeStart;
490
491         GC_tot_alloc += alloc;
492
493         /* avoid divide by zero if time is measured as 0.00 seconds -- SDM */
494         if (time  == 0.0)  time = 1;
495         if (etime == 0.0) etime = 1;
496         
497         /* Count total garbage collections */
498         for (g = 0; g < RtsFlags.GcFlags.generations; g++)
499             total_collections += generations[g].collections;
500
501         /* For SMP, we have to get the user time from each thread
502          * and try to work out the total time.
503          */
504 #ifdef SMP
505         {   nat i;
506             MutUserTime = 0.0;
507             for (i = 0; i < RtsFlags.ParFlags.nNodes; i++) {
508                 MutUserTime += task_ids[i].mut_time;
509             }
510         }
511         time = MutUserTime + GC_tot_time + InitUserTime + ExitUserTime;
512         if (MutUserTime < 0) { MutUserTime = 0; }
513 #endif
514
515         if (RtsFlags.GcFlags.giveStats >= VERBOSE_GC_STATS && sf != NULL) {
516             fprintf(sf, "%9ld %9.9s %9.9s", (lnat)alloc*sizeof(W_), "", "");
517             fprintf(sf, " %5.2f %5.2f\n\n", 0.0, 0.0);
518         }
519
520         if (RtsFlags.GcFlags.giveStats >= SUMMARY_GC_STATS && sf != NULL) {
521             ullong_format_string(GC_tot_alloc*sizeof(W_), 
522                                  temp, rtsTrue/*commas*/);
523             fprintf(sf, "%11s bytes allocated in the heap\n", temp);
524
525             ullong_format_string(GC_tot_copied*sizeof(W_), 
526                                  temp, rtsTrue/*commas*/);
527             fprintf(sf, "%11s bytes copied during GC\n", temp);
528
529             if ( ResidencySamples > 0 ) {
530                 ullong_format_string(MaxResidency*sizeof(W_), 
531                                      temp, rtsTrue/*commas*/);
532                 fprintf(sf, "%11s bytes maximum residency (%ld sample(s))\n",
533                         temp, ResidencySamples);
534             }
535             fprintf(sf,"\n");
536
537             /* Print garbage collections in each gen */
538             for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
539                 fprintf(sf, "%11d collections in generation %d (%6.2fs)\n", 
540                         generations[g].collections, g, 
541                         TICK_TO_DBL(GC_coll_times[g]));
542             }
543
544             fprintf(sf,"\n%11ld Mb total memory in use\n\n", 
545                     mblocks_allocated * MBLOCK_SIZE / (1024 * 1024));
546
547 #ifdef SMP
548             {
549                 nat i;
550                 for (i = 0; i < RtsFlags.ParFlags.nNodes; i++) {
551                     fprintf(sf, "  Task %2d:  MUT time: %6.2fs  (%6.2fs elapsed)\n"
552                             "            GC  time: %6.2fs  (%6.2fs elapsed)\n\n", 
553                             i, 
554                             TICK_TO_DBL(task_ids[i].mut_time),
555                             TICK_TO_DBL(task_ids[i].mut_etime),
556                             TICK_TO_DBL(task_ids[i].gc_time),
557                             TICK_TO_DBL(task_ids[i].gc_etime));
558                 }
559             }
560 #endif
561
562             fprintf(sf, "  INIT  time  %6.2fs  (%6.2fs elapsed)\n",
563                     TICK_TO_DBL(InitUserTime), TICK_TO_DBL(InitElapsedTime));
564             fprintf(sf, "  MUT   time  %6.2fs  (%6.2fs elapsed)\n",
565                     TICK_TO_DBL(MutUserTime), TICK_TO_DBL(MutElapsedTime));
566             fprintf(sf, "  GC    time  %6.2fs  (%6.2fs elapsed)\n",
567                     TICK_TO_DBL(GC_tot_time), TICK_TO_DBL(GCe_tot_time));
568             fprintf(sf, "  EXIT  time  %6.2fs  (%6.2fs elapsed)\n",
569                     TICK_TO_DBL(ExitUserTime), TICK_TO_DBL(ExitElapsedTime));
570             fprintf(sf, "  Total time  %6.2fs  (%6.2fs elapsed)\n\n",
571                     TICK_TO_DBL(time), TICK_TO_DBL(etime));
572             fprintf(sf, "  %%GC time     %5.1f%%  (%.1f%% elapsed)\n\n",
573                     TICK_TO_DBL(GC_tot_time)*100/time, 
574                     TICK_TO_DBL(GCe_tot_time)*100/etime);
575
576             if (time - GC_tot_time == 0)
577                 ullong_format_string(0, temp, rtsTrue/*commas*/);
578             else
579                 ullong_format_string(
580                     (ullong)((GC_tot_alloc*sizeof(W_))/
581                              TICK_TO_DBL(time - GC_tot_time)),
582                     temp, rtsTrue/*commas*/);
583             
584             fprintf(sf, "  Alloc rate    %s bytes per MUT second\n\n", temp);
585         
586             fprintf(sf, "  Productivity %5.1f%% of total user, %.1f%% of total elapsed\n\n",
587                     TICK_TO_DBL(time - GC_tot_time - InitUserTime) * 100 
588                     / TICK_TO_DBL(time), 
589                     TICK_TO_DBL(time - GC_tot_time - InitUserTime) * 100 
590                     / TICK_TO_DBL(etime));
591         }
592
593         if (RtsFlags.GcFlags.giveStats == ONELINE_GC_STATS && sf != NULL) {
594           /* print the long long separately to avoid bugginess on mingwin (2001-07-02, mingw-0.5) */
595           fprintf(sf, "<<ghc: %llu bytes, ", GC_tot_alloc*sizeof(W_));
596           fprintf(sf, "%d GCs, %ld/%ld avg/max bytes residency (%ld samples), %luM in use, %.2f INIT (%.2f elapsed), %.2f MUT (%.2f elapsed), %.2f GC (%.2f elapsed) :ghc>>\n",
597                     total_collections,
598                     AvgResidency*sizeof(W_)/ResidencySamples, 
599                     MaxResidency*sizeof(W_), 
600                     ResidencySamples,
601                     (unsigned long)(mblocks_allocated * MBLOCK_SIZE / (1024L * 1024L)),
602                     TICK_TO_DBL(InitUserTime), TICK_TO_DBL(InitElapsedTime),
603                     TICK_TO_DBL(MutUserTime), TICK_TO_DBL(MutElapsedTime),
604                     TICK_TO_DBL(GC_tot_time), TICK_TO_DBL(GCe_tot_time));
605         }
606
607         fflush(sf);
608         fclose(sf);
609     }
610 }
611
612 /* -----------------------------------------------------------------------------
613    stat_describe_gens
614
615    Produce some detailed info on the state of the generational GC.
616    -------------------------------------------------------------------------- */
617 void
618 stat_describe_gens(void)
619 {
620   nat g, s, mut, mut_once, lge, live;
621   StgMutClosure *m;
622   bdescr *bd;
623   step *step;
624
625   fprintf(stderr, "     Gen    Steps      Max   Mutable  Mut-Once  Step   Blocks     Live    Large\n                    Blocks  Closures  Closures                         Objects\n");
626
627   for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
628     for (m = generations[g].mut_list, mut = 0; m != END_MUT_LIST; 
629          m = m->mut_link) 
630       mut++;
631     for (m = generations[g].mut_once_list, mut_once = 0; m != END_MUT_LIST; 
632          m = m->mut_link) 
633       mut_once++;
634     fprintf(stderr, "%8d %8d %8d %9d %9d", g, generations[g].n_steps,
635             generations[g].max_blocks, mut, mut_once);
636
637     for (s = 0; s < generations[g].n_steps; s++) {
638       step = &generations[g].steps[s];
639       for (bd = step->large_objects, lge = 0; bd; bd = bd->link)
640         lge++;
641       live = 0;
642       if (RtsFlags.GcFlags.generations == 1) {
643         bd = step->to_space;
644       } else {
645         bd = step->blocks;
646       }
647       for (; bd; bd = bd->link) {
648         live += (bd->free - bd->start) * sizeof(W_);
649       }
650       if (s != 0) {
651         fprintf(stderr,"%46s","");
652       }
653       fprintf(stderr,"%6d %8d %8d %8d\n", s, step->n_blocks,
654               live, lge);
655     }
656   }
657   fprintf(stderr,"\n");
658 }
659
660 /* -----------------------------------------------------------------------------
661    Stats available via a programmatic interface, so eg. GHCi can time
662    each compilation and expression evaluation.
663    -------------------------------------------------------------------------- */
664
665 extern HsInt getAllocations( void ) 
666 { return (HsInt)(total_allocated * sizeof(W_)); }