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.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
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
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 }