d15071eed36f1ef30363415cbd161c20faeec1c0
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / internal / analysis / timing / core / callgraph / AggregatedCalledFunctionStatistics.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.analysis.timing.core.callgraph;
11
12 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics;
13 import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
14
15 /**
16 * Class to calculate statistics for an aggregated function.
17 *
18 * @author Sonia Farrah
19 */
20 public class AggregatedCalledFunctionStatistics extends SegmentStoreStatistics {
21
22 /**
23 * The maximum self time
24 */
25 private long fMaxSelfTime;
26 /**
27 * The minimum duration
28 */
29 private long fMinSelfTime;
30 /**
31 * The average self time
32 */
33 private double fSelfTimeAverage;
34 /**
35 * The variance of the self time
36 */
37 private double fVariance;
38
39 /**
40 * Constructor
41 *
42 * @param duration
43 * The function's duration
44 * @param selfTime
45 * The function's self time
46 */
47 public AggregatedCalledFunctionStatistics(long duration, long selfTime) {
48 fMaxSelfTime = selfTime;
49 fMinSelfTime = selfTime;
50 fSelfTimeAverage = selfTime;
51 fVariance = 0.0;
52 update(new BasicSegment(0, duration));
53 }
54
55 /**
56 * Update the statistics, this is used while merging nodes for the
57 * aggregation tree.
58 *
59 * @param duration
60 * The function to be merged duration
61 * @param selfTime
62 * The function to be merged self time
63 */
64 public void update(long duration, long selfTime) {
65 update(new BasicSegment(0, duration));
66 if (fMaxSelfTime < selfTime) {
67 fMaxSelfTime = selfTime;
68 }
69 if (fMinSelfTime > selfTime) {
70 fMinSelfTime = selfTime;
71 }
72 double delta = selfTime - fSelfTimeAverage;
73 fSelfTimeAverage += delta / getNbSegments();
74 fVariance += delta * (selfTime - fSelfTimeAverage);
75 }
76
77 /**
78 * Get the maximum self time
79 *
80 * @return The maximum self time
81 */
82 public long getMaxSelfTime() {
83 return fMaxSelfTime;
84 }
85
86 /**
87 * Get the minimum self time
88 *
89 * @return The minimum self time
90 */
91 public long getMinSelfTime() {
92 return fMinSelfTime;
93 }
94
95 /**
96 * Get the average self time
97 *
98 * @return The average self time
99 */
100 public double getAverageSelfTime() {
101 return fSelfTimeAverage;
102 }
103
104 /**
105 * Get the standard deviation of the self time
106 *
107 * @return The standard deviation of the self time
108 */
109 public double getStdDevSelfTime() {
110 long nbSegments = getNbSegments();
111 return nbSegments > 2 ? Math.sqrt(fVariance / (nbSegments - 1)) : Double.NaN;
112 }
113
114 /**
115 * Initialize the maximum and minimum self time
116 *
117 * @param selfTime
118 * Self time
119 */
120 public void initializeMaxMinSelfTime(long selfTime) {
121 fMaxSelfTime = selfTime;
122 fMinSelfTime = selfTime;
123 fSelfTimeAverage = selfTime;
124 }
125 }
This page took 0.039736 seconds and 4 git commands to generate.