[project @ 1996-01-11 14:06:51 by partain]
[ghc-hetmet.git] / ghc / runtime / profiling / Timer.lc
1 Only have cost centres etc if @PROFILING@ defined
2
3 \begin{code}
4 #include "rtsdefs.h"
5
6 #if defined (PROFILING) || defined(PAR)
7 \end{code}
8
9 %************************************************************************
10 %*                                                                      *
11 \subsection[timer-interrupts]{Processing of Profiling Timer Signals}
12 %*                                                                      *
13 %************************************************************************
14
15 Problem: If we set @HpLim = Hp@ in handler neither can be in registers!
16          Rather add test for flag to Hp check macros.
17
18 \begin{code}
19
20 I_ time_profiling = 0;                 /* Flag to indicate timer/serial profiling */
21
22 I_ interval_expired = 0;               /* Flag tested by HP_CHK routines */
23 I_ current_interval = 1;               /* Current interval number -- stored in AGE */
24 I_ interval_ticks = DEFAULT_INTERVAL;  /* No of ticks in an interval */
25
26 I_ previous_ticks = 0;                 /* ticks in previous intervals */
27 I_ current_ticks = 0;                  /* ticks in current interval */
28
29 void
30 set_profile_timer(I_ ms)
31 {
32     if (initialize_virtual_timer(ms)) {
33         fflush(stdout);
34         fprintf(stderr, "Can't initialize virtual timer.\n");
35         EXIT(EXIT_FAILURE);
36     }
37 }
38
39 void
40 handle_tick_serial(STG_NO_ARGS)
41 {
42     CC_TICK(CCC);
43
44     /* fprintf(stderr,"tick for %s\n", CCC->label); */
45 #if defined(PROFILING) && defined(DEBUG)
46     /* Why is this here?  --JSM  Debugging --WDP */
47     if (CCC == STATIC_CC_REF(CC_OVERHEAD))
48         abort();
49 #endif
50
51     if (++current_ticks >= interval_ticks && CCC != STATIC_CC_REF(CC_GC)) {
52 #if defined(PROFILING)
53         interval_expired = 1;   /* stop to process interval */
54 #else
55         report_cc_profiling(0 /*partial*/);
56         restart_time_profiler();
57 #endif
58       }
59     return;
60 }
61
62 void
63 handle_tick_noserial(STG_NO_ARGS)
64 {
65     CC_TICK(CCC);
66     ++current_ticks;
67     return;
68 }
69
70 void
71 stop_time_profiler()
72 {                               /* Stops time profile */
73     if (time_profiling) {
74         set_profile_timer(0);
75     }
76 }
77
78 void
79 restart_time_profiler()
80 {                               /* Restarts time profile */
81 #if defined(PROFILING)
82     if (interval_expired)
83 #endif
84     {
85         current_interval++;
86         previous_ticks += current_ticks;
87         current_ticks = 0;
88         interval_expired = 0;
89     }
90 }
91
92 void
93 start_time_profiler()
94 {                               /* Starts time profile */
95     if (time_profiling) {
96 #ifdef PAR
97         set_profile_timer(RTSflags.CcFlags.msecsPerTick);
98 #else
99         set_profile_timer(TICK_MILLISECS);
100 #endif
101     }
102 }
103 \end{code}
104
105 \begin{code}
106 #endif /* PROFILING || PAR */
107 \end{code}