Reorganisation of the source tree
[ghc.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 RtsFlags.ProfFlags.profileIntervalTicks =
61 RtsFlags.ProfFlags.profileInterval / TICK_MILLISECS;
62
63 ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
64
65 startHeapProfTimer();
66 }
67
68
69 void
70 handleProfTick(void)
71 {
72 if (do_prof_ticks) {
73 CCCS->time_ticks++;
74 }
75
76 if (do_heap_prof_ticks) {
77 ticks_to_heap_profile--;
78 if (ticks_to_heap_profile <= 0) {
79 ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
80 performHeapProfile = rtsTrue;
81 }
82 }
83 }
84
85 #endif /* PROFILING */