Comments about the let/app invariant
[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 #include "Rts.h"
11
12 #include "Profiling.h"
13 #include "Proftimer.h"
14 #include "Capability.h"
15
16 #ifdef PROFILING
17 static rtsBool do_prof_ticks = rtsFalse; // enable profiling ticks
18 #endif
19
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 #ifdef PROFILING
32 do_prof_ticks = rtsFalse;
33 #endif
34 }
35
36 void
37 startProfTimer( void )
38 {
39 #ifdef PROFILING
40 do_prof_ticks = rtsTrue;
41 #endif
42 }
43
44 void
45 stopHeapProfTimer( void )
46 {
47 do_heap_prof_ticks = rtsFalse;
48 }
49
50 void
51 startHeapProfTimer( void )
52 {
53 if (RtsFlags.ProfFlags.doHeapProfile &&
54 RtsFlags.ProfFlags.heapProfileIntervalTicks > 0) {
55 do_heap_prof_ticks = rtsTrue;
56 }
57 }
58
59 void
60 initProfTimer( void )
61 {
62 performHeapProfile = rtsFalse;
63
64 ticks_to_heap_profile = RtsFlags.ProfFlags.heapProfileIntervalTicks;
65
66 startHeapProfTimer();
67 }
68
69 nat total_ticks = 0;
70
71 void
72 handleProfTick(void)
73 {
74 #ifdef PROFILING
75 total_ticks++;
76 if (do_prof_ticks) {
77 nat n;
78 for (n=0; n < n_capabilities; n++) {
79 capabilities[n]->r.rCCCS->time_ticks++;
80 }
81 }
82 #endif
83
84 if (do_heap_prof_ticks) {
85 ticks_to_heap_profile--;
86 if (ticks_to_heap_profile <= 0) {
87 ticks_to_heap_profile = RtsFlags.ProfFlags.heapProfileIntervalTicks;
88 performHeapProfile = rtsTrue;
89 }
90 }
91 }