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     // DATA
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     // partner of the metric. If the metric is exclusive, then its partner is the inclusive one
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     // CONSTRUCTOR
00052     //-------------------------------------------------------------------------------
00053 
00054 
00055     /*************************************************************************
00056      * 
00057      * @param sID: Unique ID of the metric
00058      * @param sDisplayName: the name of the title
00059      * @param displayed: will metric be displayed ?
00060      * @param format: format of the display
00061      * @param annotationType: show the percent or process number ?
00062      * @param index: index in the table
00063      *************************************************************************/
00064     public BaseMetric(String sID, String sDisplayName, boolean displayed, String format, 
00065             AnnotationType annotationType, int index, int partner_index, MetricType type) 
00066     {
00067         // in case of instantiation from duplicate() method, we need to make sure there is
00068         //  no double empty suffix
00069         if (sDisplayName.endsWith(EMPTY_SUFFIX))
00070             this.displayName = sDisplayName;
00071         else
00072             this.displayName = sDisplayName + EMPTY_SUFFIX; // johnmc - hack to leave enough room for ascending/descending triangle;
00073         
00074         this.displayed = displayed;
00075         this.annotationType = annotationType;
00076         this.index = index;
00077         this.partner_index = partner_index;
00078         
00079         // format
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     // METHODS
00100     //-------------------------------------------------------------------------------
00101     /*************************************************************************
00102      *  Sets the metric's index.
00103      ************************************************************************/
00104 
00105     public void setIndex(int index)
00106     {
00107         this.index = index;
00108     }
00109 
00110     /*************************************************************************
00111      *  Returns the metric's index.
00112      ************************************************************************/
00113 
00114     public int getIndex()
00115     {
00116         return this.index;
00117     }
00118 
00119     
00120     /*****
00121      * get the partner metric index
00122      * @return
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     //      ACCESS TO METRIC
00137     //=================================================================================
00138 
00139     /*************************************************************************
00140      *  Returns the metric's short (internal) name.
00141      ************************************************************************/
00142     public String getShortName()
00143     {
00144         return this.shortName;
00145     }
00146 
00147     /*************************************************************************
00148      * 
00149      * @param newName
00150      *************************************************************************/
00151     public void setShortName(String newName)
00152     {
00153         this.shortName = newName;
00154     }
00155 
00156     /*************************************************************************
00157      *  Returns the metric's native (target OS toolset) name.
00158      ************************************************************************/
00159     public String getNativeName()
00160     {
00161         return this.nativeName;
00162     }
00163 
00164     /*************************************************************************
00165      *  Returns the metric's user-visible name.
00166      ************************************************************************/
00167     public String getDisplayName()
00168     {
00169         return this.displayName;
00170     }   
00171 
00172     /*************************************************************************
00173      * set the new display name
00174      * @param name
00175      *************************************************************************/
00176     public void setDisplayName(String name)
00177     {
00178         displayName = name;
00179     }   
00180 
00181     /*************************************************************************
00182      *  Returns whether the metric should be displayed.
00183      ************************************************************************/  
00184     public boolean getDisplayed()
00185     {
00186         return this.displayed;
00187     }
00188 
00189     /*************************************************************************
00190      * Set display flag (true=to be displayed)
00191      * @param d, the flag
00192      *************************************************************************/
00193     public void setDisplayed(boolean d)
00194     {
00195         this.displayed = d;
00196     }
00197 
00198     /*************************************************************************
00199      *  Returns the type of annotation a metric's display should include (percent, process number, others ??).
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      * Return the text to display based on the metric value
00223      * @param mv: the value of a metric
00224      *************************************************************************/
00225     public String getMetricTextValue(MetricValue mv_) {
00226         String sText;
00227         MetricValue mv = mv_;
00228         
00229         // enforce bounds for presentation
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         // if not a special case, convert the number to a string
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      * Sets the metric's display format.
00248      * @param format
00249      *************************************************************************/
00250     public void setDisplayFormat( IMetricValueFormat format )
00251     {
00252         this.displayFormat = format;
00253     }
00254 
00255     /*************************************************************************
00256      *  Returns the metric's display format.
00257      ************************************************************************/
00258     public IMetricValueFormat getDisplayFormat()
00259     {
00260         return this.displayFormat;
00261     }
00262     
00263     /*************************************************************************
00264      *  MISC
00265      ************************************************************************/
00266     public MetricType getMetricType()
00267     {
00268         return this.metricType;
00269     }
00270 
00271     /*************************************************************************
00272      * 
00273      * @param objType
00274      *************************************************************************/
00275     public void setMetricType( MetricType objType ) 
00276     {
00277         this.metricType = objType;
00278     }
00279     /*************************************************************************
00280      * Laks: need an interface to update the sample period due to change in DTD
00281      * @param s
00282      *************************************************************************/
00283     public void setSamplePeriod(String s) {
00284         this.sampleperiod = this.convertSamplePeriode(s);
00285     }
00286 
00287     /*************************************************************************
00288      * 
00289      * @param sUnit
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      * Return the sample period
00299      * @return
00300      *************************************************************************/
00301     public double getSamplePeriod()
00302     {
00303         return this.sampleperiod;
00304     }
00305 
00306     //=================================================================================
00307     //      ABSTRACT METHODS
00308     //=================================================================================
00309     /*************************************************************************
00310      * method to return the value of a given scope. To be implemented by derived class.
00311      * @param s
00312      * @return
00313      *************************************************************************/
00314     abstract public MetricValue getValue(Scope s);
00315 
00316     /***
00317      * Method to duplicate itself (cloning)
00318      * @return
00319      */
00320     abstract public BaseMetric duplicate();
00321 
00322 
00323     //=================================================================================
00324     //      UTILITY METHODS
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 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1