analysis: avoid division by 0 in latency statistics
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / latency / statistics / LatencyStatistics.java
CommitLineData
ce8319b6
BH
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
13
14import org.eclipse.tracecompass.segmentstore.core.ISegment;
15
16/**
17 * Class to calculate simple latency statistics (min, max, average)
18 *
19 * @author Bernd Hufmann
20 */
21public class LatencyStatistics {
22 private long fMin;
23 private long fMax;
24 private long fSum;
25 private long fNbSegments;
26
27 /**
28 * Constructor
29 */
30 public LatencyStatistics() {
31 this.fMin = Long.MAX_VALUE;
32 this.fMax = Long.MIN_VALUE;
33 this.fSum = 0;
34 this.fNbSegments = 0;
35 }
36
37 /**
38 * Get minimum value
39 *
40 * @return minimum value
41 */
42 public long getMin() {
43 return fMin;
44 }
45
46 /**
47 * Get maximum value
48 *
49 * @return maximum value
50 */
51 public long getMax() {
52 return fMax;
53 }
54
55 /**
56 * Get number of segments analyzed
57 *
58 * @return number of segments analyzed
59 */
60 public long getNbSegments() {
61 return fNbSegments;
62 }
63
64 /**
65 * Gets the arithmetic average
66 *
67 * @return arithmetic average
68 */
69 public double getAverage() {
70 return ((double) fSum) / fNbSegments;
71 }
72
73 /**
74 * Update the statistics based on a given segment
75 *
76 * @param segment
77 * the segment used for the update
78 */
79 public void update (ISegment segment) {
80 long value = segment.getLength();
81 fMin = Math.min(fMin, value);
82 fMax = Math.max(fMax, value);
83 fSum += value;
84 fNbSegments++;
85 }
86}
This page took 0.038261 seconds and 5 git commands to generate.