1 %************************************************************************
3 \subsection[AgeProfile.lh]{Age Profiling Definitions for Heap and Lifetime Profiling}
5 %************************************************************************
7 Multi-slurp protection:
13 Definitions relating to the life field in fixed header:
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)
21 We have age header in closure if @LIFE_PROFILE@ or
22 @HEAP_PROF_WITH_AGE@ defined.
26 #if defined(HEAP_PROF_WITH_AGE) || defined(LIFE_PROFILE) || defined(UPDATES_ENTERED_COUNT)
28 #define AGE_HDR_SIZE 1
29 #define AGE_HDR(closure) (((P_)(closure))[AGE_HDR_POSN])
30 #define SET_STATIC_AGE_HDR() ,0
32 #if defined (HEAP_PROF_WITH_AGE) || defined(UPDATES_ENTERED_COUNT)
33 #define SET_AGE_HDR(closure) AGE_HDR(closure) = 0
36 /* SET_AGE_HDR(closure) defined below if LIFE_PROFILE required */
39 #else /* ! LIFE_PROFILE && ! HEAP_PROF_WITH_AGE && ! UPDATES_ENTERED */
41 #define AGE_HDR_SIZE 0
42 #define SET_AGE_HDR(closure)
43 #define SET_STATIC_AGE_HDR()
45 #endif /* ! LIFE_PROFILE && ! HEAP_PROF_WITH_AGE */
49 %************************************************************************
51 \subsubsection[lifetime-profiling]{Declarations For Lifetime Profiling}
53 %************************************************************************
55 The SM is responsible for:
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).
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.
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
71 Calling \tr{life_profile_closure} for every closure collected during a
75 The RTS is responsible for:
78 Allocating extra age word in closures.
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
85 Calling \tr{life_profile_init} and \tr{life_profile_finish} routines.
87 Calling \tr{update_profile_closure} for every closure updated.
92 #if defined(LIFE_PROFILE)
94 extern W_ closures_alloced;
95 #define SET_AGE_HDR(closure) do { AGE_HDR(closure) = (W_)CurrentTime; \
96 closures_alloced++; HpLim++; } while(0)
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.
103 /* start of execution -- looks for -l flag */
104 extern I_ life_profile_init PROTO((StgChar *rts_argv[], StgChar *prog_argv[]));
106 /* end of execution -- produce report if -l flag */
107 extern void life_profile_finish PROTO((I_ alloc, StgChar *prog_argv[]));
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) */
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 */
117 /* START of gc profile */
118 extern void life_profile_setup(STG_NO_ARGS);
120 /* END of gc profile -- returns next alloc interval */
121 /* passed alloc since last (inc age words) and req size */
123 extern I_ life_profile_done PROTO((I_ alloc, I_ reqsize));
125 /* LIFE PROFILE function called for every closure collected */
126 /* records info if part_interval == 0, indicating a profile reqd */
128 extern void life_profile_closure PROTO((P_ closure, I_ size));
130 /* UPDATE PROFILE function called for every closure updated */
131 /* records info if the user requested a lifetime profiling */
133 extern void update_profile_closure PROTO((P_ closure));
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)
140 #else /* ! LIFE_PROFILE */
142 #define LIFE_PROFILE_CLOSURE(closure,size)
143 #define UPDATE_PROFILE_CLOSURE(closure)
145 #endif /* ! LIFE_PROFILE */
148 End multi-slurp protection:
150 #endif /* LifeProfile_H */