1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.statistics
;
14 import org
.eclipse
.tracecompass
.segmentstore
.core
.BasicSegment
;
15 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
18 * Class to calculate simple segment store statistics (min, max, average)
20 * @author Bernd Hufmann
22 public class SegmentStoreStatistics
{
23 private ISegment fMin
;
24 private ISegment fMax
;
25 private long fNbSegments
;
26 private double fAverage
;
27 private double fVariance
;
28 private double fTotal
;
33 public SegmentStoreStatistics() {
34 fMin
= new BasicSegment(0, Long
.MAX_VALUE
);
35 fMax
= new BasicSegment(Long
.MIN_VALUE
, 0);
45 * @return minimum value
47 public long getMin() {
48 return fMin
.getLength();
54 * @return maximum value
56 public long getMax() {
57 return fMax
.getLength();
61 * Get segment with minimum length
63 * @return segment with minimum length
65 public ISegment
getMinSegment() {
70 * Get segment with maximum length
72 * @return segment with maximum length
74 public ISegment
getMaxSegment() {
79 * Get number of segments analyzed
81 * @return number of segments analyzed
83 public long getNbSegments() {
88 * Gets the arithmetic average
90 * @return arithmetic average
92 public double getAverage() {
97 * Gets the standard deviation of the segments, uses the online algorithm
99 * "https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm">
100 * Wikipedia article of dec 3 2015 </a>
102 * @return the standard deviation of the segment store, will return NaN if
103 * there are less than 3 elements
105 public double getStdDev() {
106 return fNbSegments
> 2 ? Math
.sqrt(fVariance
/ (fNbSegments
- 1)) : Double
.NaN
;
110 * Update the statistics based on a given segment
112 * This is an online algorithm and must retain a complexity of O(1)
115 * the segment used for the update
117 public void update(ISegment segment
) {
118 long value
= segment
.getLength();
120 * Min and max are trivial, as well as number of segments
122 long min
= fMin
.getLength();
123 long max
= fMax
.getLength();
124 fMin
= min
<= value ? fMin
: segment
;
125 fMax
= max
>= value ? fMax
: segment
;
129 * The running mean is not trivial, see proof in javadoc.
131 double delta
= value
- fAverage
;
132 fAverage
+= delta
/ fNbSegments
;
133 fVariance
+= delta
* (value
- fAverage
);
140 * @return total value
143 public double getTotal() {
This page took 0.049808 seconds and 6 git commands to generate.