public static final int CP_EVENTTYPE_END = 2;
public static final int CP_EVENTTYPE_ONEOFF = 3;
- public static final int CP_EVENTID_MAIN = 0x04;
- public static final int CP_EVENTID_RUNMALLOC = 0x10;
- public static final int CP_EVENTID_RUNFREE = 0x11;
- public static final int CP_EVENTID_WORKSCHEDGRAB = 0x20;
- public static final int CP_EVENTID_TASKDISPATCH = 0x30;
- public static final int CP_EVENTID_TASKEXECUTE = 0x31;
- public static final int CP_EVENTID_TASKRETIRE = 0x32;
- public static final int CP_EVENTID_TASKSTALLVAR = 0x40;
- public static final int CP_EVENTID_TASKSTALLMEM = 0x41;
+ public static final int CP_EVENTID_MAIN = 0x04;
+ public static final int CP_EVENTID_RUNMALLOC = 0x10;
+ public static final int CP_EVENTID_RUNFREE = 0x11;
+ public static final int CP_EVENTID_POOLALLOC = 0x14;
+ public static final int CP_EVENTID_COUNT_POOLALLOC = 0x15;
+ public static final int CP_EVENTID_COUNT_POOLREUSE = 0x16;
+ public static final int CP_EVENTID_WORKSCHEDGRAB = 0x20;
+ public static final int CP_EVENTID_TASKDISPATCH = 0x30;
+ public static final int CP_EVENTID_PREPAREMEMQ = 0x31;
+ public static final int CP_EVENTID_TASKEXECUTE = 0x40;
+ public static final int CP_EVENTID_TASKRETIRE = 0x50;
+ public static final int CP_EVENTID_TASKSTALLVAR = 0x60;
+ public static final int CP_EVENTID_TASKSTALLMEM = 0x61;
+ public static final int CP_EVENTID_DEBUG_A = 0x180;
+ public static final int CP_EVENTID_DEBUG_B = 0x181;
+ public static final int CP_EVENTID_DEBUG_C = 0x182;
+ public static final int CP_EVENTID_DEBUG_D = 0x183;
+ public static final int CP_EVENTID_DEBUG_E = 0x184;
+ public static final int CP_EVENTID_DEBUG_F = 0x185;
+ public static final int CP_EVENTID_DEBUG_G = 0x186;
+ public static final int CP_EVENTID_DEBUG_H = 0x187;
+ public static final int CP_EVENTID_DEBUG_I = 0x188;
+ public static final int CP_EVENTID_DEBUG_J = 0x189;
void initNames() {
eid2name = new Hashtable<Integer, String>();
- eid2name.put( CP_EVENTID_MAIN, "MAIN " );
- eid2name.put( CP_EVENTID_RUNMALLOC, "RUNMALLOC " );
- eid2name.put( CP_EVENTID_RUNFREE, "RUNFREE " );
- eid2name.put( CP_EVENTID_WORKSCHEDGRAB, "WORKSCHEDGRAB" );
- eid2name.put( CP_EVENTID_TASKDISPATCH, "TASKDISPATCH " );
- eid2name.put( CP_EVENTID_TASKEXECUTE, "TASKEXECUTE " );
- eid2name.put( CP_EVENTID_TASKRETIRE, "TASKRETIRE " );
- eid2name.put( CP_EVENTID_TASKSTALLVAR, "TASKSTALLVAR " );
- eid2name.put( CP_EVENTID_TASKSTALLMEM, "TASKSTALLMEM " );
+ eid2name.put( CP_EVENTID_MAIN, "MAIN " );
+ eid2name.put( CP_EVENTID_RUNMALLOC, "RUNMALLOC " );
+ eid2name.put( CP_EVENTID_RUNFREE, "RUNFREE " );
+ eid2name.put( CP_EVENTID_POOLALLOC, "POOLALLOC " );
+ eid2name.put( CP_EVENTID_COUNT_POOLALLOC, "POOLALLOC CNT" );
+ eid2name.put( CP_EVENTID_COUNT_POOLREUSE, "POOLREUSE CNT" );
+ eid2name.put( CP_EVENTID_WORKSCHEDGRAB, "WORKSCHEDGRAB" );
+ eid2name.put( CP_EVENTID_TASKDISPATCH, "TASKDISPATCH " );
+ eid2name.put( CP_EVENTID_PREPAREMEMQ, "PREPAREMEMQ " );
+ eid2name.put( CP_EVENTID_TASKEXECUTE, "TASKEXECUTE " );
+ eid2name.put( CP_EVENTID_TASKRETIRE, "TASKRETIRE " );
+ eid2name.put( CP_EVENTID_TASKSTALLVAR, "TASKSTALLVAR " );
+ eid2name.put( CP_EVENTID_TASKSTALLMEM, "TASKSTALLMEM " );
+ eid2name.put( CP_EVENTID_DEBUG_A, "DEBUG A " );
+ eid2name.put( CP_EVENTID_DEBUG_B, "DEBUG B " );
+ eid2name.put( CP_EVENTID_DEBUG_C, "DEBUG C " );
+ eid2name.put( CP_EVENTID_DEBUG_D, "DEBUG D " );
+ eid2name.put( CP_EVENTID_DEBUG_E, "DEBUG E " );
+ eid2name.put( CP_EVENTID_DEBUG_F, "DEBUG F " );
+ eid2name.put( CP_EVENTID_DEBUG_G, "DEBUG G " );
+ eid2name.put( CP_EVENTID_DEBUG_H, "DEBUG H " );
+ eid2name.put( CP_EVENTID_DEBUG_I, "DEBUG I " );
+ eid2name.put( CP_EVENTID_DEBUG_J, "DEBUG J " );
}
Hashtable<Integer, String> eid2name;
public static void main( String args[] ) {
- if( args.length != 2 ) {
- System.out.println( "usage: <coreprof.dat file> <trace out file>" );
+ if( args.length < 2 ||
+ args.length > 3 ) {
+ System.out.println( "usage: [-2txt] <coreprof.dat file> <trace out file>" );
+ System.out.println( "The -2txt option will take the raw binary events and spit\n"+
+ "out every event as text in events.txt, useful for debugging\n"+
+ "event mis-matches." );
System.exit( 0 );
}
- Trace t = new Trace( args[0], args[1] );
+
+ Trace t;
+ if( args[0].equals( "-2txt" ) ) {
+ t = new Trace( true, args[1], args[2] );
+ } else {
+ t = new Trace( false, args[0], args[1] );
+ }
}
int numThreads;
ThreadData[] threadData;
+ boolean convert2txt;
+ BufferedWriter txtStream;
+
+
+ public Trace( boolean c2txt, String inFile, String outFile ) {
- public Trace( String inFile, String outFile ) {
+ convert2txt = c2txt;
openInputStreams( inFile );
bis = new BufferedInputStream( new FileInputStream( filename ) );
offset = readHeader( bis );
bis.close();
+
+ if( convert2txt ) {
+ txtStream = new BufferedWriter( new FileWriter( "events.txt" ) );
+ }
+
} catch( Exception e ) {
e.printStackTrace();
System.exit( -1 );
System.out.print( "Reading thread "+tNum );
+ if( convert2txt ) {
+ try {
+ txtStream.write( "\n\n\n\n" );
+ txtStream.write( "*************************************************\n" );
+ txtStream.write( "** Thread "+tNum+"\n" );
+ txtStream.write( "*************************************************\n" );
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
+
ThreadData tdata = threadData[tNum];
tdata.stackDepth = 0;
long timeStamp = 0;
System.out.println( "" );
- if( tdata.stackDepth != 0 ) {
+ while( tdata.stackDepth > 0 ) {
// worker threads currently do not exit gracefully, and therefore
- // never register their MAIN END event, so if the mismatch is with
- // MAIN BEGIN then treat it as fine, otherwise warn.
- if( tdata.stackDepth == 1 ) {
- // the value of timestamp will be equal to whatever the last
- // properly registered event for this thread was
- popEvent( tdata, CP_EVENTID_MAIN, timeStamp );
- } else {
- System.out.println( "Warning: unmatched event begin/end\n" );
+ // may not register END events, so supply them with whatever the
+ // latest known timestamp is
+ EventSummary eventSummary = tdata.eventStack.get( tdata.stackDepth );
+
+ if( eventSummary == null ) {
+ // if there is no previous event it means there are no children
+ // events with a timestamp for the workaround, so just punt
+ break;
}
+
+ popEvent( tdata, eventSummary.eventID, timeStamp );
+
+ --tdata.stackDepth;
}
}
if( tdata.eventStack.size() <= tdata.stackDepth ) {
tdata.eventStack.setSize( 2*tdata.stackDepth + 20 );
}
+
tdata.eventStack.set( tdata.stackDepth, eventSummary );
+
+ // print to the event text file (if needed) before
+ // updating the stack depth to get tabs right
+ if( convert2txt ) {
+ try {
+ for( int tabs = 0; tabs < tdata.stackDepth; ++tabs ) {
+ txtStream.write( " " );
+ }
+ txtStream.write( "begin "+getEventName( eventID )+"@"+timeStamp+"\n" );
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
+
+
tdata.stackDepth++;
}
int eventID,
long timeStamp ) {
tdata.stackDepth--;
+
+
+ // print to the event text file (if needed) after
+ // updating the stack depth to get tabs right
+ if( convert2txt ) {
+ try {
+ for( int tabs = 0; tabs < tdata.stackDepth; ++tabs ) {
+ txtStream.write( " " );
+ }
+ txtStream.write( "end "+getEventName( eventID )+"@"+timeStamp+"\n" );
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
+
+
if( tdata.stackDepth < 0 ) {
throw new Error( "Event stack underflow\n" );
}
EventSummary eventSummary = tdata.eventStack.get( tdata.stackDepth );
assert eventSummary != null;
+ if( eventSummary.eventID != eventID ) {
+ System.out.println( "Warning: event begin("+
+ getEventName( eventSummary.eventID )+
+ ") end("+
+ getEventName( eventID )+
+ ") mismatch!\n" );
+ }
+
long elapsedTime =
timeStamp - eventSummary.timeStampBeginLatestInstance;
}
bw.close();
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
+
- } catch( IOException e ) {}
+ public String getEventName( int eventID ) {
+ return
+ eid2name.containsKey( eventID ) ?
+ eid2name.get ( eventID ) :
+ Integer.toString ( eventID );
}
strIndent += "--";
}
- String strEventName =
- eid2name.containsKey( es.eventID ) ?
- eid2name.get( es.eventID ) :
- Integer.toString( es.eventID );
+ String strEventName = getEventName( es.eventID );
float tOfParent_perc;
String strPercParent = "";
new Long( es.totalTime_ticks ).floatValue();
String strSelfStats =
- String.format( " total(ticks)=%12dK, %%self=%5.1f, count=%d",
+ String.format( " total(ticks)=%12dK, %%self=%5.1f, count=%d, avgTicks=%d",
es.totalTime_ticks/1000,
tSelf_perc,
- es.instanceCount );
+ es.instanceCount,
+ (int)((float)es.totalTime_ticks/(float)es.instanceCount) );
bw.write( strIndent+
strEventName+