org/objectweb/proactive/calcium/statistics/StatsImpl.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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         //sub task related stats
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         // **************   INTERFACE METHODS   *****************
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 }

Generated on Mon Jan 22 15:16:05 2007 for ProActive by  doxygen 1.5.1