1 | package de.uka.ipd.sdq.probespec.framework.calculator; |
2 | |
3 | import java.util.Vector; |
4 | |
5 | import javax.measure.unit.SI; |
6 | |
7 | import de.uka.ipd.sdq.pipesandfilters.framework.CaptureType; |
8 | import de.uka.ipd.sdq.pipesandfilters.framework.MeasurementMetric; |
9 | import de.uka.ipd.sdq.pipesandfilters.framework.Scale; |
10 | import de.uka.ipd.sdq.probespec.framework.ProbeSpecContext; |
11 | |
12 | /** |
13 | * Calculates a time span representing the waiting time. |
14 | * |
15 | * @author Faber, Philipp Merkle |
16 | * @see UnaryCalculator |
17 | * @see Calculator |
18 | */ |
19 | public class WaitingTimeCalculator extends TimeSpanCalculator { |
20 | |
21 | private static Vector<MeasurementMetric> concreteMeasurementMetrics; |
22 | |
23 | /** |
24 | * Default Constructor. |
25 | * |
26 | * @param ctx |
27 | * the {@link ProbeSpecContext} |
28 | * @param startWaitingProbeSetID |
29 | * references the ProbeSet which represents the starting point |
30 | * for the waiting time measurement |
31 | * @param stopWaitingProbeSetID |
32 | * references the ProbeSet which represents the final point for |
33 | * the waiting time measurement |
34 | */ |
35 | public WaitingTimeCalculator(ProbeSpecContext ctx, Integer startWaitingProbeSetID, Integer stopWaitingProbeSetID) { |
36 | super(ctx, startWaitingProbeSetID, stopWaitingProbeSetID); |
37 | } |
38 | |
39 | // @SuppressWarnings("unchecked") |
40 | // @Override |
41 | // protected Vector<Measure<?, ? extends Quantity>> calculate( |
42 | // ProbeSetSample sample) throws CalculatorException { |
43 | // // Obtain measured resource response time |
44 | // IMatchRule[] rules = new IMatchRule[1]; |
45 | // rules[0] = new ProbeTypeMatchRule(ProbeType.CPU_RESPONSE_TIME); |
46 | // Vector<ProbeSample<?, ? extends Quantity>> result = sample |
47 | // .getProbeSamples(rules); |
48 | // ProbeSample<Double, Duration> responseTimeSample = null; |
49 | // double responseTime = -1; |
50 | // if (result != null && result.size() > 0) { |
51 | // responseTimeSample = (ProbeSample<Double, Duration>) result.get(0); |
52 | // responseTime = responseTimeSample.getMeasure().doubleValue( |
53 | // responseTimeSample.getMeasure().getUnit()); |
54 | // } |
55 | // |
56 | // // Obtain measured demand |
57 | // rules[0] = new ProbeTypeMatchRule(ProbeType.CPU_RESOURCE_DEMAND); |
58 | // result = sample.getProbeSamples(rules); |
59 | // ProbeSample<Double, Duration> demandSample = null; |
60 | // double demand = -1; |
61 | // if (result != null && result.size() > 0) { |
62 | // demandSample = (ProbeSample<Double, Duration>) result.get(0); |
63 | // demand = demandSample.getMeasure().doubleValue( |
64 | // responseTimeSample.getMeasure().getUnit()); |
65 | // } |
66 | // |
67 | // if (responseTimeSample != null && demandSample != null) { |
68 | // // Create result tuple |
69 | // double waitTime = responseTime - demand; |
70 | // |
71 | // Measure<Double, Duration> waitTimeMeasure = Measure.valueOf( |
72 | // waitTime, responseTimeSample.getMeasure().getUnit()); |
73 | // Vector<Measure<?, ? extends Quantity>> resultTuple = new |
74 | // Vector<Measure<?, ? extends Quantity>>(); |
75 | // resultTuple.add(waitTimeMeasure); |
76 | // |
77 | // return resultTuple; |
78 | // } else { |
79 | // throw new CalculatorException( |
80 | // "Could not access all needed probe samples."); |
81 | // } |
82 | // } |
83 | |
84 | /** |
85 | * Initializes the metric information for the result of this calculator |
86 | * type. The method is called by the constructor of the super class. |
87 | */ |
88 | @Override |
89 | protected synchronized Vector<MeasurementMetric> getConcreteMeasurementMetrics() { |
90 | if (concreteMeasurementMetrics == null) { |
91 | concreteMeasurementMetrics = new Vector<MeasurementMetric>(); |
92 | MeasurementMetric mm = new MeasurementMetric( |
93 | CaptureType.NATURAL_NUMBER, SI.MILLI(SI.SECOND), |
94 | Scale.ORDINAL); |
95 | mm.setDescription("This measure represents the waiting time"); |
96 | mm.setMonotonic(false); |
97 | mm.setName("Waiting Time"); |
98 | mm.setStrongMonotonic(false); |
99 | concreteMeasurementMetrics.add(mm); |
100 | } |
101 | return concreteMeasurementMetrics; |
102 | } |
103 | |
104 | } |