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
;
14 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
17 * Class to calculate statistics for an aggregated function.
19 * @author Sonia Farrah
21 public class AggregatedCalledFunctionStatistics
extends SegmentStoreStatistics
{
24 * The maximum self time
26 private long fMaxSelfTime
;
28 * The minimum duration
30 private long fMinSelfTime
;
32 * The average self time
34 private double fSelfTimeAverage
;
36 * The variance of the self time
38 private double fVariance
;
40 * The segment with the longest duration
42 private ISegment fMaxSegment
;
44 * The segment with the shortest duration
46 private ISegment fMinSegment
;
52 * The function's duration
54 * The function's self time
56 public AggregatedCalledFunctionStatistics(ISegment duration
, ISegment selfTime
) {
57 fMaxSelfTime
= selfTime
.getLength();
58 fMinSelfTime
= selfTime
.getLength();
59 fSelfTimeAverage
= selfTime
.getLength();
61 fMinSegment
= duration
;
62 fMaxSegment
= duration
;
67 * Update the statistics, this is used while merging nodes for the
71 * The longest segment of the function to be merged
73 * The shortest segment of the function to be merged
75 * The function to be merged duration
77 * The function to be merged self time
79 public void update(ISegment maxSegment
, ISegment minSegment
, long duration
, long selfTime
) {
80 update(new BasicSegment(0, duration
));
81 if (maxSegment
.getLength() > fMaxSegment
.getLength()) {
82 fMaxSegment
= maxSegment
;
84 if (minSegment
.getLength() < fMinSegment
.getLength()) {
85 fMinSegment
= minSegment
;
87 if (fMaxSelfTime
< selfTime
) {
88 fMaxSelfTime
= selfTime
;
90 if (fMinSelfTime
> selfTime
) {
91 fMinSelfTime
= selfTime
;
93 double delta
= selfTime
- fSelfTimeAverage
;
94 fSelfTimeAverage
+= delta
/ getNbSegments();
95 fVariance
+= delta
* (selfTime
- fSelfTimeAverage
);
99 * Get the maximum self time
101 * @return The maximum self time
103 public long getMaxSelfTime() {
108 * Get the minimum self time
110 * @return The minimum self time
112 public long getMinSelfTime() {
117 * Get the average self time
119 * @return The average self time
121 public double getAverageSelfTime() {
122 return fSelfTimeAverage
;
126 * Get the standard deviation of the self time
128 * @return The standard deviation of the self time
130 public double getStdDevSelfTime() {
131 long nbSegments
= getNbSegments();
132 return nbSegments
> 2 ? Math
.sqrt(fVariance
/ (nbSegments
- 1)) : Double
.NaN
;
136 * Initialize the maximum and minimum self time
141 public void initializeMaxMinSelfTime(long selfTime
) {
142 fMaxSelfTime
= selfTime
;
143 fMinSelfTime
= selfTime
;
144 fSelfTimeAverage
= selfTime
;
148 public ISegment
getMaxSegment() {
153 public ISegment
getMinSegment() {