[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / includes / AgeProfile.lh
1 %************************************************************************
2 %*                                                                      *
3 \subsection[AgeProfile.lh]{Age Profiling Definitions for Heap and Lifetime Profiling}
4 %*                                                                      *
5 %************************************************************************
6
7 Multi-slurp protection:
8 \begin{code}
9 #ifndef LifeProfile_H
10 #define LifeProfile_H
11 \end{code}
12
13 Definitions relating to the life field in fixed header:
14
15 \begin{code}
16 #define AGE_FIXED_HDR                   (AGE_HDR_SIZE)
17 #define AGE_HDR_POSN                    AFTER_PROF_HDR
18 #define AFTER_AGE_HDR                   (AGE_FIXED_HDR+AGE_HDR_POSN)
19 \end{code}
20
21 We have age header in closure if @LIFE_PROFILE@ or
22 @HEAP_PROF_WITH_AGE@ defined.
23
24 \begin{code}
25
26 #if defined(HEAP_PROF_WITH_AGE) || defined(LIFE_PROFILE) || defined(UPDATES_ENTERED_COUNT)
27
28 #define AGE_HDR_SIZE            1
29 #define AGE_HDR(closure)        (((P_)(closure))[AGE_HDR_POSN])
30 #define SET_STATIC_AGE_HDR()    ,0
31
32 #if defined (HEAP_PROF_WITH_AGE) || defined(UPDATES_ENTERED_COUNT)
33 #define SET_AGE_HDR(closure)    AGE_HDR(closure) = 0
34 #endif
35
36 /* SET_AGE_HDR(closure) defined below if LIFE_PROFILE required */
37
38
39 #else  /* ! LIFE_PROFILE && ! HEAP_PROF_WITH_AGE && ! UPDATES_ENTERED */
40
41 #define AGE_HDR_SIZE            0
42 #define SET_AGE_HDR(closure)
43 #define SET_STATIC_AGE_HDR()
44
45 #endif /* ! LIFE_PROFILE && ! HEAP_PROF_WITH_AGE */
46
47 \end{code}
48
49 %************************************************************************
50 %*                                                                      *
51 \subsubsection[lifetime-profiling]{Declarations For Lifetime Profiling}
52 %*                                                                      *
53 %************************************************************************
54
55 The SM is responsible for:
56 \begin{itemize}
57 \item
58 Ensuring that the \tr{HpLim} increment will be ok by ALWAYS setting \tr{HpLim}
59 lower than the end of the heap (halving the free space suffices).
60 \item
61 If the user has requested a lifetime profile the storage manager must
62 arrange for a garbage collection to occur after \tr{LifeInterval}
63 words allocated (excluding age words which will be fudged with the
64 \tr{HpLim} increment). Additional collections are possible with
65 \tr{part_interval} being returned to indicate what is left.
66 \item
67 Calling \tr{life_profile_setup} and \tr{life_profile_done} during each
68 garbage collection. These can be avoided if the user has not requested
69 a lifetime profile.
70 \item
71 Calling \tr{life_profile_closure} for every closure collected during a
72 garbage collection.
73 \end{itemize}
74
75 The RTS is responsible for:
76 \begin{itemize}
77 \item
78 Allocating extra age word in closures.
79 \item
80 Initialising closure age to \tr{CurrentTime} using
81 \tr{SET_AGE_HDR(closure)}. This increments the heap limit pointer to
82 avoid collecting too soon as a result of distortion from the extra
83 word in closures.
84 \item
85 Calling \tr{life_profile_init} and \tr{life_profile_finish} routines.
86 \item
87 Calling \tr{update_profile_closure} for every closure updated.
88 \end{itemize}
89
90
91 \begin{code}
92 #if defined(LIFE_PROFILE)
93
94 extern W_ closures_alloced;
95 #define SET_AGE_HDR(closure)    do { AGE_HDR(closure) = (W_)CurrentTime; \
96                                 closures_alloced++; HpLim++; } while(0)
97
98 /* When we allocate a closure we increment HpLim so that age word will
99    not be included in the allocation before the next profiling interupt.
100 */
101
102
103 /* start of execution -- looks for -l flag */
104 extern I_ life_profile_init PROTO((StgChar *rts_argv[], StgChar *prog_argv[]));
105
106 /* end of execution -- produce report if -l flag */
107 extern void life_profile_finish PROTO((I_ alloc, StgChar *prog_argv[]));
108
109 extern I_  do_life_prof;        /* Are we liftime profiling ? */
110 extern I_  CurrentTime;         /* Current time (LifeIntervals) */
111 extern I_  LifeInterval;        /* Lifetime resolution  (in words allocated) */
112
113 #define DEFAULT_LIFE_INTERVAL  250     /* 1k -- report 10k */
114 #define INTERVALS              100000  /* Intervals recoded */
115 #define GROUPED                10      /* No of intervals grouped oin results */
116
117 /* START of gc profile */
118 extern void life_profile_setup(STG_NO_ARGS);
119
120 /* END of gc profile -- returns next alloc interval */
121 /* passed alloc since last (inc age words) and req size */
122
123 extern I_ life_profile_done  PROTO((I_ alloc, I_ reqsize));
124
125 /* LIFE PROFILE function called for every closure collected */
126 /* records info if part_interval == 0, indicating a profile reqd */
127
128 extern void life_profile_closure   PROTO((P_ closure, I_ size));
129
130 /* UPDATE PROFILE function called for every closure updated */
131 /* records info if the user requested a lifetime profiling */
132
133 extern void update_profile_closure PROTO((P_ closure));
134
135 #define LIFE_PROFILE_CLOSURE(closure,size) \
136         STGCALL2(void,(void *, P_, I_),life_profile_closure,closure,size)
137 #define UPDATE_PROFILE_CLOSURE(closure) \
138         STGCALL1(void,(void *, P_),update_profile_closure,closure)      
139
140 #else /* ! LIFE_PROFILE */
141
142 #define LIFE_PROFILE_CLOSURE(closure,size)
143 #define UPDATE_PROFILE_CLOSURE(closure)
144
145 #endif /* ! LIFE_PROFILE */
146 \end{code}
147
148 End multi-slurp protection:
149 \begin{code}
150 #endif /* LifeProfile_H */
151 \end{code}