00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.calcium.statistics;
00032
00033 import org.objectweb.proactive.calcium.interfaces.Muscle;
00034
00035 public class StatsImpl implements Stats {
00036
00037 private long computationTime;
00038 private long waitingTime, processingTime, readyTime, resultsTime;
00039 private long initTime, finitTime;
00040 private long currentStateStart;
00041 private Workout workout;
00042
00043
00044
00045 private int subTreeSize;
00046 private int numberLeafs;
00047
00048 public StatsImpl() {
00049 computationTime=0;
00050 waitingTime=processingTime=readyTime=resultsTime=0;
00051 initTime=System.currentTimeMillis();
00052 finitTime=0;
00053 currentStateStart=initTime;
00054
00055 subTreeSize =numberLeafs=0;
00056 workout= new Workout(8);
00057 }
00058
00059 public long getComputationTime(){
00060 return computationTime;
00061 }
00062
00063 public void addComputationTime(long time){
00064 computationTime+=time;
00065 }
00066
00067 public void exitReadyState() {
00068 readyTime += getStateElapsedTime();
00069 }
00070
00071 public void exitProcessingState() {
00072 processingTime += getStateElapsedTime();
00073 }
00074
00075 public void exitWaitingState() {
00076 waitingTime += getStateElapsedTime();
00077 }
00078
00079 public void exitResultsState() {
00080 resultsTime += getStateElapsedTime();
00081 }
00082
00083 private long getStateElapsedTime(){
00084 long initTime = currentStateStart;
00085 currentStateStart = System.currentTimeMillis();
00086 return currentStateStart - initTime ;
00087 }
00088
00089 @Override
00090 public String toString(){
00091 String ls= System.getProperty("line.separator");
00092
00093 return
00094 "Time: "+processingTime + "P " +
00095 readyTime + "R " +
00096 waitingTime + "W " +
00097 resultsTime + "F " +
00098 getWallClockTime() + "L " +
00099 getComputationTime()+ "C [ms] "+
00100 "TreeSize:" + getTreeSize() + " " +
00101 "TreeSpan:" + getTreeSpan() + " " +
00102 "TreeDepth:"+ getTreeDepth() + ls+
00103 workout;
00104 }
00105
00106 public void markFinishTime(){
00107 finitTime=System.currentTimeMillis();
00108 }
00109
00110 public Workout getWorkout(){
00111 return workout;
00112 }
00113
00114 public void addChildStats(StatsImpl stats) {
00115
00116 this.processingTime += stats.getProcessingTime();
00117 this.computationTime += stats.getComputationTime();
00118 this.readyTime +=stats.getReadyTime();
00119
00120 this.subTreeSize += stats.getTreeSize();
00121 this.numberLeafs += stats.getNumberLeafs()==0 ? 1 : stats.getNumberLeafs();
00122
00123 this.workout.track(stats.workout);
00124 }
00125
00126 private int getNumberLeafs() {
00127 return numberLeafs;
00128 }
00129
00130 private int getNumberInnerNodes(){
00131 return getTreeSize()-getNumberLeafs();
00132 }
00133
00134
00135
00136 public long getWallClockTime(){
00137 if(finitTime==0){
00138 return System.currentTimeMillis()-initTime;
00139 }
00140 return finitTime-initTime;
00141 }
00142
00143 public long getProcessingTime() {
00144 return processingTime;
00145 }
00146
00147 public long getReadyTime() {
00148 return readyTime;
00149 }
00150
00151 public long getResultsTime() {
00152 return resultsTime;
00153 }
00154
00155 public int getTreeSize() {
00156 return subTreeSize+1;
00157 }
00158
00159 public long getWaitingTime() {
00160 return waitingTime;
00161 }
00162
00163 public float getTreeDepth() {
00164 float base=getTreeSpan();
00165 if(base <= 0) return 0;
00166
00167 return (float) (Math.log(subTreeSize)/Math.log(base));
00168 }
00169
00170 public float getTreeSpan(){
00171 if(getNumberInnerNodes() == 0) return 0;
00172
00173 return subTreeSize/getNumberInnerNodes();
00174 }
00175
00176 public Exercise getExcercise(Muscle muscle) {
00177 return workout.getWorkout(muscle);
00178 }
00179 }