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