From c2fe59261e1ac72dd4b5f1b7a89acc895c1e3044 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 2 Nov 2010 14:47:20 +0000 Subject: [PATCH] update trace to dump out gnuplot plots --- Robust/CoreProf/Trace.java | 161 +++++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 68 deletions(-) diff --git a/Robust/CoreProf/Trace.java b/Robust/CoreProf/Trace.java index 6665d0b1..d85b15a2 100644 --- a/Robust/CoreProf/Trace.java +++ b/Robust/CoreProf/Trace.java @@ -69,21 +69,48 @@ public class Trace { public static void main( String args[] ) { - if( args.length < 2 || - args.length > 3 ) { + if( args.length < 2 ) { System.out.println( "usage: [-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 eventset=new HashSet(); + boolean hasinput=false; + long maxtime=-1; + long mintime=0; + long scale=1; + + for(int i=0; i eventset; boolean convert2txt; BufferedWriter txtStream; @@ -102,12 +130,15 @@ public class Trace { boolean convert2plot; BufferedWriter bwPlot; long tSysZero; - Hashtable plottedEvents; - - - - public Trace( boolean c2txt, String inFile, String outFile ) { - + long maxtime; + long mintime; + long scale; + + public Trace( boolean c2txt, String inFile, String outFile, HashSet eventset, long mintime, long maxtime, long scale) { + this.eventset=eventset; + this.maxtime=maxtime; + this.mintime=mintime; + this.scale=scale; convert2txt = c2txt; convert2plot = true; @@ -115,6 +146,10 @@ public class Trace { initNames(); + if (convert2plot) { + printPlotCmd(); + } + for( int i = 0; i < numThreads; i++ ) { readThread( i ); } @@ -122,7 +157,12 @@ public class Trace { printStats( outFile ); if( convert2plot ) { - printPlotCmd(); + try { + bwPlot.write("plot [0:"+(globendtime/scale)+"] [-1:"+(numThreads+1)+"] -3\n"); + bwPlot.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } @@ -199,6 +239,14 @@ public class Trace { 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; @@ -253,17 +301,6 @@ public class Trace { } } - if( convert2plot ) { - try { - bwPlot = new BufferedWriter( new FileWriter( "plot-t"+tNum+".dat" ) ); - } catch( IOException e ) { - e.printStackTrace(); - System.exit( -1 ); - } - - plottedEvents = new Hashtable(); - } - ThreadData tdata = threadData[tNum]; tdata.stackDepth = 0; @@ -279,6 +316,7 @@ public class Trace { } j = 0; + long lasttime=-1; while( i < tdata.numDataWords ) { if( !progress[j] && i > j*progressChunk ) { @@ -296,25 +334,33 @@ public class Trace { 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( "" ); @@ -323,7 +369,7 @@ public class Trace { // 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 @@ -336,15 +382,6 @@ public class Trace { --tdata.stackDepth; } - - if( convert2plot ) { - try { - bwPlot.close(); - } catch( IOException e ) { - e.printStackTrace(); - System.exit( -1 ); - } - } } @@ -473,18 +510,20 @@ public class Trace { } } + 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)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 ); @@ -592,22 +631,8 @@ public class Trace { 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 ); -- 2.34.1