1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.timing
.core
.tests
.segmentstore
.statistics
;
12 import java
.util
.Collection
;
14 import org
.eclipse
.jdt
.annotation
.NonNull
;
15 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
.SystemCall
;
16 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
19 * This calculates the statistics of a segment store in an offline manner to
20 * validate online calculations.
22 * @author Matthew Khouzam
25 public class OfflineStatisticsCalculator
{
26 private final Collection
<@NonNull SystemCall
> fSs
;
32 * segment store, fully build
34 public OfflineStatisticsCalculator(Collection
<@NonNull SystemCall
> ss
) {
41 * @return the max value
43 public long getMax() {
44 long max
= Long
.MIN_VALUE
;
45 for (ISegment interval
: fSs
) {
46 max
= Math
.max(max
, interval
.getLength());
54 * @return the min value
56 public long getMin() {
57 long min
= Long
.MAX_VALUE
;
58 for (ISegment interval
: fSs
) {
59 min
= Math
.min(min
, interval
.getLength());
65 * Get the average value
67 * @return the average value
69 public double getAvg() {
71 for (ISegment interval
: fSs
) {
72 total
+= (double) interval
.getLength() / (double) fSs
.size();
78 * Get the standard deviation for a window.
80 * @return the standard deviation
82 public double getStdDev() {
86 double mean
= getAvg();
88 double totalVariance
= 0;
89 for (ISegment interval
: fSs
) {
90 double result
= interval
.getLength() - mean
;
91 totalVariance
+= result
* result
/ (fSs
.size() - 1);
93 return Math
.sqrt(totalVariance
);