merge
[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
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 nat total_ticks = 0;
69
70 void
71 handleProfTick(void)
72 {
73 #ifdef PROFILING
74 total_ticks++;
75 if (do_prof_ticks) {
76 CCCS->time_ticks++;
77 }
78 #endif
79
80 if (do_heap_prof_ticks) {
81 ticks_to_heap_profile--;
82 if (ticks_to_heap_profile <= 0) {
83 ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
84 performHeapProfile = rtsTrue;
85 }
86 }
87 }