analysis: Add null check for dependent analysis
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / latency / statistics / SystemCallLatencyStatisticsAnalysisModule.java
CommitLineData
ce8319b6
BH
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;
13
14import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
15
16import java.util.HashMap;
17import java.util.Iterator;
18import java.util.Map;
19
20import org.eclipse.core.runtime.IProgressMonitor;
21import org.eclipse.jdt.annotation.Nullable;
aa65365a 22import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCallLatencyAnalysis;
ce8319b6
BH
23import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall;
24import org.eclipse.tracecompass.segmentstore.core.ISegment;
25import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
26import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
27import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
28import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
31
32import com.google.common.collect.ImmutableList;
33
34/**
35 * Analysis module to calculate statistics of a latency analysis
36 *
37 * @author Bernd Hufmann
38 */
aa65365a 39public class SystemCallLatencyStatisticsAnalysisModule extends TmfAbstractAnalysisModule {
ce8319b6
BH
40
41 /** The analysis module ID */
aa65365a 42 public static String ID = "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"; //$NON-NLS-1$
ce8319b6 43
aa65365a 44 private @Nullable SystemCallLatencyAnalysis fLatencyModule;
ce8319b6
BH
45
46 private @Nullable LatencyStatistics fTotalStats;
47
3507ca88 48 private @Nullable Map<String, LatencyStatistics> fPerSyscallStats;
ce8319b6
BH
49
50 @Override
51 protected Iterable<IAnalysisModule> getDependentAnalyses() {
52 ITmfTrace trace = getTrace();
53 if (trace != null) {
aa65365a 54 SystemCallLatencyAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, SystemCallLatencyAnalysis.class, checkNotNull(SystemCallLatencyAnalysis.ID));
9451f462
BH
55 if (module != null) {
56 fLatencyModule = module;
57 return checkNotNull(ImmutableList.of((IAnalysisModule) module));
58 }
ce8319b6
BH
59 }
60 return super.getDependentAnalyses();
61 }
62
63 @Override
64 protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
aa65365a 65 SystemCallLatencyAnalysis latency = fLatencyModule;
ce8319b6
BH
66 ITmfTrace trace = getTrace();
67 if ((latency == null) || (trace == null)) {
68 return false;
69 }
70 latency.waitForCompletion();
71
72 ISegmentStore<ISegment> store = latency.getResults();
73
74 if (store != null) {
75
76 boolean result = calculateTotalManual(store, monitor);
77
78 if (!result) {
79 return false;
80 }
81
82 result = calculateTotalPerSyscall(store, monitor);
83 if (!result) {
84 return false;
85 }
86 }
87 return true;
88 }
89
90 private boolean calculateTotalManual(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
91 LatencyStatistics total = new LatencyStatistics();
92 Iterator<ISegment> iter = store.iterator();
93 while (iter.hasNext()) {
94 if (monitor.isCanceled()) {
95 return false;
96 }
97 ISegment segment = iter.next();
98 total.update(checkNotNull(segment));
99 }
ce8319b6
BH
100 fTotalStats = total;
101 return true;
102 }
103
104 private boolean calculateTotalPerSyscall(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
3507ca88 105 Map<String, LatencyStatistics> perSyscallStats = new HashMap<>();
ce8319b6
BH
106
107 Iterator<ISegment> iter = store.iterator();
108 while (iter.hasNext()) {
109 if (monitor.isCanceled()) {
110 return false;
111 }
112 ISegment segment = iter.next();
113 if (segment instanceof SystemCall) {
114 SystemCall syscall = (SystemCall) segment;
3507ca88 115 LatencyStatistics values = perSyscallStats.get(syscall.getName());
ce8319b6
BH
116 if (values == null) {
117 values = new LatencyStatistics();
118 }
119 values.update(segment);
3507ca88 120 perSyscallStats.put(syscall.getName(), values);
ce8319b6
BH
121 }
122 }
3507ca88 123 fPerSyscallStats = perSyscallStats;
ce8319b6
BH
124 return true;
125 }
126
127 @Override
128 protected void canceling() {
129 }
130
131 /**
132 * The total statistics
133 *
134 * @return the total statistics
135 */
136 public @Nullable LatencyStatistics getTotalStats() {
137 return fTotalStats;
138 }
139
140 /**
141 * The per syscall statistics
142 *
143 * @return the per syscall statistics
144 */
3507ca88 145 public @Nullable Map<String, LatencyStatistics> getPerSyscallStats() {
ce8319b6
BH
146 return fPerSyscallStats;
147 }
148
149 }
This page took 0.032795 seconds and 5 git commands to generate.