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_taskdispatch
68 #define CP_EVENTID_TASKDISPATCH 0x30
71 #ifdef cpe_preparememq
72 #define CP_EVENTID_PREPAREMEMQ 0x31
75 #ifdef cpe_taskexecute
76 #define CP_EVENTID_TASKEXECUTE 0x40
80 #define CP_EVENTID_TASKRETIRE 0x50
83 #ifdef cpe_taskstallvar
84 #define CP_EVENTID_TASKSTALLVAR 0x60
87 #ifdef cpe_taskstallmem
88 #define CP_EVENTID_TASKSTALLMEM 0x61
91 // debug events don't require a preprocessor
92 // guard because normally they are not in the code
93 // base--its helpful to define them in case you
94 // want to debug events that aren't worth keeping
96 #define CP_EVENTID_DEBUG_A 0x180
97 #define CP_EVENTID_DEBUG_B 0x181
98 #define CP_EVENTID_DEBUG_C 0x182
99 #define CP_EVENTID_DEBUG_D 0x183
100 #define CP_EVENTID_DEBUG_E 0x184
101 #define CP_EVENTID_DEBUG_F 0x185
102 #define CP_EVENTID_DEBUG_G 0x186
103 #define CP_EVENTID_DEBUG_H 0x187
104 #define CP_EVENTID_DEBUG_I 0x188
105 #define CP_EVENTID_DEBUG_J 0x189
108 // Note: application-specific events (assigned
109 // during code gen) start at 0x200
113 extern __thread int cp_threadnum;
114 extern __thread struct coreprofmonitor* cp_monitor;
115 extern struct coreprofmonitor* cp_monitorList;
118 struct coreprofmonitor {
119 struct coreprofmonitor* next;
121 // index for next unused word in the following array;
122 // individual events may use a variable number of
123 // words to store information
125 unsigned int data[CP_MAXEVENTWORDS];
129 #ifndef COREPROF_CHECKOVERFLOW
130 #define CP_CHECKOVERFLOW ;
132 #define CP_CHECKOVERFLOW if \
133 ( cp_monitor->numWords >= CP_MAXEVENTWORDS ) \
134 { cp_reportOverflow(); }
138 #define CP_LOGEVENT( eventID, eventType ) { \
140 cp_monitor->data[cp_monitor->numWords] = \
141 ((eventID << CP_EVENT_BASESHIFT) | eventType); \
142 cp_monitor->numWords += 1; \
147 #define CP_LOGTIME CP_CHECKOVERFLOW; \
148 *((long long *)&cp_monitor->data[cp_monitor->numWords]) = rdtsc(); \
149 cp_monitor->numWords += 2;
153 #define CP_CREATE() cp_create();
154 #define CP_EXIT() cp_exit();
155 #define CP_DUMP() cp_dump();
160 void cp_reportOverflow();
163 static inline void* cp_calloc( int size ) {
164 #ifdef CP_EVENTID_RUNMALLOC
165 CP_LOGEVENT( CP_EVENTID_RUNMALLOC, CP_EVENTTYPE_BEGIN );
167 void* mem = calloc( 1, size );
168 #ifdef CP_EVENTID_RUNMALLOC
169 CP_LOGEVENT( CP_EVENTID_RUNMALLOC, CP_EVENTTYPE_END );
174 static inline void cp_free( void* ptr ) {
175 #ifdef CP_EVENTID_RUNFREE
176 CP_LOGEVENT( CP_EVENTID_RUNFREE, CP_EVENTTYPE_BEGIN );
179 #ifdef CP_EVENTID_RUNFREE
180 CP_LOGEVENT( CP_EVENTID_RUNFREE, CP_EVENTTYPE_END );