RTS tidyup sweep, first phase
[ghc-hetmet.git] / rts / Proftimer.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-1999
4  *
5  * Profiling interval timer
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #include "PosixSource.h"
10 #include "Rts.h"
11
12 #include "Profiling.h"
13 #include "Proftimer.h"
14
15 #ifdef PROFILING
16 static rtsBool do_prof_ticks = rtsFalse;       // enable profiling ticks
17 #endif
18
19 static rtsBool do_heap_prof_ticks = rtsFalse;  // enable heap profiling ticks
20
21 // Number of ticks until next heap census
22 static int ticks_to_heap_profile;
23
24 // Time for a heap profile on the next context switch
25 rtsBool performHeapProfile;
26
27 #ifdef PROFILING
28
29 void
30 stopProfTimer( void )
31 {
32     do_prof_ticks = rtsFalse;
33 }
34
35 void
36 startProfTimer( void )
37 {
38     do_prof_ticks = rtsTrue;
39 }
40
41 #endif
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     ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
64
65     startHeapProfTimer();
66 }
67
68
69 void
70 handleProfTick(void)
71 {
72 #ifdef PROFILING
73     if (do_prof_ticks) {
74         CCCS->time_ticks++;
75     }
76 #endif
77
78     if (do_heap_prof_ticks) {
79         ticks_to_heap_profile--;
80         if (ticks_to_heap_profile <= 0) {
81             ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
82             performHeapProfile = rtsTrue;
83         }
84     }
85 }