[project @ 2001-11-22 14:25:11 by simonmar]
[ghc-hetmet.git] / ghc / rts / Proftimer.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Proftimer.c,v 1.8 2001/11/22 14:25:12 simonmar Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Profiling interval timer
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #if defined (PROFILING)
11
12 #include "PosixSource.h"
13
14 #include "Rts.h"
15 #include "Profiling.h"
16 #include "Itimer.h"
17 #include "Proftimer.h"
18 #include "RtsFlags.h"
19
20 static rtsBool do_prof_ticks = rtsFalse;       // enable profiling ticks
21 static rtsBool do_heap_prof_ticks = rtsFalse;  // enable heap profiling ticks
22
23 // Number of ticks until next heap census
24 static int ticks_to_heap_profile;
25
26 // Time for a heap profile on the next context switch
27 rtsBool performHeapProfile;
28
29 void
30 stopProfTimer( void )
31 {
32     if (time_profiling) {
33         do_prof_ticks = rtsFalse;
34     }
35 }
36
37 void
38 startProfTimer( void )
39 {
40     if (time_profiling) {
41         do_prof_ticks = rtsTrue;
42     }
43 }
44
45 void
46 stopHeapProfTimer( void )
47 {
48     do_heap_prof_ticks = rtsFalse;
49 }
50
51 void
52 startHeapProfTimer( void )
53 {
54     if (RtsFlags.ProfFlags.doHeapProfile) {
55         do_heap_prof_ticks = rtsTrue;
56     }
57 }
58
59 void
60 initProfTimer( void )
61 {
62     performHeapProfile = rtsFalse;
63
64     RtsFlags.ProfFlags.profileIntervalTicks = 
65         RtsFlags.ProfFlags.profileInterval / TICK_MILLISECS;
66
67     ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
68
69     startHeapProfTimer();
70 }
71     
72
73 void
74 handleProfTick(void)
75 {
76     if (do_prof_ticks) {
77         CCS_TICK(CCCS);
78     }
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 }
88
89 #endif /* PROFILING */