1 #ifndef BAMBOO_MULTICORE_GC_PROFILE_H
2 #define BAMBOO_MULTICORE_GC_PROFILE_H
3 #if defined(MULTICORE_GC)||defined(PMC_GC)
5 #include "runtime_arch.h"
6 #include "structdefs.h"
9 #define GCINFOLENGTH 100
12 #define GC_PROFILE_NUM_FIELD 15
14 #define GC_PROFILE_NUM_FIELD 14
15 #endif // GC_CACHE_ADAPT
17 typedef struct gc_info {
18 unsigned long long time[GC_PROFILE_NUM_FIELD];
22 GCInfo * gc_infoArray[GCINFOLENGTH];
23 unsigned int gc_infoIndex;
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;
30 unsigned int gc_num_liveobj;
31 unsigned int gc_num_obj;
32 unsigned int gc_num_forwardobj;
33 unsigned int gc_num_profiles;
36 volatile bool gc_profile_flag;
39 void initmulticoregcprofiledata(void);
40 void gc_outputProfileData();
41 void gc_outputProfileDataReadable();
43 INLINE static void gc_profileInit() {
49 gc_num_forwardobj = 0;
50 gc_num_profiles = NUMCORESACTIVE - 1;
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;
58 gcInfo->time[0] = BAMBOO_GET_EXE_TIME();
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();
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;
81 if(gc_infoIndex == GCINFOLENGTH) {
82 gc_infoOverflow = true;
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() \
92 if(STARTUPCORE != BAMBOO_NUM_OF_CORE) { \
93 send_msg_4(STARTUPCORE,GCPROFILES,gc_num_obj,gc_num_liveobj,gc_num_forwardobj); \
100 #define GCPROFILE_RECORD_LOBJ() \
104 // record lobj space info
105 #define GCPROFILE_RECORD_LOBJSPACE() \
107 if(gc_profile_flag) { \
108 gc_num_lobjspace = sumsize; \
111 // check the live/free space info
112 #define GCPROFILE_RECORD_SPACE() \
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; \
123 gc_num_livespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_freespace; \
126 // record forward obj info
127 #define GCPROFILE_RECORD_FORWARD_OBJ() \
129 gc_num_forwardobj++; \
131 // record live obj info
132 #define GCPROFILE_RECORD_LIVE_OBJ() \
136 #define GCPROFILE_START() \
138 if(gc_profile_flag) { \
142 #define GCPROFILE_ITEM() \
144 if(gc_profile_flag) { \
148 #define GCPROFILE_END() \
150 if(gc_profile_flag) { \
155 #define GCPROFILE_RECORD_LOBJ() (gc_num_lobj++)
156 #define GCPROFILE_RECORD_LOBJSPACE() (gc_num_lobjspace = sumsize)
157 #define GCPROFILE_RECORD_SPACE() \
159 gc_num_livespace = 0; \
160 for(int tmpi = 0; tmpi < GCNUMBLOCK; tmpi++) { \
161 gc_num_livespace += bamboo_smemtbl[tmpi]; \
163 gc_num_freespace = (BAMBOO_SHARED_MEM_SIZE) - gc_num_livespace; \
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()
172 #define GCPROFILE_INIT() gc_profileInit()
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()
189 #endif // MULTICORE_GC
190 #endif // BAMBOO_MULTICORE_GC_PROFILE_H