6 // Core Prof turned off
8 #define CP_LOGEVENT( eventID, eventType ) ;
20 #ifndef CP_MAXEVENTWORDS
21 #define CP_MAXEVENTWORDS (1024*128)
25 // MASK should be enough bits to mask
26 // the values of the following event types
27 // and BASESHIFT is for shifting IDs
29 #define CP_EVENTTYPE_BEGIN 0x1
30 #define CP_EVENTTYPE_END 0x2
31 #define CP_EVENTTYPE_ONEOFF 0x3
33 #define CP_EVENT_MASK 3
34 #define CP_EVENT_BASESHIFT 8
37 // Event IDs, only those enabled explicitly as a build option
38 // will be defined and included in the compilation
40 #define CP_EVENTID_MAIN 0x04
44 #define CP_EVENTID_RUNMALLOC 0x10
48 #define CP_EVENTID_RUNFREE 0x11
52 #define CP_EVENTID_POOLALLOC 0x14
55 #ifdef cpe_count_poolalloc
56 #define CP_EVENTID_COUNT_POOLALLOC 0x15
59 #ifdef cpe_count_poolreuse
60 #define CP_EVENTID_COUNT_POOLREUSE 0x16
63 #ifdef cpe_workschedgrab
64 #define CP_EVENTID_WORKSCHEDGRAB 0x20
67 #ifdef cpe_workschedsubmit
68 #define CP_EVENTID_WORKSCHEDSUBMIT 0x21
71 #ifdef cpe_taskdispatch
72 #define CP_EVENTID_TASKDISPATCH 0x30
75 #ifdef cpe_preparememq
76 #define CP_EVENTID_PREPAREMEMQ 0x31
79 #ifdef cpe_taskexecute
80 #define CP_EVENTID_TASKEXECUTE 0x40
84 #define CP_EVENTID_TASKRETIRE 0x50
87 #ifdef cpe_taskstallvar
88 #define CP_EVENTID_TASKSTALLVAR 0x60
91 #ifdef cpe_taskstallmem
92 #define CP_EVENTID_TASKSTALLMEM 0x61
95 #ifdef cpe_rcr_traverse
96 #define CP_EVENTID_RCR_TRAVERSE 0x80
100 // debug events don't require a preprocessor
101 // guard because normally they are not in the code
102 // base--its helpful to define them in case you
103 // want to debug events that aren't worth keeping
105 #define CP_EVENTID_DEBUG_A 0x180
106 #define CP_EVENTID_DEBUG_B 0x181
107 #define CP_EVENTID_DEBUG_C 0x182
108 #define CP_EVENTID_DEBUG_D 0x183
109 #define CP_EVENTID_DEBUG_E 0x184
110 #define CP_EVENTID_DEBUG_F 0x185
111 #define CP_EVENTID_DEBUG_G 0x186
112 #define CP_EVENTID_DEBUG_H 0x187
113 #define CP_EVENTID_DEBUG_I 0x188
114 #define CP_EVENTID_DEBUG_J 0x189
117 // Note: application-specific events (assigned
118 // during code gen) start at 0x200
122 extern __thread int cp_threadnum;
123 extern __thread struct coreprofmonitor* cp_monitor;
124 extern struct coreprofmonitor* cp_monitorList;
127 struct coreprofmonitor {
128 struct coreprofmonitor* next;
130 // index for next unused word in the following array;
131 // individual events may use a variable number of
132 // words to store information
134 unsigned int data[CP_MAXEVENTWORDS];
138 #ifndef COREPROF_CHECKOVERFLOW
139 #define CP_CHECKOVERFLOW ;
141 #define CP_CHECKOVERFLOW if \
142 ( cp_monitor->numWords >= CP_MAXEVENTWORDS ) \
143 { cp_reportOverflow(); }
147 #define CP_LOGEVENT( eventID, eventType ) { \
149 cp_monitor->data[cp_monitor->numWords] = \
150 ((eventID << CP_EVENT_BASESHIFT) | eventType); \
151 cp_monitor->numWords += 1; \
156 #define CP_LOGTIME CP_CHECKOVERFLOW; \
157 *((long long *)&cp_monitor->data[cp_monitor->numWords]) = rdtsc(); \
158 cp_monitor->numWords += 2;
162 #define CP_CREATE() cp_create();
163 #define CP_EXIT() cp_exit();
164 #define CP_DUMP() cp_dump();
169 void cp_reportOverflow();
172 static inline void* cp_calloc( int size ) {
173 #ifdef CP_EVENTID_RUNMALLOC
174 CP_LOGEVENT( CP_EVENTID_RUNMALLOC, CP_EVENTTYPE_BEGIN );
176 void* mem = calloc( 1, size );
177 #ifdef CP_EVENTID_RUNMALLOC
178 CP_LOGEVENT( CP_EVENTID_RUNMALLOC, CP_EVENTTYPE_END );
183 static inline void cp_free( void* ptr ) {
184 #ifdef CP_EVENTID_RUNFREE
185 CP_LOGEVENT( CP_EVENTID_RUNFREE, CP_EVENTTYPE_BEGIN );
188 #ifdef CP_EVENTID_RUNFREE
189 CP_LOGEVENT( CP_EVENTID_RUNFREE, CP_EVENTTYPE_END );