Code clean
[IRC.git] / Robust / src / Runtime / bamboo / multicoretaskprofile.c
1 #ifdef PROFILE
2
3 #include "multicoretaskprofile.h"
4
5 void inittaskprofiledata() {
6   if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
7     // startup core to initialize corestatus[]
8     for(i = 0; i < NUMCORESACTIVE; ++i) {
9       // initialize the profile data arrays
10       profilestatus[i] = 1;
11     } // for(i = 0; i < NUMCORESACTIVE; ++i)
12   }
13
14   stall = false;
15   totalexetime = -1;
16   taskInfoIndex = 0;
17   taskInfoOverflow = false;
18 #ifdef PROFILE_INTERRUPT
19   interruptInfoIndex = 0;
20   interruptInfoOverflow = false;
21 #endif // PROFILE_INTERRUPT
22 }
23
24 // output the profiling data
25 void outputProfileData() {
26 #ifdef USEIO
27   int i;
28   unsigned long long totaltasktime = 0;
29   unsigned long long preprocessingtime = 0;
30   unsigned long long objqueuecheckingtime = 0;
31   unsigned long long postprocessingtime = 0;
32   unsigned long long other = 0;
33   unsigned long long averagetasktime = 0;
34   int tasknum = 0;
35
36   printf("Task Name, Start Time, End Time, Duration, Exit Index(, NewObj Name, Num)+\n");
37   // output task related info
38   for(i = 0; i < taskInfoIndex; i++) {
39     TaskInfo* tmpTInfo = taskInfoArray[i];
40     unsigned long long duration = tmpTInfo->endTime - tmpTInfo->startTime;
41     printf("%s, %lld, %lld, %lld, %lld", tmpTInfo->taskName, 
42         tmpTInfo->startTime, tmpTInfo->endTime, duration, tmpTInfo->exitIndex);
43     // summarize new obj info
44     if(tmpTInfo->newObjs != NULL) {
45       struct RuntimeHash * nobjtbl = allocateRuntimeHash(5);
46       struct RuntimeIterator * iter = NULL;
47       while(0 == isEmpty(tmpTInfo->newObjs)) {
48                 char * objtype = (char *)(getItem(tmpTInfo->newObjs));
49                 if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) {
50                   int num = 0;
51                   RuntimeHashget(nobjtbl, (int)objtype, &num);
52                   RuntimeHashremovekey(nobjtbl, (int)objtype);
53                   num++;
54                   RuntimeHashadd(nobjtbl, (int)objtype, num);
55                 } else {
56                   RuntimeHashadd(nobjtbl, (int)objtype, 1);
57                 }
58       }
59
60       // output all new obj info
61       iter = RuntimeHashcreateiterator(nobjtbl);
62       while(RunhasNext(iter)) {
63                 char * objtype = (char *)Runkey(iter);
64                 int num = Runnext(iter);
65                 printf(", %s, %d", objtype, num);
66       }
67     }
68     printf("\n");
69     if(strcmp(tmpTInfo->taskName, "tpd checking") == 0) {
70       preprocessingtime += duration;
71     } else if(strcmp(tmpTInfo->taskName, "post task execution") == 0) {
72       postprocessingtime += duration;
73     } else if(strcmp(tmpTInfo->taskName, "objqueue checking") == 0) {
74       objqueuecheckingtime += duration;
75     } else {
76       totaltasktime += duration;
77       averagetasktime += duration;
78       tasknum++;
79     }
80   }
81
82   if(taskInfoOverflow) {
83     printf("Caution: task info overflow!\n");
84   }
85
86   other = totalexetime-totaltasktime-preprocessingtime-postprocessingtime;
87   averagetasktime /= tasknum;
88
89   printf("\nTotal time: %lld\n", totalexetime);
90   printf("Total task execution time: %lld (%d%%)\n", totaltasktime,
91          (int)(((double)totaltasktime/(double)totalexetime)*100));
92   printf("Total objqueue checking time: %lld (%d%%)\n",
93          objqueuecheckingtime,
94          (int)(((double)objqueuecheckingtime/(double)totalexetime)*100));
95   printf("Total pre-processing time: %lld (%d%%)\n", preprocessingtime,
96          (int)(((double)preprocessingtime/(double)totalexetime)*100));
97   printf("Total post-processing time: %lld (%d%%)\n", postprocessingtime,
98          (int)(((double)postprocessingtime/(double)totalexetime)*100));
99   printf("Other time: %lld (%d%%)\n", other,
100          (int)(((double)other/(double)totalexetime)*100));
101
102   printf("\nAverage task execution time: %lld\n", averagetasktime);
103
104 #else
105   int i = 0;
106   int j = 0;
107
108   BAMBOO_PRINT(0xdddd);
109   // output task related info
110   for(i= 0; i < taskInfoIndex; i++) {
111     TaskInfo* tmpTInfo = taskInfoArray[i];
112     char* tmpName = tmpTInfo->taskName;
113     int nameLen = strlen(tmpName);
114     BAMBOO_PRINT(0xddda);
115     for(j = 0; j < nameLen; j++) {
116       BAMBOO_PRINT_REG(tmpName[j]);
117     }
118     BAMBOO_PRINT(0xdddb);
119     BAMBOO_PRINT_REG(tmpTInfo->startTime);
120     BAMBOO_PRINT_REG(tmpTInfo->endTime);
121     BAMBOO_PRINT_REG(tmpTInfo->exitIndex);
122     if(tmpTInfo->newObjs != NULL) {
123       struct RuntimeHash * nobjtbl = allocateRuntimeHash(5);
124       struct RuntimeIterator * iter = NULL;
125       while(0 == isEmpty(tmpTInfo->newObjs)) {
126                 char * objtype = (char *)(getItem(tmpTInfo->newObjs));
127                 if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) {
128                   int num = 0;
129                   RuntimeHashget(nobjtbl, (int)objtype, &num);
130                   RuntimeHashremovekey(nobjtbl, (int)objtype);
131                   num++;
132                   RuntimeHashadd(nobjtbl, (int)objtype, num);
133                 } else {
134                   RuntimeHashadd(nobjtbl, (int)objtype, 1);
135                 }
136       }
137
138       // ouput all new obj info
139       iter = RuntimeHashcreateiterator(nobjtbl);
140       while(RunhasNext(iter)) {
141                 char * objtype = (char *)Runkey(iter);
142                 int num = Runnext(iter);
143                 int nameLen = strlen(objtype);
144                 BAMBOO_PRINT(0xddda);
145                 for(j = 0; j < nameLen; j++) {
146                   BAMBOO_PRINT_REG(objtype[j]);
147                 }
148                 BAMBOO_PRINT(0xdddb);
149                 BAMBOO_PRINT_REG(num);
150           }
151     }
152     BAMBOO_PRINT(0xdddc);
153   }
154
155   if(taskInfoOverflow) {
156         BAMBOO_PRINT(0xefee);
157   }
158
159 #ifdef PROFILE_INTERRUPT
160   // output interrupt related info
161   for(i = 0; i < interruptInfoIndex; i++) {
162     InterruptInfo* tmpIInfo = interruptInfoArray[i];
163     BAMBOO_PRINT(0xddde);
164     BAMBOO_PRINT_REG(tmpIInfo->startTime);
165     BAMBOO_PRINT_REG(tmpIInfo->endTime);
166     BAMBOO_PRINT(0xdddf);
167   }
168
169   if(interruptInfoOverflow) {
170     BAMBOO_PRINT(0xefef);
171   }
172 #endif // PROFILE_INTERRUPT
173
174   BAMBOO_PRINT(0xeeee);
175 #endif
176 }
177
178 #endif // PROFILE