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 import org.objectweb.proactive.benchmarks.timit.TimIt;
00035 import org.objectweb.proactive.benchmarks.timit.util.observing.EventDataBag;
00036
00043 public class EventStatistics implements Serializable {
00047 private static final long serialVersionUID = 3762604865283613499L;
00048
00049 private String[] counterName;
00050
00051 private Object[] value;
00052
00053 private EventDataBag statDataBag;
00054
00055 private int nb;
00056
00057 private int padding;
00058
00059 private boolean empty;
00060
00061 public EventStatistics() {
00062 this(new String[1], new Object[1], 0, null);
00063 this.empty = true;
00064 }
00065
00066 public EventStatistics(String[] counterName, Object[] value, int nb,
00067 EventDataBag statDataBag) {
00068 this.counterName = counterName.clone();
00069 this.value = value.clone();
00070 this.statDataBag = statDataBag;
00071 this.nb = nb;
00072 this.empty = false;
00073 }
00074
00075 public Object getEventValue(int i) {
00076 return this.value[i];
00077 }
00078
00079 public Object getEventValue(String name) {
00080 for (int i = 0; i < this.counterName.length; i++) {
00081 if (name.equals(this.counterName[i])) {
00082 return this.value[i];
00083 }
00084 }
00085 return null;
00086 }
00087
00088 public Object getEventDataValue(String name) {
00089 for (int i = 0; i < this.counterName.length; i++) {
00090 if (name.equals(this.counterName[i])) {
00091 return this.statDataBag.getEventData(i).getFinalized();
00092 }
00093 }
00094 return null;
00095 }
00096
00097 public String getFormValue(int i) {
00098 return TimIt.df.format(this.value[i]);
00099 }
00100
00101 public String getName(int i) {
00102 return this.counterName[i];
00103 }
00104
00105 public EventDataBag getStatDataBag() {
00106 return this.statDataBag;
00107 }
00108
00109 public int getNb() {
00110 return this.nb;
00111 }
00112
00113 public void setTimerName(int id, String name) {
00114 this.counterName[id] = name;
00115 }
00116
00117 public String toString() {
00118 if (!this.empty) {
00119 return this.show();
00120 }
00121 return "";
00122 }
00123
00124 public String show() {
00125 String result = "";
00126
00127 for (int i = 0; i < this.nb; i++) {
00128 result += this.counterName[i] + " : " + this.value[i] + "\n";
00129 }
00130
00131 return result;
00132 }
00133
00134 public final String format(double t) {
00135 return this.paddingString(TimIt.df.format(t), this.padding,
00136 ' ', true)
00137 + " ";
00138 }
00139
00144 private String paddingString(String s, int n, char c, boolean paddingLeft) {
00145 StringBuffer str = new StringBuffer(s);
00146 int strLength = str.length();
00147 if (n > 0 && n > strLength) {
00148 for (int i = 0; i <= n; i++) {
00149 if (paddingLeft) {
00150 if (i < n - strLength) {
00151 str.insert(0, c);
00152 }
00153 } else {
00154 if (i > strLength) {
00155 str.append(c);
00156 }
00157 }
00158 }
00159 }
00160 return str.toString();
00161 }
00162 }