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