ad068e971fc4bc753dfb4b789fc6f9cb646c5da5
[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.segmentstore.core.ISegment;
25 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
26 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
27 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
28 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
29 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
30 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
31
32 import com.google.common.collect.ImmutableList;
33
34 /**
35 * Analysis module to calculate statistics of a latency analysis
36 *
37 * @author Bernd Hufmann
38 */
39 public class SystemCallLatencyStatisticsAnalysisModule extends TmfAbstractAnalysisModule {
40
41 /** The analysis module ID */
42 public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"; //$NON-NLS-1$
43
44 private @Nullable SystemCallLatencyAnalysis fLatencyModule;
45
46 private @Nullable SegmentStoreStatistics fTotalStats;
47
48 private @Nullable Map<String, SegmentStoreStatistics> fPerSyscallStats;
49
50 @Override
51 protected Iterable<IAnalysisModule> getDependentAnalyses() {
52 ITmfTrace trace = getTrace();
53 if (trace != null) {
54 SystemCallLatencyAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, SystemCallLatencyAnalysis.class, checkNotNull(SystemCallLatencyAnalysis.ID));
55 if (module != null) {
56 fLatencyModule = module;
57 return checkNotNull(ImmutableList.of((IAnalysisModule) module));
58 }
59 }
60 return super.getDependentAnalyses();
61 }
62
63 @Override
64 protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
65 SystemCallLatencyAnalysis latency = fLatencyModule;
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 SegmentStoreStatistics total = new SegmentStoreStatistics();
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 }
100 fTotalStats = total;
101 return true;
102 }
103
104 private boolean calculateTotalPerSyscall(ISegmentStore<ISegment> store, IProgressMonitor monitor) {
105 Map<String, SegmentStoreStatistics> perSyscallStats = new HashMap<>();
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;
115 SegmentStoreStatistics values = perSyscallStats.get(syscall.getName());
116 if (values == null) {
117 values = new SegmentStoreStatistics();
118 }
119 values.update(segment);
120 perSyscallStats.put(syscall.getName(), values);
121 }
122 }
123 fPerSyscallStats = perSyscallStats;
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 SegmentStoreStatistics getTotalStats() {
137 return fTotalStats;
138 }
139
140 /**
141 * The per syscall statistics
142 *
143 * @return the per syscall statistics
144 */
145 public @Nullable Map<String, SegmentStoreStatistics> getPerSyscallStats() {
146 return fPerSyscallStats;
147 }
148
149 }
This page took 0.068583 seconds and 5 git commands to generate.