[project @ 2001-12-12 14:31:42 by simonmar]
[ghc-hetmet.git] / ghc / rts / Proftimer.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Proftimer.c,v 1.9 2001/12/12 14:31:43 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     do_prof_ticks = rtsFalse;
33 }
34
35 void
36 startProfTimer( void )
37 {
38     do_prof_ticks = rtsTrue;
39 }
40
41 void
42 stopHeapProfTimer( void )
43 {
44     do_heap_prof_ticks = rtsFalse;
45 }
46
47 void
48 startHeapProfTimer( void )
49 {
50     if (RtsFlags.ProfFlags.doHeapProfile) {
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 */