3 #include "multicoretaskprofile.h"
5 INLINE 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
11 } // for(i = 0; i < NUMCORESACTIVE; ++i)
17 taskInfoOverflow = false;
18 #ifdef PROFILE_INTERRUPT
19 interruptInfoIndex = 0;
20 interruptInfoOverflow = false;
21 #endif // PROFILE_INTERRUPT
24 inline void setTaskExitIndex(int index) {
25 taskInfoArray[taskInfoIndex]->exitIndex = index;
28 inline void addNewObjInfo(void * nobj) {
29 if(taskInfoArray[taskInfoIndex]->newObjs == NULL) {
30 taskInfoArray[taskInfoIndex]->newObjs = createQueue();
32 addNewItem(taskInfoArray[taskInfoIndex]->newObjs, nobj);
35 inline void profileTaskStart(char * taskname) {
36 if(!taskInfoOverflow) {
37 TaskInfo* taskInfo = RUNMALLOC(sizeof(struct task_info));
38 taskInfoArray[taskInfoIndex] = taskInfo;
39 taskInfo->taskName = taskname;
40 taskInfo->startTime = BAMBOO_GET_EXE_TIME();
41 taskInfo->endTime = -1;
42 taskInfo->exitIndex = -1;
43 taskInfo->newObjs = NULL;
47 inline void profileTaskEnd() {
48 if(!taskInfoOverflow) {
49 taskInfoArray[taskInfoIndex]->endTime = BAMBOO_GET_EXE_TIME();
51 if(taskInfoIndex == TASKINFOLENGTH) {
52 taskInfoOverflow = true;
57 #ifdef PROFILE_INTERRUPT
58 INLINE void profileInterruptStart_I(void) {
59 if(!interruptInfoOverflow) {
60 InterruptInfo* intInfo = RUNMALLOC_I(sizeof(struct interrupt_info));
61 interruptInfoArray[interruptInfoIndex] = intInfo;
62 intInfo->startTime = BAMBOO_GET_EXE_TIME();
63 intInfo->endTime = -1;
67 INLINE void profileInterruptEnd_I(void) {
68 if(!interruptInfoOverflow) {
69 interruptInfoArray[interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
71 if(interruptInfoIndex == INTERRUPTINFOLENGTH) {
72 interruptInfoOverflow = true;
76 #endif // PROFILE_INTERRUPT
78 // output the profiling data
79 void outputProfileData() {
82 unsigned long long totaltasktime = 0;
83 unsigned long long preprocessingtime = 0;
84 unsigned long long objqueuecheckingtime = 0;
85 unsigned long long postprocessingtime = 0;
86 unsigned long long other = 0;
87 unsigned long long averagetasktime = 0;
90 printf("Task Name, Start Time, End Time, Duration, Exit Index(, NewObj Name, Num)+\n");
91 // output task related info
92 for(i = 0; i < taskInfoIndex; i++) {
93 TaskInfo* tmpTInfo = taskInfoArray[i];
94 unsigned long long duration = tmpTInfo->endTime - tmpTInfo->startTime;
95 printf("%s, %lld, %lld, %lld, %lld", tmpTInfo->taskName,
96 tmpTInfo->startTime, tmpTInfo->endTime, duration, tmpTInfo->exitIndex);
97 // summarize new obj info
98 if(tmpTInfo->newObjs != NULL) {
99 struct RuntimeHash * nobjtbl = allocateRuntimeHash(5);
100 struct RuntimeIterator * iter = NULL;
101 while(0 == isEmpty(tmpTInfo->newObjs)) {
102 char * objtype = (char *)(getItem(tmpTInfo->newObjs));
103 if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) {
105 RuntimeHashget(nobjtbl, (int)objtype, &num);
106 RuntimeHashremovekey(nobjtbl, (int)objtype);
108 RuntimeHashadd(nobjtbl, (int)objtype, num);
110 RuntimeHashadd(nobjtbl, (int)objtype, 1);
114 // output all new obj info
115 iter = RuntimeHashcreateiterator(nobjtbl);
116 while(RunhasNext(iter)) {
117 char * objtype = (char *)Runkey(iter);
118 int num = Runnext(iter);
119 printf(", %s, %d", objtype, num);
123 if(strcmp(tmpTInfo->taskName, "tpd checking") == 0) {
124 preprocessingtime += duration;
125 } else if(strcmp(tmpTInfo->taskName, "post task execution") == 0) {
126 postprocessingtime += duration;
127 } else if(strcmp(tmpTInfo->taskName, "objqueue checking") == 0) {
128 objqueuecheckingtime += duration;
130 totaltasktime += duration;
131 averagetasktime += duration;
136 if(taskInfoOverflow) {
137 printf("Caution: task info overflow!\n");
140 other = totalexetime-totaltasktime-preprocessingtime-postprocessingtime;
141 averagetasktime /= tasknum;
143 printf("\nTotal time: %lld\n", totalexetime);
144 printf("Total task execution time: %lld (%d%%)\n", totaltasktime,
145 (int)(((double)totaltasktime/(double)totalexetime)*100));
146 printf("Total objqueue checking time: %lld (%d%%)\n",
147 objqueuecheckingtime,
148 (int)(((double)objqueuecheckingtime/(double)totalexetime)*100));
149 printf("Total pre-processing time: %lld (%d%%)\n", preprocessingtime,
150 (int)(((double)preprocessingtime/(double)totalexetime)*100));
151 printf("Total post-processing time: %lld (%d%%)\n", postprocessingtime,
152 (int)(((double)postprocessingtime/(double)totalexetime)*100));
153 printf("Other time: %lld (%d%%)\n", other,
154 (int)(((double)other/(double)totalexetime)*100));
156 printf("\nAverage task execution time: %lld\n", averagetasktime);
162 BAMBOO_PRINT(0xdddd);
163 // output task related info
164 for(i= 0; i < taskInfoIndex; i++) {
165 TaskInfo* tmpTInfo = taskInfoArray[i];
166 char* tmpName = tmpTInfo->taskName;
167 int nameLen = strlen(tmpName);
168 BAMBOO_PRINT(0xddda);
169 for(j = 0; j < nameLen; j++) {
170 BAMBOO_PRINT_REG(tmpName[j]);
172 BAMBOO_PRINT(0xdddb);
173 BAMBOO_PRINT_REG(tmpTInfo->startTime);
174 BAMBOO_PRINT_REG(tmpTInfo->endTime);
175 BAMBOO_PRINT_REG(tmpTInfo->exitIndex);
176 if(tmpTInfo->newObjs != NULL) {
177 struct RuntimeHash * nobjtbl = allocateRuntimeHash(5);
178 struct RuntimeIterator * iter = NULL;
179 while(0 == isEmpty(tmpTInfo->newObjs)) {
180 char * objtype = (char *)(getItem(tmpTInfo->newObjs));
181 if(RuntimeHashcontainskey(nobjtbl, (int)(objtype))) {
183 RuntimeHashget(nobjtbl, (int)objtype, &num);
184 RuntimeHashremovekey(nobjtbl, (int)objtype);
186 RuntimeHashadd(nobjtbl, (int)objtype, num);
188 RuntimeHashadd(nobjtbl, (int)objtype, 1);
192 // ouput all new obj info
193 iter = RuntimeHashcreateiterator(nobjtbl);
194 while(RunhasNext(iter)) {
195 char * objtype = (char *)Runkey(iter);
196 int num = Runnext(iter);
197 int nameLen = strlen(objtype);
198 BAMBOO_PRINT(0xddda);
199 for(j = 0; j < nameLen; j++) {
200 BAMBOO_PRINT_REG(objtype[j]);
202 BAMBOO_PRINT(0xdddb);
203 BAMBOO_PRINT_REG(num);
206 BAMBOO_PRINT(0xdddc);
209 if(taskInfoOverflow) {
210 BAMBOO_PRINT(0xefee);
213 #ifdef PROFILE_INTERRUPT
214 // output interrupt related info
215 for(i = 0; i < interruptInfoIndex; i++) {
216 InterruptInfo* tmpIInfo = interruptInfoArray[i];
217 BAMBOO_PRINT(0xddde);
218 BAMBOO_PRINT_REG(tmpIInfo->startTime);
219 BAMBOO_PRINT_REG(tmpIInfo->endTime);
220 BAMBOO_PRINT(0xdddf);
223 if(interruptInfoOverflow) {
224 BAMBOO_PRINT(0xefef);
226 #endif // PROFILE_INTERRUPT
228 BAMBOO_PRINT(0xeeee);