[project @ 1998-11-26 09:17:22 by sof]
[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 0
52     /* Experimental - don't tick if we're in the middle
53        of reporting a cc_profile. Untested.
54     */
55     if (interval_expired)
56        return;
57 #endif
58
59     if (++current_ticks >= interval_ticks && CCC != STATIC_CC_REF(CC_GC)) {
60 #if defined(PROFILING)
61         interval_expired = 1;   /* stop to process interval */
62 #else
63         report_cc_profiling(0 /*partial*/);
64         restart_time_profiler();
65 #endif
66       }
67     return;
68 }
69
70 void
71 handle_tick_noserial(STG_NO_ARGS)
72 {
73     CC_TICK(CCC);
74     ++current_ticks;
75     return;
76 }
77
78 void
79 stop_time_profiler()
80 {                               /* Stops time profile */
81     if (time_profiling) {
82         set_profile_timer(0);
83     }
84 }
85
86 void
87 restart_time_profiler()
88 {                               /* Restarts time profile */
89 #if defined(PROFILING)
90     if (interval_expired)
91 #endif
92     {
93         current_interval++;
94         previous_ticks += current_ticks;
95         current_ticks = 0;
96         interval_expired = 0;
97     }
98 }
99
100 void
101 start_time_profiler()
102 {                               /* Starts time profile */
103     if (time_profiling) {
104 #ifdef PAR
105         set_profile_timer(RTSflags.CcFlags.msecsPerTick);
106 #else
107         set_profile_timer(TICK_MILLISECS);
108 #endif
109     }
110 }
111 \end{code}
112
113 \begin{code}
114 #endif /* PROFILING || PAR */
115 \end{code}