Polish multicore code
[IRC.git] / Robust / src / Runtime / bamboo / multicoregcprofile.c
1 #ifdef MULTICORE_GC
2 #ifdef GC_PROFILE
3 #include "multicoregcprofile.h"
4 #include "runtime_arch.h"
5 #include "structdefs.h"
6 #include "mem.h"
7
8 extern int corenum;
9
10 INLINE void initmulticoregcprofiledata() {
11   if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
12     // startup core to initialize corestatus[]
13     gc_infoIndex = 0;
14     gc_infoOverflow = false;
15     gc_num_livespace = 0;
16     gc_num_freespace = 0;
17   }
18   gc_num_obj = 0;
19   gc_num_liveobj = 0;
20   gc_num_forwardobj = 0;
21   gc_num_profiles = NUMCORESACTIVE - 1;
22 }
23
24 INLINE void gc_profileInit() {
25   gc_num_livespace = 0;
26   gc_num_freespace = 0;
27   gc_num_lobj = 0;
28   gc_num_lobjspace = 0;
29   gc_num_liveobj = 0;
30   gc_num_forwardobj = 0;
31   gc_num_profiles = NUMCORESACTIVE - 1;
32 }
33
34 INLINE void gc_profileStart(void) {
35   if(!gc_infoOverflow) {
36     GCInfo* gcInfo = RUNMALLOC(sizeof(struct gc_info));
37     gc_infoArray[gc_infoIndex] = gcInfo;
38     gcInfo->index = 1;
39     gcInfo->time[0] = BAMBOO_GET_EXE_TIME();
40   }
41 }
42
43 INLINE void gc_profileItem(void) {
44   if(!gc_infoOverflow) {
45     GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
46     gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
47   }
48 }
49
50 INLINE void gc_profileEnd(void) {
51   if(!gc_infoOverflow) {
52     GCInfo* gcInfo = gc_infoArray[gc_infoIndex];
53     gcInfo->time[gcInfo->index++] = BAMBOO_GET_EXE_TIME();
54     gcInfo->time[gcInfo->index++] = gc_num_livespace;
55     gcInfo->time[gcInfo->index++] = gc_num_freespace;
56     gcInfo->time[gcInfo->index++] = gc_num_lobj;
57     gcInfo->time[gcInfo->index++] = gc_num_lobjspace;
58     gcInfo->time[gcInfo->index++] = gc_num_obj;
59     gcInfo->time[gcInfo->index++] = gc_num_liveobj;
60     gcInfo->time[gcInfo->index++] = gc_num_forwardobj;
61     gc_infoIndex++;
62     if(gc_infoIndex == GCINFOLENGTH) {
63       gc_infoOverflow = true;
64     }
65   }
66 }
67
68 // output the profiling data
69 void gc_outputProfileData() {
70   int i = 0;
71   int j = 0;
72   unsigned long long totalgc = 0;
73
74 #ifndef BAMBOO_MEMPROF
75   BAMBOO_PRINT(0xdddd);
76 #endif
77   // output task related info
78   for(i= 0; i < gc_infoIndex; i++) {
79     GCInfo * gcInfo = gc_infoArray[i];
80 #ifdef BAMBOO_MEMPROF
81     unsigned long long tmp=gcInfo->time[gcInfo->index-8]-gcInfo->time[0]; //0;
82 #else
83     unsigned long long tmp = 0;
84     BAMBOO_PRINT(0xddda);
85     for(j = 0; j < gcInfo->index - 7; j++) {
86       BAMBOO_PRINT(gcInfo->time[j]);
87       BAMBOO_PRINT(gcInfo->time[j]-tmp);
88       BAMBOO_PRINT(0xdddb);
89       tmp = gcInfo->time[j];
90     }
91     tmp = (tmp-gcInfo->time[0]);
92     BAMBOO_PRINT_REG(tmp);
93     BAMBOO_PRINT(0xdddc);
94     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 7]);
95     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 6]);
96     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 5]);
97     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 4]);
98     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 3]);
99     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 2]);
100     BAMBOO_PRINT(gcInfo->time[gcInfo->index - 1]);
101     BAMBOO_PRINT(0xddde);
102 #endif
103     totalgc += tmp;
104   }
105 #ifndef BAMBOO_MEMPROF
106   BAMBOO_PRINT(0xdddf);
107 #endif
108   BAMBOO_PRINT_REG(totalgc);
109
110   if(gc_infoOverflow) {
111     BAMBOO_PRINT(0xefee);
112   }
113
114 #ifndef BAMBOO_MEMPROF
115   BAMBOO_PRINT(0xeeee);
116 #endif
117 }
118 #endif  // GC_PROFILE
119 #endif // MULTICORE_GC