From: jjenista Date: Mon, 16 Aug 2010 23:03:10 +0000 (+0000) Subject: back out change to separate event type and timestamp streams, one stream supports... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=ff604fa0eda2f0a8d7447ca4e40048ed10be36ee back out change to separate event type and timestamp streams, one stream supports future variable-length event data easily --- diff --git a/Robust/CoreProf/Counter.java b/Robust/CoreProf/Counter.java index a94e30ae..90d5c2d8 100644 --- a/Robust/CoreProf/Counter.java +++ b/Robust/CoreProf/Counter.java @@ -3,6 +3,6 @@ public class Counter { } public long count; - public long totaltime; - public long selftime; -} \ No newline at end of file + public long totalTime; + public long selfTime; +} diff --git a/Robust/CoreProf/Event.java b/Robust/CoreProf/Event.java index aefbd07f..31bab08c 100644 --- a/Robust/CoreProf/Event.java +++ b/Robust/CoreProf/Event.java @@ -1,9 +1,14 @@ public class Event { - public long time; - public int event; - public Counter counter; - public Event(long t, int ev) { - time=t; - event=ev; + public long timeStamp; + public int eventID; + public Counter counter; + + public Event( long timeStamp, + int eventId, + Counter counter ) { + + this.timeStamp = timeStamp; + this.eventID = eventID; + this.counter = counter; } -} \ No newline at end of file +} diff --git a/Robust/CoreProf/Trace.java b/Robust/CoreProf/Trace.java index 3b69c1ce..e1b0603a 100644 --- a/Robust/CoreProf/Trace.java +++ b/Robust/CoreProf/Trace.java @@ -7,173 +7,207 @@ import java.util.Iterator; import java.util.Set; public class Trace { - int numThreads; - int[] eventCounts; - Event[][] eventstack; - Hashtable getcounter[]; - Hashtable eventnames=new Hashtable(); - public static final int STACKMAX=512; + // everything defined here should match coreprof.h + // definitions exactly + public static final int CP_EVENT_MASK = 3; + public static final int CP_EVENT_BASESHIFT = 2; + + public static final int CP_EVENTTYPE_BEGIN = 0; + public static final int CP_EVENTTYPE_END = 1; + public static final int CP_EVENTTYPE_ONEOFF = 2; + + public static final int CP_EVENTID_MAIN = 0; + public static final int CP_EVENTID_RUNMALLOC = 1; + public static final int CP_EVENTID_RUNFREE = 2; + public static final int CP_EVENTID_TASKDISPATCH = 3; + public static final int CP_EVENTID_TASKRETIRE = 4; + public static final int CP_EVENTID_TASKSTALLVAR = 5; + public static final int CP_EVENTID_TASKSTALLMEM = 6; void initNames() { - eventnames.put(CP_MAIN, "MAIN "); - eventnames.put(CP_RUNMALLOC,"RUNMALLOC"); - eventnames.put(CP_RUNFREE, "RUNFREE "); + eid2name = new Hashtable(); + eid2name.put( CP_EVENTID_MAIN, "MAIN " ); + eid2name.put( CP_EVENTID_RUNMALLOC, "RUNMALLOC " ); + eid2name.put( CP_EVENTID_RUNFREE, "RUNFREE " ); + eid2name.put( CP_EVENTID_TASKDISPATCH, "TASKDISPATCH" ); + eid2name.put( CP_EVENTID_TASKRETIRE, "TASKRETIRE " ); + eid2name.put( CP_EVENTID_TASKSTALLVAR, "TASKSTALLVAR" ); + eid2name.put( CP_EVENTID_TASKSTALLMEM, "TASKSTALLMEM" ); } + - public void printStats() { - for(int i=0;i evit=getcounter[i].keySet().iterator();evit.hasNext();) { - Integer event=evit.next(); - Counter c=getcounter[i].get(event); - String eventname=eventnames.containsKey(event)?eventnames.get(event):Integer.toString(event); - System.out.println("Event: "+eventname+" self time="+c.selftime+" total time="+c.totaltime+" count="+c.count); - } - System.out.println("-------------------------------------------------------------"); + public static void main( String args[] ) { + if( args.length != 1 ) { + System.out.println( "usage: " ); + System.exit( 0 ); } + Trace t = new Trace( args[0] ); + t.printStats(); } - public static int readInt(InputStream is) { - try { - int b1=is.read(); - int b2=is.read(); - int b3=is.read(); - int b4=is.read(); - int retval=(b4<<24)|(b3<<16)|(b2<<8)|b1; - if (retval<0) - throw new Error(); - return retval; - } catch (Exception e) { - throw new Error(); - } - } - public static long readLong(InputStream is) { - try { - long b1=is.read(); - long b2=is.read(); - long b3=is.read(); - long b4=is.read(); - long b5=is.read(); - long b6=is.read(); - long b7=is.read(); - long b8=is.read(); - long retval=(b8<<56)|(b7<<48)|(b6<<40)|(b5<<32)| - (b4<<24)|(b3<<16)|(b2<<8)|b1; - if (retval<0) - throw new Error(); - return retval; - } catch (Exception e) { - throw new Error(); - } - } + // event IDs are a word, timestamps are long ints + public static final int WORD_SIZE = 4; + public static final int EVENT_SIZE = WORD_SIZE; + public static final int TIMESTAMP_SIZE = WORD_SIZE*2; + public static final int STACKMAX = 512; - int readHeader(BufferedInputStream bir) { - //First check version - int offset=4; - int version=readInt(bir); - if (version!=0) - throw new Error("Unsupported Version"); - - //Second read number of threads - offset+=4; - numThreads=readInt(bir); - - //Third read event counts for each Thread - eventCounts=new int[numThreads]; - eventstack=new Event[numThreads][STACKMAX]; - for(int i=0;i[] threadNum2eid2c; + Hashtable eid2name; - BufferedInputStream threads[]; - public Trace(String filename) { + public Trace( String filename ) { + openInputStreams( filename ); initNames(); - BufferedInputStream bir=null; - int offset=0; + readThreads(); + } + + + protected void openInputStreams( String filename ) { + + BufferedInputStream bis = null; + int offset = 0; + try { - bir=new BufferedInputStream(new FileInputStream(filename)); - offset=readHeader(bir); - bir.close(); - } catch (Exception e) { + bis = new BufferedInputStream( new FileInputStream( filename ) ); + offset = readHeader( bis ); + bis.close(); + } catch( Exception e ) { e.printStackTrace(); - System.exit(-1); + System.exit( -1 ); } - threads=new BufferedInputStream[numThreads]; - getcounter=new Hashtable[numThreads]; - for(int i=0;i(); + threadNum2stream = new BufferedInputStream[numThreads]; + + for( int i = 0; i < numThreads; ++i ) { try { - threads[i]=new BufferedInputStream(new FileInputStream(filename)); - int skip=offset; - while (skip>0) { - skip-=threads[i].skip(skip); + + // point a thread's event stream to the + // beginning of its data within the input file + threadNum2stream[i] = + new BufferedInputStream( new FileInputStream( filename ) ); + + int skip = offset; + while( skip > 0 ) { + skip -= threadNum2stream[i].skip( skip ); } - offset+=4*eventCounts[i]; - } catch (Exception e) { + + offset += WORD_SIZE*threadNum2numWords[i]; + + } catch( Exception e ) { e.printStackTrace(); - System.exit(-1); + System.exit( -1 ); } } } + + int readHeader( BufferedInputStream bis ) { + + // check version + int version = readInt( bis ); + if( version != 0 ) { + throw new Error( "Unsupported Version" ); + } + int offset = WORD_SIZE; + + // read number of threads + numThreads = readInt( bis ); + offset += WORD_SIZE; + + // read number of words used for event, per thread + threadNum2numWords = new int[numThreads]; + threadNum2eventStack = new Event[numThreads][STACKMAX]; + for( int i = 0; i < numThreads; ++i ) { + threadNum2numWords[i] = readInt( bis ); + offset += WORD_SIZE; + } + return offset; + } + + public void readThreads() { - for(int i=0;i(); + readThread( i ); + } } + - public void readThread(int t) { - BufferedInputStream bis=threads[t]; - int numevents=eventCounts[t]; - Event[] stack=eventstack[t]; - Hashtable countertab=getcounter[t]; - int i=0; - int depth=0; - long time=0; - while(i>CP_BASE_SHIFT; - i+=3; //time and event - - switch(event&CP_MASK) { - case CP_BEGIN: - enqueue(stack, depth, baseevent, time, countertab); - depth++; - break; - case CP_END: { - depth--; - Event e=stack[depth]; - long elapsedtime=time-e.time; - Counter c=e.counter; - c.totaltime+=elapsedtime; - c.selftime+=elapsedtime; - if(depth-1>=0) { - Counter cn=stack[depth-1].counter; - cn.selftime-=elapsedtime; - } - break; - } - case CP_EVENT: { - Counter counter=countertab.get(event); - if (counter==null) { - Counter c=new Counter(); - countertab.put(event, c); - counter=c; - } - counter.count++; - break; - } + public void readThread( int tNum ) { + + BufferedInputStream stream = threadNum2stream [tNum]; + int numWords = threadNum2numWords [tNum]; + Event[] stack = threadNum2eventStack[tNum]; + Hashtable eid2c = threadNum2eid2c [tNum]; + + int depth = 0; + long timeStamp = 0; + int i = 0; + + while( i < numWords ) { + + int event = readInt ( stream ); + timeStamp = readLong( stream ); + i += 3; + + int eventType = event & CP_EVENT_MASK; + int eventID = event >> CP_EVENT_BASESHIFT; + + switch( eventType ) { + + case CP_EVENTTYPE_BEGIN: { + Counter counter = eid2c.get( eventID ); + if( counter == null ) { + counter = new Counter(); + eid2c.put( eventID, counter ); + } + counter.count++; + if( stack[depth] == null ) { + stack[depth] = new Event( timeStamp, eventID, counter ); + } else { + stack[depth].timeStamp = timeStamp; + stack[depth].eventID = eventID; + stack[depth].counter = counter; + } + depth++; + if( depth == STACKMAX ) { + throw new Error( "Event stack overflow\n" ); + } + } break; + + case CP_EVENTTYPE_END: { + depth--; + if( depth < 0 ) { + throw new Error( "Event stack underflow\n" ); + } + Event e = stack[depth]; + long elapsedTime = timeStamp - e.timeStamp; + Counter c = e.counter; + c.totalTime += elapsedTime; + c.selfTime += elapsedTime; + if( depth - 1 >= 0 ) { + Counter cParent = stack[depth-1].counter; + cParent.selfTime -= elapsedTime; + } + } break; } } - if (depth!=0) { + + + if( depth != 0 ) { + System.out.println( "Warning: unmatched event begin/end\n" ); + /* //get rid of last item also depth--; Event e=stack[depth]; @@ -184,40 +218,84 @@ public class Trace { if(depth-1>=0) { Counter cn=stack[depth-1].counter; cn.selftime-=elapsedtime; - } + } + */ } } - public static void enqueue(Event[] stack, int depth, int event, long time, Hashtable getcounter) { - Counter counter=getcounter.get(event); - if (counter==null) { - Counter c=new Counter(); - getcounter.put(event, c); - counter=c; + + public static int readInt( InputStream is ) { + try { + int b1 = is.read(); + int b2 = is.read(); + int b3 = is.read(); + int b4 = is.read(); + + int retval = (b4<<24)|(b3<<16)|(b2<<8)|b1; + + if( retval < 0 ) { + throw new Error(); + } + return retval; + + } catch( Exception e ) { + throw new Error(); } - counter.count++; - if (stack[depth]==null) { - stack[depth]=new Event(time,event); - stack[depth].counter=counter; - } else { - stack[depth].time=time; - stack[depth].event=event; - stack[depth].counter=counter; + } + + + public static long readLong( InputStream is ) { + try { + long b1 = is.read(); + long b2 = is.read(); + long b3 = is.read(); + long b4 = is.read(); + long b5 = is.read(); + long b6 = is.read(); + long b7 = is.read(); + long b8 = is.read(); + + long retval = + (b8<<56)|(b7<<48)|(b6<<40)|(b5<<32)| + (b4<<24)|(b3<<16)|(b2<< 8)|b1; + + if( retval < 0 ) { + throw new Error(); + } + return retval; + + } catch( Exception e ) { + throw new Error(); } } - public static final int CP_BEGIN=0; - public static final int CP_END=1; - public static final int CP_EVENT=2; - public static final int CP_MASK=3; - public static final int CP_BASE_SHIFT=2; - - public static final int CP_MAIN=0; - public static final int CP_RUNMALLOC=1; - public static final int CP_RUNFREE=2; - public static void main(String x[]) { - Trace t=new Trace(x[0]); - t.readThreads(); - t.printStats(); + + public void printStats() { + + for( int i = 0; i < numThreads; ++i ) { + + System.out.println( "Thread "+i ); + + for( Iterator evit = threadNum2eid2c[i].keySet().iterator(); + evit.hasNext(); + ) { + Integer event = evit.next(); + Counter c = threadNum2eid2c[i].get( event ); + String eventname = eid2name.containsKey( event ) ? + eid2name.get( event ) : + Integer.toString( event ); + + float tSelf_s = new Long( c.selfTime ).floatValue() / 1000000.0f; + float tTotal_s = new Long( c.totalTime ).floatValue() / 1000000.0f; + + System.out.println( "Event: "+eventname+ + " self time=" +tSelf_s+ + " total time="+tTotal_s+ + " count="+c.count + ); + } + System.out.println("----------------------------------------------------"); + } } + } diff --git a/Robust/CoreProf/makefile b/Robust/CoreProf/makefile new file mode 100644 index 00000000..056df63c --- /dev/null +++ b/Robust/CoreProf/makefile @@ -0,0 +1,6 @@ +all: + javac -Xlint Trace.java + +clean: + rm -f *.class + rm -f *~ diff --git a/Robust/cup/java_cup/runtime/lr_parser.class b/Robust/cup/java_cup/runtime/lr_parser.class index 3edd4973..338bdd88 100644 Binary files a/Robust/cup/java_cup/runtime/lr_parser.class and b/Robust/cup/java_cup/runtime/lr_parser.class differ diff --git a/Robust/src/Benchmarks/oooJava/barneshut/makefile b/Robust/src/Benchmarks/oooJava/barneshut/makefile index abaa27a4..777999c3 100644 --- a/Robust/src/Benchmarks/oooJava/barneshut/makefile +++ b/Robust/src/Benchmarks/oooJava/barneshut/makefile @@ -6,8 +6,8 @@ SOURCE_FILES=Barneshut.java BUILDSCRIPT=../../../buildscript USEOOO= -ooojava 24 2 -ooodebug -BSFLAGS= -64bit -mainclass $(PROGRAM) -garbagestats -joptimize -noloop -optimize -DISJOINT= -disjoint -disjoint-k 1 -enable-assertions +BSFLAGS= -64bit -mainclass $(PROGRAM) -heapsize-mb 1024 -garbagestats -debug -joptimize -noloop -optimize -coreprof -coreprof-checkoverflow +DISJOINT= -disjoint -disjoint-k 1 -enable-assertions #-disjoint-desire-determinism default: $(BUILDSCRIPT) -nojava $(USEOOO) $(BSFLAGS) $(DISJOINT) -o $(PROGRAM)p $(SOURCE_FILES) -builddir par diff --git a/Robust/src/Runtime/coreprof/coreprof.c b/Robust/src/Runtime/coreprof/coreprof.c index a21e856d..25437ad5 100644 --- a/Robust/src/Runtime/coreprof/coreprof.c +++ b/Robust/src/Runtime/coreprof/coreprof.c @@ -32,6 +32,11 @@ void cp_create() { struct coreprofmonitor* monitor = calloc( 1, sizeof( struct coreprofmonitor ) ); + if( monitor == NULL ) { + printf( "ERROR: calloc returned NULL\n" ); + exit( -1 ); + } + struct coreprofmonitor* tmp; // add ourself to the list @@ -69,11 +74,8 @@ void cp_writedata( int fd, char* buffer, int count ) { void cp_dump() { - //int fdh = open( "coreprof-head.dat", O_RDWR | O_CREAT, S_IRWXU ); - //int fde = open( "coreprof-evnt.dat", O_RDWR | O_CREAT, S_IRWXU ); - //int fdt = open( "coreprof-time.dat", O_RDWR | O_CREAT, S_IRWXU ); - int fd = open( "coreprof.dat", O_RDWR | O_CREAT, S_IRWXU ); - int count = 0; + int fd = open( "coreprof.dat", O_RDWR | O_CREAT, S_IRWXU ); + int numThreads = 0; int i; struct coreprofmonitor* monitor; @@ -86,52 +88,36 @@ void cp_dump() { (char*)&version, sizeof( int ) ); - // check for overflow + // Write the number of threads monitor = cp_monitorList; while( monitor != NULL ) { - count++; - if( monitor->numEvents > CP_MAXEVENTS ) { - printf( "ERROR: EVENT COUNT EXCEEDED\n" ); - } + numThreads++; monitor = monitor->next; } - - // Write the number of threads cp_writedata( fd, - (char*)&count, + (char*)&numThreads, sizeof( int ) ); + // Write the number of words used to log + // events for each thread monitor = cp_monitorList; while( monitor != NULL ) { - - // Write the number of events for each thread cp_writedata( fd, - (char*)&monitor->numEvents, + (char*)&monitor->numWords, sizeof( int ) ); - monitor = monitor->next; } // END HEADER, BEGIN DATA - monitor = cp_monitorList; while( monitor != NULL ) { - - // Write the event IDs (index matches time below) - cp_writedata( fd, - (char*)monitor->events, - sizeof( unsigned int )*monitor->numEvents ); - - // Write the event timestamps (index matches above) cp_writedata( fd, - (char*)monitor->logTimes_ms, - sizeof( long long )*monitor->numEvents ); + (char*)monitor->data, + sizeof( unsigned int )*monitor->numWords ); monitor = monitor->next; } close( fd ); - //close( fde ); - //close( fdt ); } diff --git a/Robust/src/Runtime/coreprof/coreprof.h b/Robust/src/Runtime/coreprof/coreprof.h index 3e1ab41d..2a176658 100644 --- a/Robust/src/Runtime/coreprof/coreprof.h +++ b/Robust/src/Runtime/coreprof/coreprof.h @@ -18,8 +18,9 @@ #include "runtime.h" -#ifndef CP_MAXEVENTS -#define CP_MAXEVENTS (1024*1024*128) +#ifndef CP_MAXEVENTWORDS +//#define CP_MAXEVENTWORDS (1024*1024*128) +#define CP_MAXEVENTWORDS (1024*128) #endif @@ -44,41 +45,44 @@ #define CP_EVENTID_TASKSTALLMEM 6 +extern __thread int cp_threadnum; +extern __thread struct coreprofmonitor* cp_monitor; +extern struct coreprofmonitor* cp_monitorList; + + struct coreprofmonitor { struct coreprofmonitor* next; - // index for next empty slot in the following arrays - int numEvents; - unsigned int events [CP_MAXEVENTS]; - long long logTimes_ms[CP_MAXEVENTS]; + // index for next unused word in the following array; + // individual events may use a variable number of + // words to store information + int numWords; + unsigned int data[CP_MAXEVENTWORDS]; }; -extern __thread int cp_threadnum; -extern __thread struct coreprofmonitor* cp_monitor; -extern struct coreprofmonitor* cp_monitorList; - - #ifndef COREPROF_CHECKOVERFLOW -// normal, no overflow check version -#define CP_LOGEVENT( eventID, eventType ) { \ - cp_monitor->events[cp_monitor->numEvents] = \ - ((eventID<logTimes_ms[cp_monitor->numEvents] = rdtsc(); \ - cp_monitor->numEvents++; \ -} +#define CP_CHECKOVERFLOW ; #else -// check for event overflow, DEBUG ONLY! -void cp_reportOverflow(); +#define CP_CHECKOVERFLOW if \ + ( cp_monitor->numWords == CP_MAXEVENTWORDS ) \ + { cp_reportOverflow(); } +#endif + + #define CP_LOGEVENT( eventID, eventType ) { \ - if( cp_monitor->numEvents == CP_MAXEVENTS ) \ - { cp_reportOverflow(); } \ - cp_monitor->events[cp_monitor->numEvents] = \ - ((eventID<logTimes_ms[cp_monitor->numEvents] = rdtsc(); \ - cp_monitor->numEvents++; \ + CP_CHECKOVERFLOW; \ + cp_monitor->data[cp_monitor->numWords] = \ + ((eventID << CP_EVENT_BASESHIFT) | eventType); \ + cp_monitor->numWords += 1; \ + CP_LOGTIME; \ } -#endif + + +#define CP_LOGTIME CP_CHECKOVERFLOW; \ + *((long long *)&cp_monitor->data[cp_monitor->numWords]) = rdtsc(); \ + cp_monitor->numWords += 2; + #define CP_CREATE() cp_create(); @@ -88,7 +92,7 @@ void cp_reportOverflow(); void cp_create(); void cp_exit(); void cp_dump(); - +void cp_reportOverflow(); static inline void* cp_calloc( int size ) {