public static void main( String args[] ) {
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"+
+ System.out.println( "usage: <coreprof.dat file> <trace out file> [-2txt]\n"+
+ "\nThe -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 );
boolean convert2txt;
BufferedWriter txtStream;
+ boolean convert2plot;
+ BufferedWriter bwPlot;
+ long tSysZero;
+ Hashtable<Integer, Integer> plottedEvents;
+
public Trace( boolean c2txt, String inFile, String outFile ) {
- convert2txt = c2txt;
+ convert2txt = c2txt;
+ convert2plot = true;
openInputStreams( inFile );
}
printStats( outFile );
+
+ if( convert2plot ) {
+ printPlotCmd();
+ }
}
offset = readHeader( bis );
bis.close();
- if( convert2txt ) {
- txtStream = new BufferedWriter( new FileWriter( "events.txt" ) );
- }
-
} catch( Exception e ) {
e.printStackTrace();
System.exit( -1 );
if( convert2txt ) {
try {
+ txtStream = new BufferedWriter( new FileWriter( "events.txt" ) );
+
txtStream.write( "\n\n\n\n" );
txtStream.write( "*************************************************\n" );
txtStream.write( "** Thread "+tNum+"\n" );
}
}
+ if( convert2plot ) {
+ try {
+ bwPlot = new BufferedWriter( new FileWriter( "plot-t"+tNum+".dat" ) );
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+
+ plottedEvents = new Hashtable<Integer, Integer>();
+ }
+
+
ThreadData tdata = threadData[tNum];
tdata.stackDepth = 0;
long timeStamp = 0;
switch( eventType ) {
case CP_EVENTTYPE_BEGIN: {
- pushEvent( tdata, eventID, timeStamp );
+ if( eventID == CP_EVENTID_MAIN ) {
+ tSysZero = timeStamp;
+ }
+
+ pushEvent( tdata, eventID, timeStamp );
} break;
case CP_EVENTTYPE_END: {
} break;
}
+
+ if( convert2plot ) {
+ addPointToPlot( timeStamp, eventID );
+ }
}
System.out.println( "" );
--tdata.stackDepth;
}
+
+
+ if( convert2plot ) {
+ try {
+ bwPlot.close();
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
}
}
+ public void addPointToPlot( long timeStamp, int eventID ) {
+
+ if( !plottedEvents.containsKey( eventID ) ) {
+ plottedEvents.put( eventID, plottedEvents.size() );
+ }
+
+ try {
+ bwPlot.write( (timeStamp - tSysZero)+" "+
+ plottedEvents.get( eventID )+" "+
+ getEventName( eventID )+"\n"
+ );
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
+
+
public void printStats( String filename ) {
printEventSummary( bw, esChild, depth + 1 );
}
}
+
+
+ public void printPlotCmd() {
+ try {
+ BufferedWriter bw =
+ new BufferedWriter( new FileWriter( "plot.cmd" ) );
+
+ bw.write( "set ytics\n" );
+ bw.write( "plot \\\n" );
+
+ for( int i = 0; i < numThreads; ++i ) {
+ bw.write( "\"plot-t"+i+".dat\" using 1:2:yticlabels(3) "+
+ "title 't"+i+"' with linespoints" );
+ if( i != numThreads - 1 ) {
+ bw.write( ", \\" );
+ }
+ bw.write( "\n" );
+ }
+
+ bw.close();
+ } catch( IOException e ) {
+ e.printStackTrace();
+ System.exit( -1 );
+ }
+ }
}