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 an execution result (second tuple |
24 | * element). It needs one ProbeSet containing at least a CURRENT_TIME probe and |
25 | * an {@link ProbeType#EXECUTION_RESULT} probe. |
26 | * |
27 | * @author brosch |
28 | * |
29 | */ |
30 | public class ExecutionResultCalculator extends UnaryCalculator { |
31 | |
32 | /** |
33 | * Stores the metrics so that they are created only once. |
34 | */ |
35 | private static Vector<MeasurementMetric> concreteMeasurementMetrics; |
36 | |
37 | /** |
38 | * Constructor. It takes a reference of the blackboard and the ID of the probe set element taken |
39 | * from the model. |
40 | * |
41 | * @param ctx |
42 | * the {@link ProbeSpecContext} |
43 | * @param probeSetID |
44 | * ID of the probe set element from the model |
45 | */ |
46 | public ExecutionResultCalculator(ProbeSpecContext ctx, Integer probeSetID) { |
47 | super(ctx, probeSetID); |
48 | } |
49 | |
50 | /* |
51 | * (non-Javadoc) |
52 | * |
53 | * @see |
54 | * de.uka.ipd.sdq.probespec.framework.calculator.UnaryCalculator#calculate |
55 | * (de.uka.ipd.sdq.probespec.framework.ProbeSetSample) |
56 | */ |
57 | @Override |
58 | protected Vector<Measure<?, ? extends Quantity>> calculate( |
59 | ProbeSetSample sample) throws CalculatorException { |
60 | |
61 | // Obtain measured time: |
62 | IMatchRule[] rules = new IMatchRule[1]; |
63 | rules[0] = new ProbeTypeMatchRule(ProbeType.CURRENT_TIME); |
64 | Vector<ProbeSample<?, ? extends Quantity>> result = sample |
65 | .getProbeSamples(rules); |
66 | ProbeSample<?, ? extends Quantity> time = null; |
67 | if (result != null && result.size() > 0) { |
68 | time = result.get(0); |
69 | } |
70 | |
71 | // Obtain measured state: |
72 | rules[0] = new ProbeTypeMatchRule(ProbeType.EXECUTION_RESULT); |
73 | result = sample.getProbeSamples(rules); |
74 | ProbeSample<?, ? extends Quantity> executionResult = null; |
75 | if (result != null && result.size() > 0) { |
76 | executionResult = result.get(0); |
77 | } |
78 | |
79 | // Build the result Vector: |
80 | if (time != null && executionResult != null) { |
81 | // Create result tuple |
82 | Vector<Measure<?, ? extends Quantity>> resultTuple = new Vector<Measure<?, ? extends Quantity>>(); |
83 | resultTuple.add(time.getMeasure()); |
84 | resultTuple.add(executionResult.getMeasure()); |
85 | return resultTuple; |
86 | } else { |
87 | throw new CalculatorException( |
88 | "Could not access all needed probe samples."); |
89 | } |
90 | |
91 | } |
92 | |
93 | /** |
94 | * Initializes the metric information for the result of this calculator |
95 | * type. The method is called by the constructor of the super class. |
96 | */ |
97 | @Override |
98 | protected synchronized Vector<MeasurementMetric> getConcreteMeasurementMetrics() { |
99 | if (concreteMeasurementMetrics == null) { |
100 | concreteMeasurementMetrics = new Vector<MeasurementMetric>(); |
101 | MeasurementMetric mm = new MeasurementMetric( |
102 | CaptureType.NATURAL_NUMBER, SI.MILLI(SI.SECOND), |
103 | Scale.ORDINAL); |
104 | mm |
105 | .setDescription("This measure represents the point of time when the value is taken"); |
106 | mm.setMonotonic(false); |
107 | mm.setName("Point of time"); |
108 | mm.setStrongMonotonic(false); |
109 | concreteMeasurementMetrics.add(mm); |
110 | |
111 | mm = new MeasurementMetric(CaptureType.NATURAL_NUMBER, |
112 | Dimensionless.UNIT, Scale.ORDINAL); |
113 | mm |
114 | .setDescription("This measure represents the type of execution result"); |
115 | mm.setMonotonic(false); |
116 | mm.setName("Type of execution result"); |
117 | mm.setStrongMonotonic(false); |
118 | concreteMeasurementMetrics.add(mm); |
119 | } |
120 | return concreteMeasurementMetrics; |
121 | } |
122 | } |