11 __thread int cp_threadnum;
12 __thread struct coreprofmonitor* cp_monitor = NULL;
13 struct coreprofmonitor* cp_monitorList = NULL;
14 static volatile int cp_threadCount = 0;
17 static inline int atomicinc(volatile int *lock) {
19 __asm__ __volatile__("lock; xadd %0,%1"
21 : "m"(*lock), "0"(retval)
27 // Need to have global lock before calling this method
29 if( cp_monitor != NULL )
32 struct coreprofmonitor* monitor =
33 calloc( 1, sizeof( struct coreprofmonitor ) );
35 struct coreprofmonitor* tmp;
37 // add ourself to the list
41 } while( CAS( &cp_monitorList,
47 int ourcount = atomicinc( &cp_threadCount );
48 cp_threadnum = ourcount;
50 // point thread lock variable to event monitor
52 CP_LOGEVENT( CP_EVENTID_MAIN, CP_EVENTTYPE_BEGIN );
55 // Place to do shutdown stuff
57 CP_LOGEVENT( CP_EVENTID_MAIN, CP_EVENTTYPE_END );
60 void cp_writedata( int fd, char* buffer, int count ) {
63 int size = write( fd, &buffer[offset], count );
72 //int fdh = open( "coreprof-head.dat", O_RDWR | O_CREAT, S_IRWXU );
73 //int fde = open( "coreprof-evnt.dat", O_RDWR | O_CREAT, S_IRWXU );
74 //int fdt = open( "coreprof-time.dat", O_RDWR | O_CREAT, S_IRWXU );
75 int fd = open( "coreprof.dat", O_RDWR | O_CREAT, S_IRWXU );
79 struct coreprofmonitor* monitor;
83 // Write version number
90 monitor = cp_monitorList;
91 while( monitor != NULL ) {
93 if( monitor->numEvents > CP_MAXEVENTS ) {
94 printf( "ERROR: EVENT COUNT EXCEEDED\n" );
96 monitor = monitor->next;
99 // Write the number of threads
104 monitor = cp_monitorList;
105 while( monitor != NULL ) {
107 // Write the number of events for each thread
109 (char*)&monitor->numEvents,
112 monitor = monitor->next;
115 // END HEADER, BEGIN DATA
117 monitor = cp_monitorList;
118 while( monitor != NULL ) {
120 // Write the event IDs (index matches time below)
122 (char*)monitor->events,
123 sizeof( unsigned int )*monitor->numEvents );
125 // Write the event timestamps (index matches above)
127 (char*)monitor->logTimes_ms,
128 sizeof( long long )*monitor->numEvents );
129 monitor = monitor->next;
138 void cp_reportOverflow() {
139 printf( "ERROR: coreprof event overflow\n" );