Fix the +RTS -V0 option introduced recently; it didn't work at all, now it does.
[ghc.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
11 #include "Rts.h"
12 #include "Profiling.h"
13 #include "Timer.h"
14 #include "Proftimer.h"
15 #include "RtsFlags.h"
16
17 static rtsBool do_prof_ticks = rtsFalse; // enable profiling ticks
18 static rtsBool do_heap_prof_ticks = rtsFalse; // enable heap profiling ticks
19
20 // Number of ticks until next heap census
21 static int ticks_to_heap_profile;
22
23 // Time for a heap profile on the next context switch
24 rtsBool performHeapProfile;
25
26 void
27 stopProfTimer( void )
28 {
29 do_prof_ticks = rtsFalse;
30 }
31
32 void
33 startProfTimer( void )
34 {
35 do_prof_ticks = rtsTrue;
36 }
37
38 void
39 stopHeapProfTimer( void )
40 {
41 do_heap_prof_ticks = rtsFalse;
42 }
43
44 void
45 startHeapProfTimer( void )
46 {
47 if (RtsFlags.ProfFlags.doHeapProfile &&
48 RtsFlags.ProfFlags.profileIntervalTicks > 0) {
49 do_heap_prof_ticks = rtsTrue;
50 }
51 }
52
53 void
54 initProfTimer( void )
55 {
56 performHeapProfile = rtsFalse;
57
58 ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
59
60 startHeapProfTimer();
61 }
62
63
64 void
65 handleProfTick(void)
66 {
67 #ifdef PROFILING
68 if (do_prof_ticks) {
69 CCCS->time_ticks++;
70 }
71 #endif
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 }