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
.internal
.analysis
.timing
.core
.callgraph
;
12 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.statistics
.SegmentStoreStatistics
;
13 import org
.eclipse
.tracecompass
.segmentstore
.core
.BasicSegment
;
16 * Class to calculate statistics for an aggregated function.
18 * @author Sonia Farrah
20 public class AggregatedCalledFunctionStatistics
extends SegmentStoreStatistics
{
23 * The maximum self time
25 private long fMaxSelfTime
;
27 * The minimum duration
29 private long fMinSelfTime
;
31 * The average self time
33 private double fSelfTimeAverage
;
35 * The variance of the self time
37 private double fVariance
;
43 * The function's duration
45 * The function's self time
47 public AggregatedCalledFunctionStatistics(long duration
, long selfTime
) {
48 fMaxSelfTime
= selfTime
;
49 fMinSelfTime
= selfTime
;
51 update(new BasicSegment(0, duration
));
55 * Update the statistics, this is used while merging nodes for the
59 * The function to be merged duration
61 * The function to be merged self time
63 public void update(long duration
, long selfTime
) {
64 update(new BasicSegment(0, duration
));
65 if (fMaxSelfTime
< selfTime
) {
66 fMaxSelfTime
= selfTime
;
68 if (fMinSelfTime
> selfTime
) {
69 fMinSelfTime
= selfTime
;
71 double delta
= selfTime
- fSelfTimeAverage
;
72 fSelfTimeAverage
+= delta
/ getNbSegments();
73 fVariance
+= delta
* (selfTime
- fSelfTimeAverage
);
77 * Get the maximum self time
79 * @return The maximum self time
81 public long getMaxSelfTime() {
86 * Get the minimum self time
88 * @return The minimum self time
90 public long getMinSelfTime() {
95 * Get the average self time
97 * @return The average self time
99 public double getAverageSelfTime() {
100 return fSelfTimeAverage
;
104 * Get the standard deviation of the self time
106 * @return The standard deviation of the self time
108 public double getStdDevSelfTime() {
109 long nbSegments
= getNbSegments();
110 return nbSegments
> 2 ? Math
.sqrt(fVariance
/ (nbSegments
- 1)) : Double
.NaN
;
114 * Initialize the maximum and minimum self time
119 public void initializeMaxMinSelfTime(long selfTime
) {
120 fMaxSelfTime
= selfTime
;
121 fMinSelfTime
= selfTime
;
122 fSelfTimeAverage
= selfTime
;