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 state of a resource (second tuple |
24 | * element). It needs one ProbeSet containing at least a CURRENT_TIME probe and |
25 | * an {@link ProbeType#RESOURCE_STATE} probe. |
26 | * |
27 | * @author Faber, Philipp Merkle |
28 | * |
29 | */ |
30 | public class StateCalculator extends UnaryCalculator { |
31 | |
32 | private static Vector<MeasurementMetric> concreteMeasurementMetrics; |
33 | |
34 | /** |
35 | * Constructor. It takes a reference of the blackboard and the ID of the probe set element taken |
36 | * 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 StateCalculator(ProbeSpecContext ctx, Integer probeSetID) { |
44 | super(ctx, probeSetID); |
45 | } |
46 | |
47 | @Override |
48 | protected Vector<Measure<?, ? extends Quantity>> calculate( |
49 | ProbeSetSample sample) throws CalculatorException { |
50 | // Obtain measuring time |
51 | IMatchRule[] rules = new IMatchRule[1]; |
52 | rules[0] = new ProbeTypeMatchRule(ProbeType.CURRENT_TIME); |
53 | Vector<ProbeSample<?, ? extends Quantity>> result = sample |
54 | .getProbeSamples(rules); |
55 | ProbeSample<?, ? extends Quantity> time = null; |
56 | if (result != null && result.size() > 0) |
57 | time = result.get(0); |
58 | |
59 | // Obtain measured state |
60 | rules[0] = new ProbeTypeMatchRule(ProbeType.RESOURCE_STATE); |
61 | result = sample.getProbeSamples(rules); |
62 | ProbeSample<?, ? extends Quantity> resourceState = null; |
63 | if (result != null && result.size() > 0) |
64 | resourceState = result.get(0); |
65 | |
66 | if (time != null && resourceState != null) { |
67 | // Create result tuple |
68 | Vector<Measure<?, ? extends Quantity>> resultTuple = new Vector<Measure<?, ? extends Quantity>>(); |
69 | resultTuple.add(time.getMeasure()); |
70 | resultTuple.add(resourceState.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 meausre 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 state of the CPU resource"); |
102 | mm.setMonotonic(false); |
103 | mm.setName("State of the CPU resource"); |
104 | mm.setStrongMonotonic(false); |
105 | concreteMeasurementMetrics.add(mm); |
106 | } |
107 | return concreteMeasurementMetrics; |
108 | } |
109 | |
110 | } |