MergeMetric.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.experiment.merge;
00002 
00003 import java.util.ArrayList;
00004 
00005 import edu.rice.cs.hpc.data.experiment.metric.BaseMetric;
00006 import edu.rice.cs.hpc.data.experiment.metric.MetricValue;
00007 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00008 
00009 /*****
00010  * 
00011  * information of two merged metrics 
00012  * 
00013  * the merge of two database cause the following changes:
00014  * - if the metrics are the same, it will be merged into one metric
00015  * - otherwise, the two metrics will be appended at the end 
00016  *      of list of metric in the new database 
00017  *
00018  */
00019 public class MergeMetric {
00020     int pointerMetric1[];
00021     int pointerMetric2[];
00022     int pointerCommon[];
00023     
00024     ArrayList<BaseMetric> metrics;
00025     
00026     /*****
00027      * compute the delta of two metric values
00028      *
00029      * @param target
00030      * @param source
00031      * @param offset : the index of the source v.a.v the target
00032      */
00033     static public void mergeMetrics(Scope target, Scope source, int offset[]) {
00034         
00035         for(int i=0; i<offset.length; i++) {
00036             MetricValue sourceValue = source.getMetricValue(i);
00037             MetricValue newValue = MetricValue.NONE;
00038             
00039             if (sourceValue != null && MetricValue.isAvailable(sourceValue)) {
00040                 newValue = new MetricValue();
00041                 MetricValue targetValue = target.getMetricValue(offset[i]);
00042                 float myValue = 0;
00043                 
00044                 if (targetValue != null && MetricValue.isAvailable(targetValue)) {
00045                     myValue = target.getMetricValue(offset[i]).getValue();
00046                 }
00047                 MetricValue.setValue(newValue, myValue - sourceValue.getValue());
00048                 target.setMetricValue(offset[i], newValue);
00049             }
00050             // make it uniform: annotation not available for all metrics
00051             MetricValue.setAnnotationAvailable(newValue, false);
00052         }
00053     }
00054     
00055     static public void setMetrics(Scope target, Scope source, int offset[], int factor) {
00056         
00057         for(int i=0; i<offset.length; i++) {
00058             MetricValue mv = source.getMetricValue(i);
00059             MetricValue mine = MetricValue.NONE;
00060             
00061             if (mv != null && MetricValue.isAvailable(mv)) {
00062                 mine = new MetricValue();
00063                 MetricValue myMV = target.getMetricValue(i);
00064                 float myValue = 0;
00065                 
00066                 if (myMV != null && MetricValue.isAvailable(myMV)) {
00067                     myValue = target.getMetricValue(i).getValue();
00068                     MetricValue.setValue(mine, myValue - mv.getValue());
00069                 } else {
00070                     MetricValue.setValue(mine, factor * mv.getValue());
00071                     float annValue = MetricValue.getAnnotationValue(mv);
00072                     MetricValue.setAnnotationValue(mine, annValue);
00073                 }
00074                 // we don't want to show percentage in the merged metric
00075                 MetricValue.setAnnotationAvailable(mine, false);
00076                 target.setMetricValue(i, mine);
00077             }
00078         }
00079     }
00080     
00081 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1