[project @ 2001-11-22 14:25:11 by simonmar]
[ghc-hetmet.git] / ghc / rts / LdvProfile.h
1 /* -----------------------------------------------------------------------------
2  * $Id: LdvProfile.h,v 1.1 2001/11/22 14:25:12 simonmar Exp $
3  *
4  * (c) The GHC Team, 2001
5  * Author: Sungwoo Park
6  *
7  * Lag/Drag/Void profiling.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 #ifndef LDVPROFILE_H
12 #define LDVPROFILE_H
13
14 #ifdef PROFILING
15
16 #include "ProfHeap.h"
17
18 void  LDV_recordDead_FILL_SLOP_DYNAMIC( StgClosure *p );
19
20 // Precesses a closure 'c' being destroyed whose size is 'size'.
21 // Make sure that LDV_recordDead() is not invoked on 'inherently used' closures
22 // such as TSO; they should not be involved in computing dragNew or voidNew.
23 // 
24 // Note: ldvTime is 0 if LDV profiling is turned off.
25 //       ldvTime is > 0 if LDV profiling is turned on.
26 //       size does not include StgProfHeader.
27 //
28 // Even though ldvTime is checked in both LdvCensusForDead() and 
29 // LdvCensusKillAll(), we still need to make sure that ldvTime is > 0 because 
30 // LDV_recordDead() may be called from elsewhere in the runtime system. E.g., 
31 // when a thunk is replaced by an indirection object.
32
33 static inline void
34 LDV_recordDead( StgClosure *c, nat size )
35 {
36     if (ldvTime > 0 && closureSatisfiesConstraints(c)) {
37         nat t;
38         size -= sizeofW(StgProfHeader);
39         if ((LDVW((c)) & LDV_STATE_MASK) == LDV_STATE_CREATE) {
40             t = (LDVW((c)) & LDV_CREATE_MASK) >> LDV_SHIFT;
41             if (t < ldvTime) {
42                 gi[t].voidNew += (int)size;
43                 gi[ldvTime].voidNew -= (int)size;
44             }
45         } else {
46             t = LDVW((c)) & LDV_LAST_MASK;
47             if (t + 1 < ldvTime) {
48                 gi[t + 1].dragNew += size;
49                 gi[ldvTime].dragNew -= size;
50             }
51         }
52     }
53 }
54
55 extern void initLdvProfiling ( void );
56 extern void endLdvProfiling  ( void );
57 extern void LdvCensus        ( void );
58 extern void LdvCensusForDead ( nat );
59 extern void LdvCensusKillAll ( void );
60
61 #endif /* PROFILING */
62
63 #endif /* LDVPROFILE_H */