| 1 | package de.uka.ipd.sdq.probespec.framework.calculator; |
| 2 | |
| 3 | import java.util.Vector; |
| 4 | |
| 5 | import javax.measure.Measure; |
| 6 | import javax.measure.quantity.Dimensionless; |
| 7 | import javax.measure.quantity.Quantity; |
| 8 | import javax.measure.unit.SI; |
| 9 | |
| 10 | import de.uka.ipd.sdq.pipesandfilters.framework.CaptureType; |
| 11 | import de.uka.ipd.sdq.pipesandfilters.framework.MeasurementMetric; |
| 12 | import de.uka.ipd.sdq.pipesandfilters.framework.Scale; |
| 13 | import de.uka.ipd.sdq.probespec.framework.ProbeSample; |
| 14 | import de.uka.ipd.sdq.probespec.framework.ProbeSetSample; |
| 15 | import de.uka.ipd.sdq.probespec.framework.ProbeSpecContext; |
| 16 | import de.uka.ipd.sdq.probespec.framework.ProbeType; |
| 17 | import de.uka.ipd.sdq.probespec.framework.exceptions.CalculatorException; |
| 18 | import de.uka.ipd.sdq.probespec.framework.matching.IMatchRule; |
| 19 | import de.uka.ipd.sdq.probespec.framework.matching.ProbeTypeMatchRule; |
| 20 | |
| 21 | /** |
| 22 | * This class is a specific Calculator which composes a 2-tuple containing a |
| 23 | * time stamp (first tuple element) and the CPU demand of an entity (second |
| 24 | * tuple element). It needs one ProbeSet containing at least a CURRENT_TIME |
| 25 | * probe and an CPU_RESOURCE_DEMAND probe. |
| 26 | * |
| 27 | * @author Faber, Philipp Merkle |
| 28 | * |
| 29 | */ |
| 30 | public class DemandCalculator extends UnaryCalculator { |
| 31 | |
| 32 | private static Vector<MeasurementMetric> concreteMeasurementMetrics; |
| 33 | |
| 34 | /** |
| 35 | * Constructor for the CPUDemandCalculator. It takes a reference of the blackboard and the ID of |
| 36 | * the probe set element taken from the model. |
| 37 | * |
| 38 | * @param ctx |
| 39 | * the {@link ProbeSpecContext} |
| 40 | * @param probeSetID |
| 41 | * ID of the probe set element from the model |
| 42 | */ |
| 43 | public DemandCalculator(ProbeSpecContext ctx, Integer probeSetID) { |
| 44 | super(ctx, probeSetID); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public Vector<Measure<?, ? extends Quantity>> calculate( |
| 49 | ProbeSetSample sample) throws CalculatorException { |
| 50 | // Obtain measurement time |
| 51 | ProbeSample<?, ? extends Quantity> measurementTime = null; |
| 52 | IMatchRule[] rules = new IMatchRule[1]; |
| 53 | rules[0] = new ProbeTypeMatchRule(ProbeType.CURRENT_TIME); |
| 54 | Vector<ProbeSample<?, ? extends Quantity>> result = sample |
| 55 | .getProbeSamples(rules); |
| 56 | if (result != null && result.size() > 0) |
| 57 | measurementTime = result.get(0); |
| 58 | |
| 59 | // Obtain demand |
| 60 | ProbeSample<?, ? extends Quantity> demand = null; |
| 61 | rules[0] = new ProbeTypeMatchRule(ProbeType.RESOURCE_DEMAND); |
| 62 | result = sample.getProbeSamples(rules); |
| 63 | if (result != null && result.size() > 0) |
| 64 | demand = result.get(0); |
| 65 | |
| 66 | if (measurementTime != null && demand != null) { |
| 67 | Vector<Measure<?, ? extends Quantity>> resultTuple = new Vector<Measure<?, ? extends Quantity>>(); |
| 68 | |
| 69 | resultTuple.add(measurementTime.getMeasure()); |
| 70 | resultTuple.add(demand.getMeasure()); |
| 71 | |
| 72 | return resultTuple; |
| 73 | } else { |
| 74 | throw new CalculatorException( |
| 75 | "Could not access all needed probe samples."); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Initializes the metric information for the result of this calculator |
| 82 | * type. The method is called by the constructor of the super class. |
| 83 | */ |
| 84 | @Override |
| 85 | protected synchronized Vector<MeasurementMetric> getConcreteMeasurementMetrics() { |
| 86 | if (concreteMeasurementMetrics == null) { |
| 87 | concreteMeasurementMetrics = new Vector<MeasurementMetric>(); |
| 88 | MeasurementMetric mm = new MeasurementMetric( |
| 89 | CaptureType.NATURAL_NUMBER, SI.MILLI(SI.SECOND), |
| 90 | Scale.ORDINAL); |
| 91 | mm |
| 92 | .setDescription("This measure represents the point of time when the value is taken"); |
| 93 | mm.setMonotonic(false); |
| 94 | mm.setName("Point of time"); |
| 95 | mm.setStrongMonotonic(false); |
| 96 | concreteMeasurementMetrics.add(mm); |
| 97 | |
| 98 | mm = new MeasurementMetric(CaptureType.NATURAL_NUMBER, |
| 99 | Dimensionless.UNIT, Scale.ORDINAL); |
| 100 | mm |
| 101 | .setDescription("This measure represents the CPU demand of the entity"); |
| 102 | mm.setMonotonic(false); |
| 103 | mm.setName("CPU demand of the entity"); |
| 104 | mm.setStrongMonotonic(false); |
| 105 | concreteMeasurementMetrics.add(mm); |
| 106 | } |
| 107 | return concreteMeasurementMetrics; |
| 108 | } |
| 109 | |
| 110 | } |