Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ | |
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; | |
ce8319b6 | 22 | import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCall; |
53f46dc0 | 23 | import org.eclipse.tracecompass.analysis.os.linux.core.latency.SystemCallLatencyAnalysis; |
658401c8 | 24 | import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; |
ce8319b6 BH |
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 | */ | |
aa65365a | 40 | public class SystemCallLatencyStatisticsAnalysisModule extends TmfAbstractAnalysisModule { |
ce8319b6 BH |
41 | |
42 | /** The analysis module ID */ | |
5ea53577 | 43 | public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.core.latency.statistics.syscall"; //$NON-NLS-1$ |
ce8319b6 | 44 | |
aa65365a | 45 | private @Nullable SystemCallLatencyAnalysis fLatencyModule; |
ce8319b6 | 46 | |
53f46dc0 | 47 | private @Nullable SegmentStoreStatistics fTotalStats; |
ce8319b6 | 48 | |
53f46dc0 | 49 | private @Nullable Map<String, SegmentStoreStatistics> fPerSyscallStats; |
ce8319b6 BH |
50 | |
51 | @Override | |
52 | protected Iterable<IAnalysisModule> getDependentAnalyses() { | |
53 | ITmfTrace trace = getTrace(); | |
54 | if (trace != null) { | |
aa65365a | 55 | SystemCallLatencyAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(trace, SystemCallLatencyAnalysis.class, checkNotNull(SystemCallLatencyAnalysis.ID)); |
9451f462 BH |
56 | if (module != null) { |
57 | fLatencyModule = module; | |
58 | return checkNotNull(ImmutableList.of((IAnalysisModule) module)); | |
59 | } | |
ce8319b6 BH |
60 | } |
61 | return super.getDependentAnalyses(); | |
62 | } | |
63 | ||
64 | @Override | |
65 | protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException { | |
aa65365a | 66 | SystemCallLatencyAnalysis latency = fLatencyModule; |
ce8319b6 BH |
67 | ITmfTrace trace = getTrace(); |
68 | if ((latency == null) || (trace == null)) { | |
69 | return false; | |
70 | } | |
71 | latency.waitForCompletion(); | |
72 | ||
73c74de7 | 73 | ISegmentStore<ISegment> segStore = latency.getSegmentStore(); |
ce8319b6 | 74 | |
73c74de7 | 75 | if (segStore != null) { |
ce8319b6 | 76 | |
73c74de7 | 77 | boolean result = calculateTotalManual(segStore, monitor); |
ce8319b6 BH |
78 | |
79 | if (!result) { | |
80 | return false; | |
81 | } | |
82 | ||
73c74de7 | 83 | result = calculateTotalPerSyscall(segStore, monitor); |
ce8319b6 BH |
84 | if (!result) { |
85 | return false; | |
86 | } | |
87 | } | |
88 | return true; | |
89 | } | |
90 | ||
91 | private boolean calculateTotalManual(ISegmentStore<ISegment> store, IProgressMonitor monitor) { | |
53f46dc0 | 92 | SegmentStoreStatistics total = new SegmentStoreStatistics(); |
ce8319b6 BH |
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 | } | |
ce8319b6 BH |
101 | fTotalStats = total; |
102 | return true; | |
103 | } | |
104 | ||
105 | private boolean calculateTotalPerSyscall(ISegmentStore<ISegment> store, IProgressMonitor monitor) { | |
53f46dc0 | 106 | Map<String, SegmentStoreStatistics> perSyscallStats = new HashMap<>(); |
ce8319b6 BH |
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; | |
53f46dc0 | 116 | SegmentStoreStatistics values = perSyscallStats.get(syscall.getName()); |
ce8319b6 | 117 | if (values == null) { |
53f46dc0 | 118 | values = new SegmentStoreStatistics(); |
ce8319b6 BH |
119 | } |
120 | values.update(segment); | |
3507ca88 | 121 | perSyscallStats.put(syscall.getName(), values); |
ce8319b6 BH |
122 | } |
123 | } | |
3507ca88 | 124 | fPerSyscallStats = perSyscallStats; |
ce8319b6 BH |
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 | */ | |
53f46dc0 | 137 | public @Nullable SegmentStoreStatistics getTotalStats() { |
ce8319b6 BH |
138 | return fTotalStats; |
139 | } | |
140 | ||
141 | /** | |
142 | * The per syscall statistics | |
143 | * | |
144 | * @return the per syscall statistics | |
145 | */ | |
53f46dc0 | 146 | public @Nullable Map<String, SegmentStoreStatistics> getPerSyscallStats() { |
ce8319b6 BH |
147 | return fPerSyscallStats; |
148 | } | |
149 | ||
150 | } |