01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.metric;
12:
13: /**
14: * A performance metric that is the difference of two other metrics.
15: * @keep-all
16: */
17: public class DifferenceMetric extends DerivedMetric {
18:
19: private Metric metricA;
20: private Metric metricB;
21: private final int defaultCalc;
22:
23: public DifferenceMetric(String name, String displayName,
24: String category, String descr, Metric[] args) {
25: this (name, displayName, category, descr, args[0], args[1],
26: args[0].getDefaultCalc(), args[0].getDecimals());
27: }
28:
29: public DifferenceMetric(String name, String displayName,
30: String category, String descr, Metric metricA,
31: Metric metricB, int defaultCalc, int decimals) {
32: super (name, displayName, category, descr, decimals);
33: this .metricA = metricA;
34: this .metricB = metricB;
35: this .defaultCalc = defaultCalc;
36: }
37:
38: /**
39: * How many arguments does this metric accept? Return 0 for any number
40: * of arguments.
41: */
42: public int getArgCount() {
43: return 2;
44: }
45:
46: /**
47: * Get the value of this metric for the given range of samples in the
48: * data set.
49: * @param dataSet The raw data
50: * @param firstSampleNo The first sample
51: * @param lastSampleNo The last sample (inclusive)
52: * @param calc The duration of the sample range in seconds
53: */
54: public double get(MetricDataSource dataSet, int firstSampleNo,
55: int lastSampleNo, int calc, double seconds) {
56: return metricA.get(dataSet, firstSampleNo, lastSampleNo, calc,
57: seconds)
58: - metricB.get(dataSet, firstSampleNo, lastSampleNo,
59: calc, seconds);
60: }
61:
62: /**
63: * What calculation method makes the most sense for this Metric.
64: */
65: public int getDefaultCalc() {
66: return defaultCalc;
67: }
68:
69: }
|