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 a / b expressed as a percentage.
15: * @keep-all
16: */
17: public class PercentageMetric extends DerivedMetric {
18:
19: private final Metric a;
20: private final Metric b;
21:
22: public PercentageMetric(String name, String displayName,
23: String category, String descr, Metric[] args) {
24: this (name, displayName, category, descr, args[0], args[1]);
25: }
26:
27: public PercentageMetric(String name, String displayName,
28: String category, String descr, Metric a, Metric b) {
29: super (name, displayName, category, descr, 1);
30: this .a = a;
31: this .b = b;
32: }
33:
34: /**
35: * How many arguments does this metric accept? Return 0 for any number
36: * of arguments.
37: */
38: public int getArgCount() {
39: return 2;
40: }
41:
42: /**
43: * Get the value of this metric for the given range of samples in the
44: * data set.
45: * @param dataSet The raw data
46: * @param firstSampleNo The first sample
47: * @param lastSampleNo The last sample (inclusive)
48: * @param calc The duration of the sample range in seconds
49: */
50: public double get(MetricDataSource dataSet, int firstSampleNo,
51: int lastSampleNo, int calc, double seconds) {
52: double b = this .b.get(dataSet, firstSampleNo, lastSampleNo,
53: calc, seconds);
54: if (b == 0.0)
55: return 0.0;
56: double a = this .a.get(dataSet, firstSampleNo, lastSampleNo,
57: calc, seconds);
58: return a * 100.0 / b;
59: }
60:
61: /**
62: * What calculation method makes the most sense for this Metric.
63: */
64: public int getDefaultCalc() {
65: return CALC_AVERAGE;
66: }
67:
68: }
|