public static void main( String args[] ) {
- if( args.length < 2 ||
- args.length > 3 ) {
+ if( args.length < 2 ) {
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 );
}
-
- Trace t;
- if( args[0].equals( "-2txt" ) ) {
- t = new Trace( true, args[1], args[2] );
- } else {
- t = new Trace( false, args[0], args[1] );
+ String inputfile=null;
+ String outputfile=null;
+ boolean events=false;
+ HashSet<Integer> eventset=new HashSet<Integer>();
+ boolean hasinput=false;
+ long maxtime=-1;
+ long mintime=0;
+ long scale=1;
+
+ for(int i=0; i<args.length; i++) {
+ if (args[i].equals("-2txt")) {
+ events=true;
+ } else if (args[i].equals("-event")) {
+ eventset.add(Integer.parseInt(args[i+1]));
+ i++;
+ } else if (args[i].equals("-maxtime")) {
+ maxtime=Long.parseLong(args[i+1]);
+ i++;
+ } else if (args[i].equals("-mintime")) {
+ mintime=Long.parseLong(args[i+1]);
+ i++;
+ } else if (args[i].equals("-scale")) {
+ scale=Long.parseLong(args[i+1]);
+ i++;
+ } else {
+ if (hasinput) {
+ outputfile=args[i];
+ } else {
+ hasinput=true;
+ inputfile=args[i];
+ }
+ }
}
+
+ Trace t = new Trace(events, inputfile, outputfile, eventset, mintime, maxtime,scale);
}
int numThreads;
ThreadData[] threadData;
+ HashSet<Integer> eventset;
boolean convert2txt;
BufferedWriter txtStream;
boolean convert2plot;
BufferedWriter bwPlot;
long tSysZero;
- Hashtable<Integer, Integer> plottedEvents;
-
-
-
- public Trace( boolean c2txt, String inFile, String outFile ) {
-
+ long maxtime;
+ long mintime;
+ long scale;
+
+ public Trace( boolean c2txt, String inFile, String outFile, HashSet<Integer> eventset, long mintime, long maxtime, long scale) {
+ this.eventset=eventset;
+ this.maxtime=maxtime;
+ this.mintime=mintime;
+ this.scale=scale;
convert2txt = c2txt;
convert2plot = true;
initNames();
+ if (convert2plot) {
+ printPlotCmd();
+ }
+
for( int i = 0; i < numThreads; i++ ) {
readThread( i );
}
printStats( outFile );
if( convert2plot ) {
- printPlotCmd();
+ try {
+ bwPlot.write("plot [0:"+(globendtime/scale)+"] [-1:"+(numThreads+1)+"] -3\n");
+ bwPlot.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
while( skip > 0 ) {
skip -= threadData[i].dataStream.skip( skip );
}
+ threadData[i].dataStream.mark(20);
+ int eventRaw = readInt ( threadData[i].dataStream );
+ long Stamp = readLong( threadData[i].dataStream );
+ threadData[i].dataStream.reset();
+
+ if (globalstarttime==-1||globalstarttime>Stamp)
+ globalstarttime=Stamp;
+
offset += WORD_SIZE*threadData[i].numDataWords;
}
}
- 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;
}
j = 0;
+ long lasttime=-1;
while( i < tdata.numDataWords ) {
if( !progress[j] && i > j*progressChunk ) {
int eventType = eventRaw & CP_EVENT_MASK;
int eventID = eventRaw >> CP_EVENT_BASESHIFT;
- switch( eventType ) {
+ if (eventset.isEmpty()||eventset.contains(eventID))
+ switch( eventType ) {
case CP_EVENTTYPE_BEGIN: {
if( eventID == CP_EVENTID_MAIN ) {
tSysZero = timeStamp;
}
+ if( tdata.stackDepth>0 && convert2plot ) {
+ EventSummary esParent = tdata.eventStack.get( tdata.stackDepth - 1 );
+ long starttime=lasttime>esParent.timeStampBeginLatestInstance?lasttime:esParent.timeStampBeginLatestInstance;
+ addPointToPlot( tNum, esParent.eventID, starttime, timeStamp);
+ }
pushEvent( tdata, eventID, timeStamp );
} break;
case CP_EVENTTYPE_END: {
+ if( convert2plot ) {
+ EventSummary esParent = tdata.eventStack.get( tdata.stackDepth - 1 );
+ long starttime=lasttime>esParent.timeStampBeginLatestInstance?lasttime:esParent.timeStampBeginLatestInstance;
+
+ addPointToPlot( tNum, esParent.eventID, starttime, timeStamp);
+ lasttime=timeStamp;
+ }
popEvent( tdata, eventID, timeStamp );
} break;
-
- }
-
- if( convert2plot ) {
- addPointToPlot( timeStamp, eventID );
- }
+ }
}
System.out.println( "" );
// worker threads currently do not exit gracefully, and therefore
// may not register END events, so supply them with whatever the
// latest known timestamp is
- EventSummary eventSummary = tdata.eventStack.get( tdata.stackDepth );
+ EventSummary eventSummary = tdata.eventStack.get( tdata.stackDepth);
if( eventSummary == null ) {
// if there is no previous event it means there are no children
--tdata.stackDepth;
}
-
- if( convert2plot ) {
- try {
- bwPlot.close();
- } catch( IOException e ) {
- e.printStackTrace();
- System.exit( -1 );
- }
- }
}
}
}
+ long globalstarttime=-1;
+ long globendtime=-1;
- public void addPointToPlot( long timeStamp, int eventID ) {
-
- if( !plottedEvents.containsKey( eventID ) ) {
- plottedEvents.put( eventID, plottedEvents.size() );
- }
-
+ public void addPointToPlot( int thread, int eventID, long starttime, long endtime) {
try {
- bwPlot.write( (timeStamp - tSysZero)+" "+
- plottedEvents.get( eventID )+" "+
- getEventName( eventID )+"\n"
- );
+ long nstart=starttime-globalstarttime-mintime;
+ long nend=endtime-globalstarttime-mintime;
+ if ((maxtime==-1 || (endtime-globalstarttime)<maxtime)&&(nend>0)) {
+ if (nend>globendtime)
+ globendtime=nend;
+ if (nstart<0)
+ nstart=0;
+ bwPlot.write( "set arrow from "+(nstart/scale)+","+thread+" to "+(nend/scale)+","+thread+" lt "+eventID+" nohead\n");
+ }
} catch( IOException e ) {
e.printStackTrace();
System.exit( -1 );
public void printPlotCmd() {
try {
- BufferedWriter bw =
+ bwPlot =
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 );