fix profile code
[IRC.git] / Robust / src / Runtime / bamboo / multicoregcprofile.h
1 #ifndef BAMBOO_MULTICORE_GC_PROFILE_H
2 #define BAMBOO_MULTICORE_GC_PROFILE_H
3 #if defined(MULTICORE_GC)||defined(PMC_GC)
4 #include "multicore.h"
5 #include "runtime_arch.h"
6 #include "structdefs.h"
7
8 #ifdef GC_PROFILE
9 #define GCINFOLENGTH 100
10
11 #ifdef GC_CACHE_ADAPT
12 #define GC_PROFILE_NUM_FIELD 15
13 #else
14 #define GC_PROFILE_NUM_FIELD 14
15 #endif // GC_CACHE_ADAPT
16
17 typedef struct gc_info {
18   unsigned long long time[GC_PROFILE_NUM_FIELD];
19   unsigned int index;
20 } GCInfo;
21
22 GCInfo * gc_infoArray[GCINFOLENGTH];
23 unsigned int gc_infoIndex;
24 bool gc_infoOverflow;
25 unsigned long long gc_num_livespace;
26 unsigned long long gc_num_freespace;
27 unsigned long long gc_num_lobjspace;
28 unsigned int gc_num_lobj;
29
30 unsigned int gc_num_liveobj;
31 unsigned int gc_num_obj;
32 unsigned int gc_num_forwardobj;
33 unsigned int gc_num_profiles;
34
35 #ifdef MGC_SPEC
36 volatile bool gc_profile_flag;
37 #endif
38
39 void initmulticoregcprofiledata(void);
40 void gc_outputProfileData();
41 void gc_outputProfileDataReadable();
42
43 INLINE static void gc_profileInit() {
44   gc_num_livespace = 0;
45   gc_num_freespace = 0;
46   gc_num_lobj = 0;
47   gc_num_lobjspace = 0;
48   gc_num_liveobj = 0;
49   gc_num_forwardobj = 0;
50   gc_num_profiles = NUMCORESACTIVE - 1;
51 }
52
53 INLINE static void gc_profileStart(void) {
54   if(!gc_infoOverflow) {
55     GCInfo* gcInfo = RUNMALLOC(sizeof(struct gc_info));
56     gc_infoArray[gc_infoIndex] = gcInfo;
57     gcInfo->index = 1;
58     gcInfo->time[0] = BAMBOO_GET_EXE_TIME();
59   }
60 }
61
62 INLINE static void gc_profileItem(void) {
63   if(!gc_infoOverflow) {
64     GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
65     gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
66   }
67 }
68
69 INLINE static void gc_profileEnd(void) {
70   if(!gc_infoOverflow) {
71     GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
72     gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
73     gcInfo->time[gcInfo->index++] = gc_num_livespace;
74     gcInfo->time[gcInfo->index++] = gc_num_freespace;
75     gcInfo->time[gcInfo->index++] = gc_num_lobj;
76     gcInfo->time[gcInfo->index++] = gc_num_lobjspace;
77     gcInfo->time[gcInfo->index++] = gc_num_obj;
78     gcInfo->time[gcInfo->index++] = gc_num_liveobj;
79     gcInfo->time[gcInfo->index++] = gc_num_forwardobj;
80     gc_infoIndex++;
81     if(gc_infoIndex == GCINFOLENGTH) {
82       gc_infoOverflow = true;
83     }
84   }
85 }
86
87 #define INIT_MULTICORE_GCPROFILE_DATA() initmulticoregcprofiledata()
88 #define GC_OUTPUT_PROFILE_DATA() gc_outputProfileData()
89 // send the num of obj/liveobj/forwardobj to the startupcore
90 #define GCPROFILE_INFO_2_MASTER() \
91   { \
92     if(STARTUPCORE != BAMBOO_NUM_OF_CORE) { \
93       send_msg_4(STARTUPCORE,GCPROFILES,gc_num_obj,gc_num_liveobj,gc_num_forwardobj); \
94     }\
95     gc_num_obj = 0; \
96   }
97
98 #ifdef MGC_SPEC
99 // record lobj info
100 #define GCPROFILE_RECORD_LOBJ() \
101   { \
102       gc_num_lobj++; \
103   }
104 // record lobj space info
105 #define GCPROFILE_RECORD_LOBJSPACE() \
106   { \
107     if(gc_profile_flag) { \
108       gc_num_lobjspace = sumsize; \
109     } \
110   }
111 // check the live/free space info
112 #define GCPROFILE_RECORD_SPACE() \
113   { \
114     if(gc_profile_flag) { \
115       gc_num_freespace = 0; \
116       block_t lowestblock=allocationinfo.lowestfreeblock; \
117       for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) { \
118         struct blockrecord * block=&allocationinfo.blocktable[searchblock]; \
119         if (block->status==BS_FREE) { \
120           gc_num_freespace+=block->freespace&~BAMBOO_CACHE_LINE_MASK; \
121         } \
122       } \
123       gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
124     } \
125   }
126 // record forward obj info
127 #define GCPROFILE_RECORD_FORWARD_OBJ() \
128   { \
129       gc_num_forwardobj++; \
130   }
131 // record live obj info
132 #define GCPROFILE_RECORD_LIVE_OBJ() \
133   { \
134       gc_num_liveobj++; \
135   }
136 #define GCPROFILE_START() \
137   { \
138     if(gc_profile_flag) { \
139       gc_profileStart(); \
140     } \
141   }
142 #define GCPROFILE_ITEM() \
143   { \
144     if(gc_profile_flag) { \
145       gc_profileItem(); \
146     } \
147   }
148 #define GCPROFILE_END() \
149   { \
150     if(gc_profile_flag) { \
151       gc_profileEnd(); \
152     } \
153   }
154 #else // MGC_SPEC
155 #define GCPROFILE_RECORD_LOBJ() (gc_num_lobj++)
156 #define GCPROFILE_RECORD_LOBJSPACE() (gc_num_lobjspace = sumsize)
157 #define GCPROFILE_RECORD_SPACE() \
158   { \
159     gc_num_livespace = 0; \
160     for(int tmpi = 0; tmpi < GCNUMBLOCK; tmpi++) { \
161       gc_num_livespace += bamboo_smemtbl[tmpi]; \
162     } \
163     gc_num_freespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_livespace; \
164   }
165 #define GCPROFILE_RECORD_FORWARD_OBJ() (gc_num_forwardobj++)
166 #define GCPROFILE_RECORD_LIVE_OBJ() (gc_num_liveobj++)
167 #define GCPROFILE_START() gc_profileStart()
168 #define GCPROFILE_ITEM() gc_profileItem()
169 #define GCPROFILE_END() gc_profileEnd()
170 #endif // MGC_SPEC
171
172 #define GCPROFILE_INIT() gc_profileInit()
173
174 #else // GC_PROFILE
175 #define INIT_MULTICORE_GCPROFILE_DATA()
176 #define GC_OUTPUT_PROFILE_DATA() 
177 #define GCPROFILE_INFO_2_MASTER() 
178 #define GCPROFILE_RECORD_LOBJ()
179 #define GCPROFILE_RECORD_LOBJSPACE()
180 #define GCPROFILE_RECORD_SPACE()
181 #define GCPROFILE_RECORD_FORWARD_OBJ() 
182 #define GCPROFILE_RECORD_LIVE_OBJ() 
183 #define GCPROFILE_START()
184 #define GCPROFILE_ITEM()
185 #define GCPROFILE_END()
186 #define GCPROFILE_INIT()
187 #endif // GC_PROFILE
188
189 #endif // MULTICORE_GC
190 #endif // BAMBOO_MULTICORE_GC_PROFILE_H