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 if( monitor == NULL ) {
36 printf( "ERROR: calloc returned NULL\n" );
40 struct coreprofmonitor* tmp;
42 // add ourself to the list
46 } while( CAS( &cp_monitorList,
52 int ourcount = atomicinc( &cp_threadCount );
53 cp_threadnum = ourcount;
55 // point thread lock variable to event monitor
57 CP_LOGEVENT( CP_EVENTID_MAIN, CP_EVENTTYPE_BEGIN );
60 // Place to do shutdown stuff
62 CP_LOGEVENT( CP_EVENTID_MAIN, CP_EVENTTYPE_END );
65 void cp_writedata( int fd, char* buffer, int count ) {
68 int size = write( fd, &buffer[offset], count );
77 int fd = open( "coreprof.dat", O_RDWR | O_CREAT, S_IRWXU );
81 struct coreprofmonitor* monitor;
85 // Write version number
91 // Write the number of threads
92 monitor = cp_monitorList;
93 while( monitor != NULL ) {
95 monitor = monitor->next;
101 // Write the number of words used to log
102 // events for each thread
103 monitor = cp_monitorList;
104 while( monitor != NULL ) {
106 (char*)&monitor->numWords,
108 monitor = monitor->next;
111 // END HEADER, BEGIN DATA
112 monitor = cp_monitorList;
113 while( monitor != NULL ) {
115 (char*)monitor->data,
116 sizeof( unsigned int )*monitor->numWords );
117 monitor = monitor->next;
124 void cp_reportOverflow() {
125 printf( "ERROR: coreprof event overflow\n" );