flamegraph: add min and max duration support to flamegraph statistics.
[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 import org.eclipse.tracecompass.segmentstore.core.ISegment;
15
16 /**
17 * Class to calculate statistics for an aggregated function.
18 *
19 * @author Sonia Farrah
20 */
21 public class AggregatedCalledFunctionStatistics extends SegmentStoreStatistics {
22
23 /**
24 * The maximum self time
25 */
26 private long fMaxSelfTime;
27 /**
28 * The minimum duration
29 */
30 private long fMinSelfTime;
31 /**
32 * The average self time
33 */
34 private double fSelfTimeAverage;
35 /**
36 * The variance of the self time
37 */
38 private double fVariance;
39 /**
40 * The segment with the longest duration
41 */
42 private ISegment fMaxSegment;
43 /**
44 * The segment with the shortest duration
45 */
46 private ISegment fMinSegment;
47
48 /**
49 * Constructor
50 *
51 * @param duration
52 * The function's duration
53 * @param selfTime
54 * The function's self time
55 */
56 public AggregatedCalledFunctionStatistics(ISegment duration, ISegment selfTime) {
57 fMaxSelfTime = selfTime.getLength();
58 fMinSelfTime = selfTime.getLength();
59 fSelfTimeAverage = selfTime.getLength();
60 fVariance = 0.0;
61 fMinSegment = duration;
62 fMaxSegment = duration;
63 update(duration);
64 }
65
66 /**
67 * Update the statistics, this is used while merging nodes for the
68 * aggregation tree.
69 *
70 * @param maxSegment
71 * The longest segment of the function to be merged
72 * @param minSegment
73 * The shortest segment of the function to be merged
74 * @param duration
75 * The function to be merged duration
76 * @param selfTime
77 * The function to be merged self time
78 */
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;
83 }
84 if (minSegment.getLength() < fMinSegment.getLength()) {
85 fMinSegment = minSegment;
86 }
87 if (fMaxSelfTime < selfTime) {
88 fMaxSelfTime = selfTime;
89 }
90 if (fMinSelfTime > selfTime) {
91 fMinSelfTime = selfTime;
92 }
93 double delta = selfTime - fSelfTimeAverage;
94 fSelfTimeAverage += delta / getNbSegments();
95 fVariance += delta * (selfTime - fSelfTimeAverage);
96 }
97
98 /**
99 * Get the maximum self time
100 *
101 * @return The maximum self time
102 */
103 public long getMaxSelfTime() {
104 return fMaxSelfTime;
105 }
106
107 /**
108 * Get the minimum self time
109 *
110 * @return The minimum self time
111 */
112 public long getMinSelfTime() {
113 return fMinSelfTime;
114 }
115
116 /**
117 * Get the average self time
118 *
119 * @return The average self time
120 */
121 public double getAverageSelfTime() {
122 return fSelfTimeAverage;
123 }
124
125 /**
126 * Get the standard deviation of the self time
127 *
128 * @return The standard deviation of the self time
129 */
130 public double getStdDevSelfTime() {
131 long nbSegments = getNbSegments();
132 return nbSegments > 2 ? Math.sqrt(fVariance / (nbSegments - 1)) : Double.NaN;
133 }
134
135 /**
136 * Initialize the maximum and minimum self time
137 *
138 * @param selfTime
139 * Self time
140 */
141 public void initializeMaxMinSelfTime(long selfTime) {
142 fMaxSelfTime = selfTime;
143 fMinSelfTime = selfTime;
144 fSelfTimeAverage = selfTime;
145 }
146
147 @Override
148 public ISegment getMaxSegment() {
149 return fMaxSegment;
150 }
151
152 @Override
153 public ISegment getMinSegment() {
154 return fMinSegment;
155 }
156 }
This page took 0.037039 seconds and 6 git commands to generate.