org/objectweb/proactive/benchmarks/timit/util/HierarchicalTimerStatistics.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.benchmarks.timit.util;
00032 
00033 import java.io.Serializable;
00034 
00035 import org.objectweb.proactive.benchmarks.timit.TimIt;
00036 
00042 public class HierarchicalTimerStatistics implements Serializable {
00043 
00047     private static final long serialVersionUID = 2887387260859694305L;
00048 
00049     private String[] timerName;
00050 
00051     private double[][][] deviation;
00052 
00053     private double[][][] average;
00054 
00055     private double[][][] min;
00056 
00057     private double[][][] max;
00058 
00059     private int[] hierarchy;
00060 
00061     private int nb;
00062 
00063     private int padding;
00064 
00065     private boolean empty;
00066 
00071     public HierarchicalTimerStatistics() {
00072         this(new String[1], new double[1][1][1], new double[1][1][1],
00073                 new double[1][1][1], new double[1][1][1], new int[1], 0);
00074         this.empty = true;
00075     }
00076 
00089     public HierarchicalTimerStatistics(String[] timerName,
00090             double[][][] deviation, double[][][] average, double[][][] min,
00091             double[][][] max, int[] hierarchy, int nb) {
00092         this.timerName = timerName.clone();
00093         this.deviation = deviation.clone();
00094         this.average = average.clone();
00095         this.min = min.clone();
00096         this.max = max.clone();
00097         this.hierarchy = hierarchy.clone();
00098         this.nb = nb;
00099         this.empty = false;
00100     }
00101 
00102     public double getDeviation(int i, int j, int k) {
00103         return this.deviation[i][j][k];
00104     }
00105 
00106     public double getAverage(int i, int j, int k) {
00107         return this.average[i][j][k];
00108     }
00109 
00110     public double getMin(int i, int j, int k) {
00111         return this.min[i][j][k];
00112     }
00113 
00114     public double getMax(int i, int j, int k) {
00115         return this.max[i][j][k];
00116     }
00117 
00118     public String getFormDeviation(int i, int j, int k) {
00119         return TimIt.df.format(this.deviation[i][j][k]);
00120     }
00121 
00122     public String getFormAverage(int i, int j, int k) {
00123         return TimIt.df.format(this.average[i][j][k]);
00124     }
00125 
00126     public String getFormMin(int i, int j, int k) {
00127         return TimIt.df.format(this.min[i][j][k]);
00128     }
00129 
00130     public String getFormMax(int i, int j, int k) {
00131         return TimIt.df.format(this.max[i][j][k]);
00132     }
00133 
00134     public int getParent(int i, int j, int k) {
00135         return this.hierarchy[i];
00136     }
00137 
00138     public String[] getNameArray() {
00139         return this.timerName.clone();
00140     }
00141 
00142     public int getNb() {
00143         return this.nb;
00144     }
00145 
00146     public int[] getHierarchy() {
00147         return this.hierarchy.clone();
00148     }
00149 
00150     public void setTimerName(int id, String name) {
00151         this.timerName[id] = name;
00152     }
00153 
00157     public String toString() {
00158         if ( this.empty || this.timerName.length == 0 ) {
00159             return "";
00160         }
00161 
00162         String result = "";
00163         int i, j, k;
00164 
00165         // Suppose that the root timer is the first of the timerName array
00166         String rootName = this.timerName[0];
00167         String tName;
00168         String first = "\n";
00169 
00170         this.padding = (int) Math.ceil(Math.log10(this.max[0][0][0])) + 4;
00171 
00172         for (i = 0; i < this.nb; i++) {
00173             for (j = 0; j < this.nb; j++) {
00174                 for (k = 0; k < this.nb; k++) {
00175 
00176                     if (this.min[i][j][k] != -1) {
00177 
00178                         // If the current timer name is the rootName print data
00179                         if (this.timerName[k] != null) {
00180                             if (this.timerName[k].equals(rootName)) {
00181                                 tName = rootName + " :";
00182                                 tName = this.paddingString(tName, 30,
00183                                         ' ', false);
00184                                 result += tName
00185                                         + "min "
00186                                         + this.format(this.min[i][j][k]);
00187                             } else {
00188                                 if (this.timerName[j] != null) {
00189                                     if (this.timerName[k]
00190                                             .equals(this.timerName[j])) {
00191                                         tName = "-----> " + this.timerName[j]
00192                                                 + " :";
00193                                         tName = this.paddingString(tName, 30,
00194                                                 ' ', false);
00195                                         result += tName
00196                                                 + "min "
00197                                                 + this.format(this.min[i][j][k]);
00198                                     } else {
00199                                         tName = "        -----> "
00200                                                 + this.timerName[k] + " :";
00201                                         tName = this.paddingString(tName, 30,
00202                                                 ' ', false);
00203                                         result += tName
00204                                                 + "min "
00205                                                 + this.format(this.min[i][j][k]);
00206                                     }
00207                                 }
00208                             }
00209                         }
00210                     }
00211 
00212                     if (this.average[i][j][k] != -1) {
00213                         result += "avg " + this.format(this.average[i][j][k]);
00214                     }
00215                     if (this.max[i][j][k] != -1) {
00216                         result += "max " + this.format(this.max[i][j][k]);
00217                     }
00218                     if (this.deviation[i][j][k] != -1) {
00219                         result += "dev " + this.format(this.deviation[i][j][k])
00220                                 + "\n" + first;
00221                     }
00222                     first = "";
00223                 }
00224             }
00225         }
00226 
00227         return result;
00228     }
00229 
00237     private final String format(double t) {
00238         return this.paddingString(TimIt.df.format(t),
00239                 this.padding, ' ', true)
00240                 + "s    ";
00241     }
00242 
00247     private String paddingString(String s, int n, char c, boolean paddingLeft) {
00248         StringBuffer str = new StringBuffer(s);
00249         int strLength = str.length();
00250         if (n > 0 && n > strLength) {
00251             for (int i = 0; i <= n; i++) {
00252                 if (paddingLeft) {
00253                     if (i < n - strLength) {
00254                         str.insert(0, c);
00255                     }
00256                 } else {
00257                     if (i > strLength) {
00258                         str.append(c);
00259                     }
00260                 }
00261             }
00262         }
00263         return str.toString();
00264     }
00265 }

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