From 52ee21d8deb51b48393abc063242a732831d06c2 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 3 Aug 2010 08:04:54 +0000 Subject: [PATCH 1/1] changes --- Robust/CoreProf/Counter.java | 7 ++ Robust/CoreProf/Event.java | 9 ++ Robust/CoreProf/Plot.java | 69 +++++++++++++ Robust/CoreProf/Series.java | 28 ++++++ Robust/CoreProf/Trace.java | 184 +++++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+) create mode 100644 Robust/CoreProf/Counter.java create mode 100644 Robust/CoreProf/Event.java create mode 100644 Robust/CoreProf/Plot.java create mode 100644 Robust/CoreProf/Series.java create mode 100644 Robust/CoreProf/Trace.java diff --git a/Robust/CoreProf/Counter.java b/Robust/CoreProf/Counter.java new file mode 100644 index 00000000..caf9eaa1 --- /dev/null +++ b/Robust/CoreProf/Counter.java @@ -0,0 +1,7 @@ +public class Counter { + public Counter() { + } + + public int totaltime; + public int selftime; +} \ No newline at end of file diff --git a/Robust/CoreProf/Event.java b/Robust/CoreProf/Event.java new file mode 100644 index 00000000..aefbd07f --- /dev/null +++ b/Robust/CoreProf/Event.java @@ -0,0 +1,9 @@ +public class Event { + public long time; + public int event; + public Counter counter; + public Event(long t, int ev) { + time=t; + event=ev; + } +} \ No newline at end of file diff --git a/Robust/CoreProf/Plot.java b/Robust/CoreProf/Plot.java new file mode 100644 index 00000000..877ad06f --- /dev/null +++ b/Robust/CoreProf/Plot.java @@ -0,0 +1,69 @@ +import java.io.*; +import java.util.*; + +public class Plot { + PrintWriter out; + PrintWriter command; + String filename; + int count=0; + String cmdstr="plot "; + Hashtable series; + boolean first=true; + boolean percent; + public Plot(String filename, boolean percent) { + this(filename); + this.percent=percent; + } + + public Plot(String filename) { + try { + command=new PrintWriter(new FileOutputStream(filename+".cmd"), true); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + this.filename=filename; + series=new Hashtable(); + } + + public Series getSeries(String name) { + if (series.containsKey(name)) + return (Series)series.get(name); + Series s=createSeries(name); + series.put(name, s); + return s; + } + + private Series createSeries(String name) { + Series s=null; + try { + s=new Series(new PrintWriter(new FileOutputStream(filename+"."+count),true)); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + if (!first) cmdstr+=","; + first=false; + cmdstr+="\""+filename+"."+count+"\" title \""+name+"\""; + count++; + return s; + } + + public void close() { + for(Iterator it=series.values().iterator();it.hasNext();) { + Series s=(Series)it.next(); + s.close(); + } + command.println("set style data linespoints"); + command.println("set terminal postscript enhanced eps \"Times-Roman\" 18"); + command.println("set key left"); + command.println("set output \""+filename+"linear.eps\""); + command.println(cmdstr); + if (!percent) { + command.println("set log y"); + command.println("set output \""+filename+"log.eps\""); + command.println(cmdstr); + } + command.close(); + } +} \ No newline at end of file diff --git a/Robust/CoreProf/Series.java b/Robust/CoreProf/Series.java new file mode 100644 index 00000000..92dc9ae1 --- /dev/null +++ b/Robust/CoreProf/Series.java @@ -0,0 +1,28 @@ +import java.io.*; + +public class Series { + PrintWriter out; + public Series(PrintWriter out) { + this.out=out; + } + + public void addPoint(long x, int y) { + addPoint(Long.toString(x), Integer.toString(y)); + } + + public void addPoint(int x, double y) { + addPoint(Integer.toString(x), Double.toString(y)); + } + + public void addPoint(int x, long y) { + addPoint(Integer.toString(x), Long.toString(y)); + } + + public void addPoint(String time, String value) { + out.println(time+" "+value); + } + + public void close() { + out.close(); + } +} \ No newline at end of file diff --git a/Robust/CoreProf/Trace.java b/Robust/CoreProf/Trace.java new file mode 100644 index 00000000..775eaeb9 --- /dev/null +++ b/Robust/CoreProf/Trace.java @@ -0,0 +1,184 @@ +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.BufferedInputStream; +import java.util.Vector; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Set; + +public class Trace { + int numThreads; + int[] eventCounts; + Event[][] eventstack; + Hashtable getcounter[]; + + public static final int STACKMAX=512; + + public void printStats() { + for(int i=0;i evit=getcounter[i].keySet().iterator();evit.hasNext();) { + Integer event=evit.next(); + Counter c=getcounter[i].get(event); + System.out.println("Event: "+event+" self time="+c.selftime+" total time"+c.totaltime); + } + System.out.println("-------------------------------------------------------------"); + } + } + + public static int readInt(InputStream is) { + try { + int b1=is.read(); + int b2=is.read(); + int b3=is.read(); + int b4=is.read(); + int retval=(b4<<24)|(b3<<16)|(b2<<8)|b1; + if (retval<0) + throw new Error(); + return retval; + } catch (Exception e) { + throw new Error(); + } + } + + public static long readLong(InputStream is) { + try { + long b1=is.read(); + long b2=is.read(); + long b3=is.read(); + long b4=is.read(); + long b5=is.read(); + long b6=is.read(); + long b7=is.read(); + long b8=is.read(); + long retval=(b8<<56)|(b7<<48)|(b6<<40)|(b5<<32)| + (b4<<24)|(b3<<16)|(b2<<8)|b1; + if (retval<0) + throw new Error(); + return retval; + } catch (Exception e) { + throw new Error(); + } + } + + int readHeader(BufferedInputStream bir) { + //First check version + int offset=4; + int version=readInt(bir); + if (version!=0) + throw new Error("Unsupported Version"); + + //Second read number of threads + offset+=4; + numThreads=readInt(bir); + + //Third read event counts for each Thread + eventCounts=new int[numThreads]; + eventstack=new Event[numThreads][STACKMAX]; + for(int i=0;i(); + try { + threads[i]=new BufferedInputStream(new FileInputStream(filename)); + int skip=offset; + while (skip>0) { + skip-=threads[i].skip(skip); + } + offset+=4*eventCounts[i]; + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } + } + } + + public void readThread(int t) { + BufferedInputStream bis=threads[t]; + int numevents=eventCounts[t]; + int i=0; + Event[] stack=eventstack[t]; + int depth=0; + Hashtable countertab=getcounter[t]; + + while(i>CP_BASE_SHIFT; + i+=3; //time and event + + switch(event&CP_MASK) { + case CP_BEGIN: + enqueue(stack, depth, baseevent, time, countertab); + depth++; + break; + case CP_END: { + Event e=stack[depth]; + long elapsedtime=time-e.time; + Counter c=e.counter; + c.totaltime+=elapsedtime; + c.selftime+=elapsedtime; + depth--; + for(int j=depth;j>=0;j--) { + Counter cn=e.counter; + cn.totaltime-=elapsedtime; + } + break; + } + case CP_EVENT: + break; + } + } + } + + public static void enqueue(Event[] stack, int depth, int event, long time, Hashtable getcounter) { + Counter counter=getcounter.get(event); + if (counter==null) { + Counter c=new Counter(); + getcounter.put(event, c); + } + if (stack[depth]==null) { + stack[depth]=new Event(time,event); + stack[depth].counter=counter; + } else { + stack[depth].time=time; + stack[depth].event=event; + stack[depth].counter=counter; + } + } + + public static final int CP_BEGIN=0; + public static final int CP_END=1; + public static final int CP_EVENT=2; + public static final int CP_MASK=3; + public static final int CP_BASE_SHIFT=2; + + public static final int CP_MAIN=0; + public static final int CP_RUNMALLOC=1; + public static final int CP_RUNFREE=2; + public static void main(String x[]) { + Trace t=new Trace(x[0]); + t.printStats(); + } +} -- 2.34.1