[project @ 2002-12-05 23:49:43 by mthomas]
[ghc-hetmet.git] / ghc / rts / Proftimer.c
1 /* -----------------------------------------------------------------------------
2  * $Id: Proftimer.c,v 1.10 2002/07/18 09:12:34 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 <stdio.h>
15
16 #include "Rts.h"
17 #include "Profiling.h"
18 #include "Itimer.h"
19 #include "Proftimer.h"
20 #include "RtsFlags.h"
21
22 static rtsBool do_prof_ticks = rtsFalse;       // enable profiling ticks
23 static rtsBool do_heap_prof_ticks = rtsFalse;  // enable heap profiling ticks
24
25 // Number of ticks until next heap census
26 static int ticks_to_heap_profile;
27
28 // Time for a heap profile on the next context switch
29 rtsBool performHeapProfile;
30
31 void
32 stopProfTimer( void )
33 {
34     do_prof_ticks = rtsFalse;
35 }
36
37 void
38 startProfTimer( void )
39 {
40     do_prof_ticks = rtsTrue;
41 }
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         do_heap_prof_ticks = rtsTrue;
54     }
55 }
56
57 void
58 initProfTimer( void )
59 {
60     performHeapProfile = rtsFalse;
61
62     RtsFlags.ProfFlags.profileIntervalTicks = 
63         RtsFlags.ProfFlags.profileInterval / TICK_MILLISECS;
64
65     ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
66
67     startHeapProfTimer();
68 }
69
70
71 void
72 handleProfTick(void)
73 {
74     if (do_prof_ticks) {
75         CCCS->time_ticks++;
76     }
77
78     if (do_heap_prof_ticks) {
79         ticks_to_heap_profile--;
80         if (ticks_to_heap_profile <= 0) {
81             ticks_to_heap_profile = RtsFlags.ProfFlags.profileIntervalTicks;
82             performHeapProfile = rtsTrue;
83         }
84     }
85 }
86
87 #endif /* PROFILING */