BaseMetric.java
Go to the documentation of this file.00001
00004 package edu.rice.cs.hpc.data.experiment.metric;
00005
00006 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00007
00012 public abstract class BaseMetric {
00013
00014
00015
00016
00018 public enum AnnotationType { NONE, PERCENT, PROCESS };
00019
00021 protected String shortName;
00022
00024 protected String nativeName;
00025
00027 protected String displayName;
00028
00030 protected boolean displayed;
00031
00033 protected AnnotationType annotationType = AnnotationType.NONE;
00034
00036 protected int index;
00037
00038 protected int partner_index;
00039
00041 protected IMetricValueFormat displayFormat;
00042
00043 protected MetricType metricType;
00044
00045 protected double sampleperiod;
00046
00047 private char unit;
00048
00049 final private String EMPTY_SUFFIX = " ";
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 public BaseMetric(String sID, String sDisplayName, boolean displayed, String format,
00065 AnnotationType annotationType, int index, int partner_index, MetricType type)
00066 {
00067
00068
00069 if (sDisplayName.endsWith(EMPTY_SUFFIX))
00070 this.displayName = sDisplayName;
00071 else
00072 this.displayName = sDisplayName + EMPTY_SUFFIX;
00073
00074 this.displayed = displayed;
00075 this.annotationType = annotationType;
00076 this.index = index;
00077 this.partner_index = partner_index;
00078
00079
00080 if (format == null) {
00081 if (annotationType == AnnotationType.PERCENT) {
00082 this.displayFormat = new MetricValueFormat(true, MetricValueFormat.FLOAT, 8, 2, true, MetricValueFormat.FIXED, 5, 1, "#0.0%", 1);
00083 } else if (annotationType == AnnotationType.PROCESS) {
00084 this.displayFormat = new MetricValueFormat(true, MetricValueFormat.FLOAT, 8, 2, true, MetricValueFormat.FIXED, 5, 0, "<0>", 1);
00085 } else {
00086 this.displayFormat = new MetricValueFormat(true, MetricValueFormat.FLOAT, 8, 2, false, 0, 0, 0, null, 1);
00087 }
00088 } else {
00089 this.displayFormat = new MetricValuePredefinedFormat(format);
00090 }
00091
00092 this.unit = '0';
00093 this.shortName = sID;
00094
00095 this.metricType = type;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105 public void setIndex(int index)
00106 {
00107 this.index = index;
00108 }
00109
00110
00111
00112
00113
00114 public int getIndex()
00115 {
00116 return this.index;
00117 }
00118
00119
00120
00121
00122
00123
00124 public int getPartner() {
00125 return partner_index;
00126 }
00127
00128
00129 public void setPartner(int ei)
00130 {
00131 this.partner_index = ei;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 public String getShortName()
00143 {
00144 return this.shortName;
00145 }
00146
00147
00148
00149
00150
00151 public void setShortName(String newName)
00152 {
00153 this.shortName = newName;
00154 }
00155
00156
00157
00158
00159 public String getNativeName()
00160 {
00161 return this.nativeName;
00162 }
00163
00164
00165
00166
00167 public String getDisplayName()
00168 {
00169 return this.displayName;
00170 }
00171
00172
00173
00174
00175
00176 public void setDisplayName(String name)
00177 {
00178 displayName = name;
00179 }
00180
00181
00182
00183
00184 public boolean getDisplayed()
00185 {
00186 return this.displayed;
00187 }
00188
00189
00190
00191
00192
00193 public void setDisplayed(boolean d)
00194 {
00195 this.displayed = d;
00196 }
00197
00198
00199
00200
00201 public AnnotationType getAnnotationType()
00202 {
00203 return this.annotationType;
00204 }
00205
00206 public void setAnnotationType( AnnotationType annType )
00207 {
00208 annotationType = annType;
00209 }
00210
00216 public String getMetricTextValue(Scope scope) {
00217 MetricValue mv = this.getValue(scope);
00218 return this.getMetricTextValue(mv);
00219 }
00220
00221
00222
00223
00224
00225 public String getMetricTextValue(MetricValue mv_) {
00226 String sText;
00227 MetricValue mv = mv_;
00228
00229
00230 if (mv.value > 9.99e99) mv.value = Float.POSITIVE_INFINITY;
00231 else if (mv.value < -9.99e99) mv.value = Float.NEGATIVE_INFINITY;
00232 else if (Math.abs(mv.value) < 1.00e-99) mv.value = (float) 0.0;
00233
00234
00235 if (mv.value == 0.0 || mv == MetricValue.NONE || !MetricValue.isAvailable(mv) ) sText = "";
00236 else if (mv.value == Float.POSITIVE_INFINITY) sText = "Infinity";
00237 else if (mv.value == Float.NEGATIVE_INFINITY) sText = "-Infinity";
00238 else if (Float.isNaN(mv.value)) sText = "NaN";
00239 else {
00240 sText = getDisplayFormat().format(mv);
00241 }
00242
00243 return sText;
00244 }
00245
00246
00247
00248
00249
00250 public void setDisplayFormat( IMetricValueFormat format )
00251 {
00252 this.displayFormat = format;
00253 }
00254
00255
00256
00257
00258 public IMetricValueFormat getDisplayFormat()
00259 {
00260 return this.displayFormat;
00261 }
00262
00263
00264
00265
00266 public MetricType getMetricType()
00267 {
00268 return this.metricType;
00269 }
00270
00271
00272
00273
00274
00275 public void setMetricType( MetricType objType )
00276 {
00277 this.metricType = objType;
00278 }
00279
00280
00281
00282
00283 public void setSamplePeriod(String s) {
00284 this.sampleperiod = this.convertSamplePeriode(s);
00285 }
00286
00287
00288
00289
00290
00291 public void setUnit (String sUnit) {
00292 this.unit = sUnit.charAt(0);
00293 if (this.isUnitEvent())
00294 this.sampleperiod = 1.0;
00295 }
00296
00297
00298
00299
00300
00301 public double getSamplePeriod()
00302 {
00303 return this.sampleperiod;
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 abstract public MetricValue getValue(Scope s);
00315
00316
00317
00318
00319
00320 abstract public BaseMetric duplicate();
00321
00322
00323
00324
00325
00326
00331 private boolean isUnitEvent() {
00332 return this.unit == 'e';
00333 }
00334
00340 protected double convertSamplePeriode( String sPeriod ) {
00341 if (this.isUnitEvent())
00342 return 1.0;
00343
00344 double period = 1.0;
00345 if (sPeriod != null && sPeriod.length()>0) {
00346 try {
00347 period = Double.parseDouble(sPeriod);
00348 } catch (java.lang.NumberFormatException e) {
00349 System.err.println("The sample period is incorrect :" + sPeriod);
00350 }
00351 }
00352 return period;
00353 }
00354
00355 }