[project @ 2004-02-12 02:04:59 by mthomas]
[ghc-hetmet.git] / ghc / rts / Proftimer.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Proftimer.c,v 1.12 2003/02/22 04:51:52 sof Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Profiling interval timer
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #if defined (PROFILING)
11
12 #include "PosixSource.h"
13
14 #include <stdio.h>
15
16 #include "Rts.h"
17 #include "Profiling.h"
18 #include "Timer.h"
19 #include "Proftimer.h"
20 #include "RtsFlags.h"
21
22 static rtsBool do_prof_ticks = rtsFalse;       // enable profiling ticks
23 static rtsBool do_heap_prof_ticks = rtsFalse;  // enable heap profiling ticks
24
25 // Number of ticks until next heap census
26 static int ticks_to_heap_profile;
27
28 // Time for a heap profile on the next context switch
29 rtsBool performHeapProfile;
30
31 void
32 stopProfTimer( void )
33 {
34     do_prof_ticks = rtsFalse;
35 }
36
37 void
38 startProfTimer( void )
39 {
40     do_prof_ticks = rtsTrue;
41 }
42
43 void
44 stopHeapProfTimer( void )
45 {
46     do_heap_prof_ticks = rtsFalse;
47 }
48
49 void
50 startHeapProfTimer( void )
51 {
52     if (RtsFlags.ProfFlags.doHeapProfile && 
53         RtsFlags.ProfFlags.profileIntervalTicks > 0) {
54         do_heap_prof_ticks = rtsTrue;
55     }
56 }
57
58 void
59 initProfTimer( void )
60 {
61     performHeapProfile = rtsFalse;
62
63     RtsFlags.ProfFlags.profileIntervalTicks = 
64         RtsFlags.ProfFlags.profileInterval / TICK_MILLISECS;
65
66     ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
67
68     startHeapProfTimer();
69 }
70
71
72 void
73 handleProfTick(void)
74 {
75     if (do_prof_ticks) {
76         CCCS->time_ticks++;
77     }
78
79     if (do_heap_prof_ticks) {
80         ticks_to_heap_profile--;
81         if (ticks_to_heap_profile <= 0) {
82             ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
83             performHeapProfile = rtsTrue;
84         }
85     }
86 }
87
88 #endif /* PROFILING */