[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / runtime / profiling / Timer.lc
1 Only have cost centres etc if @USE_COST_CENTRES@ defined
2
3 \begin{code}
4 #include "rtsdefs.h"
5
6 #if defined (USE_COST_CENTRES) || defined(GUM)
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 #ifdef CONCURRENT
30 I_ tick_millisecs;                     /* milliseconds per timer tick */
31 #endif
32
33 void
34 set_profile_timer(ms)
35 I_ ms;
36 {
37     if (initialize_virtual_timer(ms)) {
38         fflush(stdout);
39         fprintf(stderr, "Can't initialize virtual timer.\n");
40         EXIT(EXIT_FAILURE);
41     }
42 }
43
44 void
45 handle_tick_serial(STG_NO_ARGS)
46 {
47     CC_TICK(CCC);
48
49     /* fprintf(stderr,"tick for %s\n", CCC->label); */
50 #if defined(USE_COST_CENTRES) && defined(DEBUG)
51     /* Why is this here?  --JSM  Debugging --WDP */
52     if (CCC == STATIC_CC_REF(CC_OVERHEAD))
53         abort();
54 #endif
55
56     if (++current_ticks >= interval_ticks && CCC != STATIC_CC_REF(CC_GC)) {
57 #if defined(USE_COST_CENTRES)
58         interval_expired = 1;   /* stop to process interval */
59 #else
60         report_cc_profiling(0 /*partial*/);
61         restart_time_profiler();
62 #endif
63       }
64     return;
65 }
66
67 void
68 handle_tick_noserial(STG_NO_ARGS)
69 {
70     CC_TICK(CCC);
71     return;
72 }
73
74 void
75 stop_time_profiler()
76 {                               /* Stops time profile */
77     if (time_profiling) {
78         set_profile_timer(0);
79     }
80 }
81
82 void
83 restart_time_profiler()
84 {                               /* Restarts time profile */
85 #if defined(USE_COST_CENTRES)
86     if (interval_expired)
87 #endif
88     {
89         current_interval++;
90         previous_ticks += current_ticks;
91         current_ticks = 0;
92         interval_expired = 0;
93     }
94 }
95
96 void
97 start_time_profiler()
98 {                               /* Starts time profile */
99     if (time_profiling) {
100 #ifdef CONCURRENT
101         set_profile_timer(tick_millisecs);
102 #else
103         set_profile_timer(TICK_MILLISECS);
104 #endif
105     }
106 }
107 \end{code}
108
109 \begin{code}
110 #endif /* USE_COST_CENTRES || GUM */
111 \end{code}