From d18208cbe6af5b164249bbe930d3a6b39e34893f Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 3 Aug 2010 09:45:13 +0000 Subject: [PATCH] fix bugs --- Robust/CoreProf/Counter.java | 5 +-- Robust/CoreProf/Trace.java | 59 ++++++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Robust/CoreProf/Counter.java b/Robust/CoreProf/Counter.java index caf9eaa1..a94e30ae 100644 --- a/Robust/CoreProf/Counter.java +++ b/Robust/CoreProf/Counter.java @@ -2,6 +2,7 @@ public class Counter { public Counter() { } - public int totaltime; - public int selftime; + public long count; + public long totaltime; + public long selftime; } \ No newline at end of file diff --git a/Robust/CoreProf/Trace.java b/Robust/CoreProf/Trace.java index 775eaeb9..a25c8f6c 100644 --- a/Robust/CoreProf/Trace.java +++ b/Robust/CoreProf/Trace.java @@ -11,16 +11,25 @@ public class Trace { int[] eventCounts; Event[][] eventstack; Hashtable getcounter[]; + Hashtable eventnames=new Hashtable(); public static final int STACKMAX=512; + + void initNames() { + eventnames.put(CP_MAIN, "MAIN "); + eventnames.put(CP_RUNMALLOC,"RUNMALLOC"); + eventnames.put(CP_RUNFREE, "RUNFREE "); + } + 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); + String eventname=eventnames.containsKey(event)?eventnames.get(event):Integer.toString(event); + System.out.println("Event: "+eventname+" self time="+c.selftime+" total time="+c.totaltime+" count="+c.count); } System.out.println("-------------------------------------------------------------"); } @@ -85,6 +94,7 @@ public class Trace { BufferedInputStream threads[]; public Trace(String filename) { + initNames(); BufferedInputStream bir=null; int offset=0; try { @@ -113,18 +123,23 @@ public class Trace { } } } + + public void readThreads() { + for(int i=0;i countertab=getcounter[t]; - + int i=0; + int depth=0; + long time=0; while(i>CP_BASE_SHIFT; i+=3; //time and event @@ -134,21 +149,42 @@ public class Trace { depth++; break; case CP_END: { + depth--; 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; + if(depth-1>0) { + Counter cn=stack[depth-1].counter; + cn.selftime-=elapsedtime; } break; } - case CP_EVENT: + case CP_EVENT: { + Counter counter=countertab.get(event); + if (counter==null) { + Counter c=new Counter(); + countertab.put(event, c); + counter=c; + } + counter.count++; break; } + } + } + if (depth!=0) { + //get rid of last item also + depth--; + Event e=stack[depth]; + long elapsedtime=time-e.time; + Counter c=e.counter; + c.totaltime+=elapsedtime; + c.selftime+=elapsedtime; + if(depth-1>0) { + Counter cn=stack[depth-1].counter; + cn.selftime-=elapsedtime; + } } } @@ -157,7 +193,9 @@ public class Trace { if (counter==null) { Counter c=new Counter(); getcounter.put(event, c); + counter=c; } + counter.count++; if (stack[depth]==null) { stack[depth]=new Event(time,event); stack[depth].counter=counter; @@ -179,6 +217,7 @@ public class Trace { public static final int CP_RUNFREE=2; public static void main(String x[]) { Trace t=new Trace(x[0]); + t.readThreads(); t.printStats(); } } -- 2.34.1