changes
[IRC.git] / Robust / src / Runtime / bamboo / multicoretaskprofile.h
1 #ifndef BAMBOO_MULTICORE_TASK_PROFILE_H
2 #define BAMBOO_MULTICORE_TASK_PROFILE_H
3 #include "multicore.h"
4
5 #ifdef TASK
6 // data structures for profile mode
7 #ifdef PROFILE
8 #define TASKINFOLENGTH 3000
9
10 typedef struct task_info {
11   char* taskName;
12   unsigned long long startTime;
13   unsigned long long endTime;
14   unsigned long long exitIndex;
15   struct Queue * newObjs;
16 } TaskInfo_t;
17
18 typedef struct task_profile {
19   TaskInfo_t * taskInfoArray[TASKINFOLENGTH];
20   int taskInfoIndex;
21   bool taskInfoOverflow;
22 } TaskProfile_t;
23
24 extern TaskProfile_t taskProfileInfo;
25 #ifdef PROFILE_INTERRUPT
26 #define INTERRUPTINFOLENGTH 50
27 typedef struct interrupt_info {
28   unsigned long long startTime;
29   unsigned long long endTime;
30 } InterruptInfo_t;
31
32 typedef struct interrupt_profile {
33   InterruptInfo_t * interruptInfoArray[INTERRUPTINFOLENGTH];
34   int interruptInfoIndex;
35   bool interruptInfoOverflow;
36 } InterruptProfile_t;
37
38 extern InterruptProfile_t interruptProfileInfo;
39 #endif
40
41 void outputProfileData();
42 void inittaskprofiledata();
43
44 INLINE static void setTaskExitIndex(int index) {
45   taskProfileInfo.taskInfoArray[taskProfileInfo.taskInfoIndex]->exitIndex = index;
46 }
47
48 INLINE static void addNewObjInfo(void * nobj) {
49   if(taskProfileInfo.taskInfoArray[taskProfileInfo.taskInfoIndex]->newObjs==NULL) {
50     taskProfileInfo.taskInfoArray[taskProfileInfo.taskInfoIndex]->newObjs=createQueue();
51   }
52   addNewItem(taskProfileInfo.taskInfoArray[taskProfileInfo.taskInfoIndex]->newObjs, nobj);
53 }
54
55 INLINE static void profileTaskStart(char * taskname) {
56   if(!taskProfileInfo.taskInfoOverflow) {
57     TaskInfo* taskInfo=RUNMALLOC(sizeof(struct task_info));
58     taskProfileInfo.taskInfoArray[taskProfileInfo.taskInfoIndex]=taskInfo;
59     taskInfo->taskName=taskname;
60     taskInfo->startTime=BAMBOO_GET_EXE_TIME();
61     taskInfo->endTime=-1;
62     taskInfo->exitIndex=-1;
63     taskInfo->newObjs=NULL;
64   }
65 }
66
67 INLINE staitc void profileTaskEnd() {
68   if(!taskProfileInfo.taskInfoOverflow) {
69     taskProfileInfo.taskInfoArray[taskProfileInfo.taskInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
70     taskProfileInfo.taskInfoIndex++;
71     if(taskProfileInfo.taskInfoIndex == TASKINFOLENGTH) {
72       taskProfileInfo.taskInfoOverflow=true;
73     }
74   }
75 }
76
77 #ifdef PROFILE_INTERRUPT
78 INLINE static void profileInterruptStart_I(void) {
79   if(!interruptProfileInfo.interruptInfoOverflow) {
80     InterruptInfo* intInfo=RUNMALLOC_I(sizeof(struct interrupt_info));
81     interruptProfileInfo.interruptInfoArray[interruptProfileInfo.interruptInfoIndex]=intInfo;
82     intInfo->startTime=BAMBOO_GET_EXE_TIME();
83     intInfo->endTime=-1;
84   }
85 }
86
87 INLINE static void profileInterruptEnd_I(void) {
88   if(!interruptProfileInfo.interruptInfoOverflow) {
89     interruptProfileInfo.interruptInfoArray[interruptProfileInfo.interruptInfoIndex]->endTime=BAMBOO_GET_EXE_TIME();
90     interruptProfileInfo.interruptInfoIndex++;
91     if(interruptProfileInfo.interruptInfoIndex==INTERRUPTINFOLENGTH) {
92       interruptProfileInfo.interruptInfoOverflow=true;
93     }
94   }
95 }
96 #endif // PROFILE_INTERRUPT
97
98 #define INIT_TASKPROFILE_DATA() inittaskprofiledata()
99 #define PROFILE_TASK_START(s) profileTaskStart(s)
100 #define PROFILE_TASK_END() profileTaskEnd()
101 #ifdef PROFILE_INTERRUPT
102 #define PROFILE_INTERRUPT_START() profileInterruptStart_I()
103 #define PROFILE_INTERRUPT_END() profileInterruptEnd_I()
104 #else
105 #define PROFILE_INTERRUPT_START() 
106 #define PROFILE_INTERRUPT_END() 
107 #endif
108 #else // PROFILE
109 #define INIT_TASKPROFILE_DATA() 
110 #define PROFILE_TASK_START(s)
111 #define PROFILE_TASK_END()
112 #define PROFILE_INTERRUPT_START() 
113 #define PROFILE_INTERRUPT_END() 
114 #endif // PROFILE
115 #else // TASK
116 #define INIT_TASKPROFILE_DATA() 
117 #define PROFILE_TASK_START(s)
118 #define PROFILE_TASK_END()
119 #define PROFILE_INTERRUPT_START() 
120 #define PROFILE_INTERRUPT_END()
121 #endif // TASK
122 #endif // BAMBOO_MULTICORE_TASK_PROFILE_H