have coreprof plot events
authorjjenista <jjenista>
Tue, 2 Nov 2010 02:56:14 +0000 (02:56 +0000)
committerjjenista <jjenista>
Tue, 2 Nov 2010 02:56:14 +0000 (02:56 +0000)
Robust/CoreProf/Trace.java
Robust/CoreProf/makefile

index 0d69195e7ed5919c96238fe04af5d5c154475442..6665d0b1991c046520f1893396c423fc7ef7878f 100644 (file)
@@ -71,8 +71,8 @@ public class Trace {
   public static void main( String args[] ) {
     if( args.length < 2 ||
         args.length > 3 ) {
   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 );
                           "out every event as text in events.txt, useful for debugging\n"+
                           "event mis-matches." );
       System.exit( 0 );
@@ -99,11 +99,17 @@ public class Trace {
   boolean        convert2txt;
   BufferedWriter txtStream;
 
   boolean        convert2txt;
   BufferedWriter txtStream;
 
+  boolean             convert2plot;
+  BufferedWriter      bwPlot;
+  long                tSysZero;
+  Hashtable<Integer, Integer> plottedEvents;
+
 
 
   public Trace( boolean c2txt, String inFile, String outFile ) {
 
 
 
   public Trace( boolean c2txt, String inFile, String outFile ) {
 
-    convert2txt = c2txt;
+    convert2txt  = c2txt;
+    convert2plot = true;
 
     openInputStreams( inFile );
 
 
     openInputStreams( inFile );
 
@@ -114,6 +120,10 @@ public class Trace {
     }
 
     printStats( outFile );
     }
 
     printStats( outFile );
+
+    if( convert2plot ) {
+      printPlotCmd();
+    }
   }
 
 
   }
 
 
@@ -173,10 +183,6 @@ public class Trace {
       offset = readHeader( bis );
       bis.close();
 
       offset = readHeader( bis );
       bis.close();
 
-      if( convert2txt ) {
-        txtStream = new BufferedWriter( new FileWriter( "events.txt" ) );
-      }
-
     } catch( Exception e ) {
       e.printStackTrace();
       System.exit( -1 );
     } catch( Exception e ) {
       e.printStackTrace();
       System.exit( -1 );
@@ -235,6 +241,8 @@ public class Trace {
 
     if( convert2txt ) {
       try {
 
     if( convert2txt ) {
       try {
+        txtStream = new BufferedWriter( new FileWriter( "events.txt" ) );
+
         txtStream.write( "\n\n\n\n" );
         txtStream.write( "*************************************************\n" );
         txtStream.write( "**  Thread "+tNum+"\n" );
         txtStream.write( "\n\n\n\n" );
         txtStream.write( "*************************************************\n" );
         txtStream.write( "**  Thread "+tNum+"\n" );
@@ -245,6 +253,18 @@ 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<Integer, Integer>();
+    }
+
+
     ThreadData tdata = threadData[tNum];
     tdata.stackDepth = 0;
     long timeStamp   = 0;
     ThreadData tdata = threadData[tNum];
     tdata.stackDepth = 0;
     long timeStamp   = 0;
@@ -279,7 +299,11 @@ public class Trace {
       switch( eventType ) {
 
         case CP_EVENTTYPE_BEGIN: {
       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;
 
         case CP_EVENTTYPE_END: {
@@ -287,6 +311,10 @@ public class Trace {
         } break;    
     
       }
         } break;    
     
       }
+
+      if( convert2plot ) {
+        addPointToPlot( timeStamp, eventID );
+      }
     }
 
     System.out.println( "" );
     }
 
     System.out.println( "" );
@@ -307,6 +335,16 @@ public class Trace {
 
       --tdata.stackDepth;
     }
 
       --tdata.stackDepth;
     }
+
+
+    if( convert2plot ) {
+      try {
+        bwPlot.close();
+      } catch( IOException e ) {
+        e.printStackTrace();
+        System.exit( -1 );
+      }
+    }
   }
 
 
   }
 
 
@@ -436,6 +474,24 @@ public class Trace {
   }
 
 
   }
 
 
+  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 ) {
 
 
   public void printStats( String filename ) {
 
@@ -532,4 +588,29 @@ public class Trace {
       printEventSummary( bw, esChild, depth + 1 );
     }    
   }
       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 );
+    }    
+  }
 }
 }
index 79ecaa140c38214288af9881090c6f3a483525df..e534b7c6f9f32bc1eb98179a811de2e20c5073ba 100644 (file)
@@ -6,6 +6,10 @@ run:
        java -ea Trace coreprof.dat trace.out
 
 
        java -ea Trace coreprof.dat trace.out
 
 
+plot: coreprof.dat
+       gnuplot plot.cmd
+
+
 clean:
        rm -f *.class
        rm -f *~
 clean:
        rm -f *.class
        rm -f *~