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