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