bea37a3a7f72bfbfec6bf5ce64001f79e4f3382b
[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 fVariance = 0.0;
51 update(new BasicSegment(0, duration));
52 }
53
54 /**
55 * Update the statistics, this is used while merging nodes for the
56 * aggregation tree.
57 *
58 * @param duration
59 * The function to be merged duration
60 * @param selfTime
61 * The function to be merged self time
62 */
63 public void update(long duration, long selfTime) {
64 update(new BasicSegment(0, duration));
65 if (fMaxSelfTime < selfTime) {
66 fMaxSelfTime = selfTime;
67 }
68 if (fMinSelfTime > selfTime) {
69 fMinSelfTime = selfTime;
70 }
71 double delta = selfTime - fSelfTimeAverage;
72 fSelfTimeAverage += delta / getNbSegments();
73 fVariance += delta * (selfTime - fSelfTimeAverage);
74 }
75
76 /**
77 * Get the maximum self time
78 *
79 * @return The maximum self time
80 */
81 public long getMaxSelfTime() {
82 return fMaxSelfTime;
83 }
84
85 /**
86 * Get the minimum self time
87 *
88 * @return The minimum self time
89 */
90 public long getMinSelfTime() {
91 return fMinSelfTime;
92 }
93
94 /**
95 * Get the average self time
96 *
97 * @return The average self time
98 */
99 public double getAverageSelfTime() {
100 return fSelfTimeAverage;
101 }
102
103 /**
104 * Get the standard deviation of the self time
105 *
106 * @return The standard deviation of the self time
107 */
108 public double getStdDevSelfTime() {
109 long nbSegments = getNbSegments();
110 return nbSegments > 2 ? Math.sqrt(fVariance / (nbSegments - 1)) : Double.NaN;
111 }
112
113 /**
114 * Initialize the maximum and minimum self time
115 *
116 * @param selfTime
117 * Self time
118 */
119 public void initializeMaxMinSelfTime(long selfTime) {
120 fMaxSelfTime = selfTime;
121 fMinSelfTime = selfTime;
122 fSelfTimeAverage = selfTime;
123 }
124 }
This page took 0.048211 seconds and 4 git commands to generate.