9 __thread struct coreprofmonitor * cp_events;
10 struct coreprofmonitor * cp_eventlist=NULL;
11 static volatile int cp_threadcount=0;
12 __thread int threadnum;
14 //Need to have global lock before calling this method
15 void createprofiler() {
16 struct coreprofmonitor *event=calloc(1, sizeof(struct coreprofmonitor));
17 //add new eventmonitor to list
18 struct coreprofmonitor *tmp;
20 //add ourself to the list
24 } while(CAS(&cp_eventlist, tmp, event)!=tmp);
26 int ourcount=atomic_inc(&cp_threadcount);
27 cp_threadnum=ourcount;
29 //point thread lock variable to eventmonitor
31 CPLOGEVENT((CP_START<<CP_BASE_SHIFT)|CP_BEGIN);
34 void cpwritedata(int fd, char * buffer, int count) {
37 int size=write(fd, &buffer[offset], count);
44 int fd=open("logdata",O_RDWR|O_CREAT,S_IRWXU);
46 struct coreprofmonitor * ptr=cp_eventlist;
48 //Write version number
49 cpwritedata(fd, &version, sizeof(int));
52 if (ptr->index>CPMAXEVENTS) {
53 printf("ERROR: EVENT COUNT EXCEEDED\n");
58 //Write the number of threads
59 cpwritedata(fd, (char *)&count, sizeof(int));
61 //Write the number of events for each thread
64 cpwritedata(fd, &ptr->index, sizeof(int));
71 cpwritedata(fd, (char *) ptr->value, sizeof(int)*ptr->index);