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
51 #ifdef cpe_count_poolalloc
52 #define CP_EVENTID_COUNT_POOLALLOC 0x15
55 #ifdef cpe_count_poolreuse
56 #define CP_EVENTID_COUNT_POOLREUSE 0x16
59 #ifdef cpe_workschedgrab
60 #define CP_EVENTID_WORKSCHEDGRAB 0x20
63 #ifdef cpe_taskdispatch
64 #define CP_EVENTID_TASKDISPATCH 0x30
67 #ifdef cpe_taskexecute
68 #define CP_EVENTID_TASKEXECUTE 0x31
72 #define CP_EVENTID_TASKRETIRE 0x32
75 #ifdef cpe_taskstallvar
76 #define CP_EVENTID_TASKSTALLVAR 0x40
79 #ifdef cpe_taskstallmem
80 #define CP_EVENTID_TASKSTALLMEM 0x41
84 // Note: application-specific events (assigned
85 // during code gen) start at 0x200
89 extern __thread int cp_threadnum;
90 extern __thread struct coreprofmonitor* cp_monitor;
91 extern struct coreprofmonitor* cp_monitorList;
94 struct coreprofmonitor {
95 struct coreprofmonitor* next;
97 // index for next unused word in the following array;
98 // individual events may use a variable number of
99 // words to store information
101 unsigned int data[CP_MAXEVENTWORDS];
105 #ifndef COREPROF_CHECKOVERFLOW
106 #define CP_CHECKOVERFLOW ;
108 #define CP_CHECKOVERFLOW if \
109 ( cp_monitor->numWords >= CP_MAXEVENTWORDS ) \
110 { cp_reportOverflow(); }
114 #define CP_LOGEVENT( eventID, eventType ) { \
116 cp_monitor->data[cp_monitor->numWords] = \
117 ((eventID << CP_EVENT_BASESHIFT) | eventType); \
118 cp_monitor->numWords += 1; \
123 #define CP_LOGTIME CP_CHECKOVERFLOW; \
124 *((long long *)&cp_monitor->data[cp_monitor->numWords]) = rdtsc(); \
125 cp_monitor->numWords += 2;
129 #define CP_CREATE() cp_create();
130 #define CP_EXIT() cp_exit();
131 #define CP_DUMP() cp_dump();
136 void cp_reportOverflow();
139 static inline void* cp_calloc( int size ) {
140 #ifdef CP_EVENTID_RUNMALLOC
141 CP_LOGEVENT( CP_EVENTID_RUNMALLOC, CP_EVENTTYPE_BEGIN );
143 void* mem = calloc( 1, size );
144 #ifdef CP_EVENTID_RUNMALLOC
145 CP_LOGEVENT( CP_EVENTID_RUNMALLOC, CP_EVENTTYPE_END );
150 static inline void cp_free( void* ptr ) {
151 #ifdef CP_EVENTID_RUNFREE
152 CP_LOGEVENT( CP_EVENTID_RUNFREE, CP_EVENTTYPE_BEGIN );
155 #ifdef CP_EVENTID_RUNFREE
156 CP_LOGEVENT( CP_EVENTID_RUNFREE, CP_EVENTTYPE_END );