Commit | Line | Data |
---|---|---|
7b79ee46 | 1 | /******************************************************************************* |
65a4afc0 | 2 | * Copyright (c) 2015, 2016 EfficiOS Inc., Ericsson |
7b79ee46 FLN |
3 | * |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | ||
660d4ed9 | 10 | package org.eclipse.tracecompass.internal.analysis.os.linux.core.latency; |
7b79ee46 FLN |
11 | |
12 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; | |
13 | ||
14 | import java.io.IOException; | |
15 | import java.io.ObjectInputStream; | |
18c18ee0 | 16 | import java.util.Collection; |
09f15ee9 | 17 | import java.util.Collections; |
6ad9d1cb | 18 | import java.util.Comparator; |
7b79ee46 | 19 | import java.util.HashMap; |
7b79ee46 | 20 | import java.util.Map; |
7b79ee46 | 21 | |
7858428e GB |
22 | import org.eclipse.core.runtime.IProgressMonitor; |
23 | import org.eclipse.core.runtime.NullProgressMonitor; | |
07b705e8 | 24 | import org.eclipse.jdt.annotation.NonNull; |
7b79ee46 | 25 | import org.eclipse.jdt.annotation.Nullable; |
0f7a12d3 | 26 | import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect; |
09f15ee9 | 27 | import org.eclipse.tracecompass.analysis.os.linux.core.tid.TidAnalysisModule; |
7b79ee46 FLN |
28 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout; |
29 | import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace; | |
65a4afc0 | 30 | import org.eclipse.tracecompass.analysis.timing.core.segmentstore.AbstractSegmentStoreAnalysisEventBasedModule; |
7b79ee46 FLN |
31 | import org.eclipse.tracecompass.segmentstore.core.ISegment; |
32 | import org.eclipse.tracecompass.segmentstore.core.ISegmentStore; | |
09f15ee9 | 33 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; |
7b79ee46 | 34 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
18c18ee0 | 35 | import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect; |
09f15ee9 | 36 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
7b79ee46 | 37 | |
18c18ee0 | 38 | import com.google.common.collect.ImmutableList; |
09f15ee9 | 39 | import com.google.common.collect.ImmutableSet; |
7b79ee46 FLN |
40 | |
41 | /** | |
42 | * @author Alexandre Montplaisir | |
fb3a499b | 43 | * @since 2.0 |
7b79ee46 | 44 | */ |
65a4afc0 | 45 | public class SystemCallLatencyAnalysis extends AbstractSegmentStoreAnalysisEventBasedModule { |
7b79ee46 FLN |
46 | |
47 | /** | |
48 | * The ID of this analysis | |
49 | */ | |
aa65365a | 50 | public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.latency.syscall"; //$NON-NLS-1$ |
7b79ee46 FLN |
51 | |
52 | private static final String DATA_FILENAME = "latency-analysis.dat"; //$NON-NLS-1$ | |
53 | ||
18c18ee0 | 54 | private static final Collection<ISegmentAspect> BASE_ASPECTS = |
0e4f957e | 55 | ImmutableList.of(SyscallNameAspect.INSTANCE); |
18c18ee0 | 56 | |
7b79ee46 FLN |
57 | @Override |
58 | public String getId() { | |
59 | return ID; | |
60 | } | |
61 | ||
09f15ee9 GB |
62 | @Override |
63 | protected Iterable<IAnalysisModule> getDependentAnalyses() { | |
64 | ITmfTrace trace = getTrace(); | |
65 | if (trace == null) { | |
66 | throw new IllegalStateException(); | |
67 | } | |
68 | IAnalysisModule module = trace.getAnalysisModule(TidAnalysisModule.ID); | |
69 | if (module == null) { | |
70 | return Collections.EMPTY_SET; | |
71 | } | |
72 | return ImmutableSet.of(module); | |
73 | } | |
74 | ||
18c18ee0 BH |
75 | @Override |
76 | public Iterable<ISegmentAspect> getSegmentAspects() { | |
77 | return BASE_ASPECTS; | |
78 | } | |
79 | ||
7b79ee46 | 80 | @Override |
07b705e8 | 81 | public @NonNull String getDataFileName() { |
152630e0 | 82 | return DATA_FILENAME; |
7b79ee46 FLN |
83 | } |
84 | ||
85 | @Override | |
152630e0 BH |
86 | public AbstractSegmentStoreAnalysisRequest createAnalysisRequest(ISegmentStore<ISegment> syscalls) { |
87 | return new SyscallLatencyAnalysisRequest(syscalls); | |
7b79ee46 FLN |
88 | } |
89 | ||
152630e0 BH |
90 | @Override |
91 | protected Object[] readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { | |
92 | return checkNotNull((Object[]) ois.readObject()); | |
7b79ee46 FLN |
93 | } |
94 | ||
09f15ee9 | 95 | private class SyscallLatencyAnalysisRequest extends AbstractSegmentStoreAnalysisRequest { |
7b79ee46 | 96 | |
7b79ee46 | 97 | private final Map<Integer, SystemCall.InitialInfo> fOngoingSystemCalls = new HashMap<>(); |
152630e0 | 98 | private @Nullable IKernelAnalysisEventLayout fLayout; |
7858428e | 99 | private final IProgressMonitor fMonitor = new NullProgressMonitor(); |
7b79ee46 | 100 | |
152630e0 BH |
101 | public SyscallLatencyAnalysisRequest(ISegmentStore<ISegment> syscalls) { |
102 | super(syscalls); | |
7b79ee46 FLN |
103 | } |
104 | ||
105 | @Override | |
106 | public void handleData(final ITmfEvent event) { | |
107 | super.handleData(event); | |
152630e0 BH |
108 | IKernelAnalysisEventLayout layout = fLayout; |
109 | if (layout == null) { | |
0e4f957e | 110 | IKernelTrace trace = (IKernelTrace) event.getTrace(); |
152630e0 BH |
111 | layout = trace.getKernelEventLayout(); |
112 | fLayout = layout; | |
113 | } | |
7b79ee46 FLN |
114 | final String eventName = event.getType().getName(); |
115 | ||
152630e0 BH |
116 | if (eventName.startsWith(layout.eventSyscallEntryPrefix()) || |
117 | eventName.startsWith(layout.eventCompatSyscallEntryPrefix())) { | |
7b79ee46 FLN |
118 | /* This is a system call entry event */ |
119 | ||
7858428e GB |
120 | Integer tid; |
121 | try { | |
122 | tid = KernelTidAspect.INSTANCE.resolve(event, true, fMonitor); | |
123 | } catch (InterruptedException e) { | |
124 | return; | |
125 | } | |
7b79ee46 FLN |
126 | if (tid == null) { |
127 | // no information on this event/trace ? | |
128 | return; | |
129 | } | |
130 | ||
131 | /* Record the event's data into the intial system call info */ | |
132 | // String syscallName = fLayout.getSyscallNameFromEvent(event); | |
133 | long startTime = event.getTimestamp().getValue(); | |
152630e0 | 134 | String syscallName = eventName.substring(layout.eventSyscallEntryPrefix().length()); |
bbadfd0a | 135 | |
137512b3 | 136 | SystemCall.InitialInfo newSysCall = new SystemCall.InitialInfo(startTime, syscallName.intern()); |
7b79ee46 FLN |
137 | fOngoingSystemCalls.put(tid, newSysCall); |
138 | ||
152630e0 | 139 | } else if (eventName.startsWith(layout.eventSyscallExitPrefix())) { |
7b79ee46 FLN |
140 | /* This is a system call exit event */ |
141 | ||
7858428e GB |
142 | Integer tid; |
143 | try { | |
144 | tid = KernelTidAspect.INSTANCE.resolve(event, true, fMonitor); | |
145 | } catch (InterruptedException e) { | |
146 | return; | |
147 | } | |
7b79ee46 FLN |
148 | if (tid == null) { |
149 | return; | |
150 | } | |
151 | ||
152 | SystemCall.InitialInfo info = fOngoingSystemCalls.remove(tid); | |
153 | if (info == null) { | |
154 | /* | |
155 | * We have not seen the entry event corresponding to this | |
156 | * exit (lost event, or before start of trace). | |
157 | */ | |
158 | return; | |
159 | } | |
160 | ||
161 | long endTime = event.getTimestamp().getValue(); | |
137512b3 | 162 | ISegment syscall = new SystemCall(info, endTime); |
152630e0 | 163 | getSegmentStore().add(syscall); |
7b79ee46 FLN |
164 | } |
165 | } | |
166 | ||
167 | @Override | |
168 | public void handleCompleted() { | |
169 | fOngoingSystemCalls.clear(); | |
7858428e GB |
170 | super.handleCompleted(); |
171 | } | |
172 | ||
173 | @Override | |
174 | public void handleCancel() { | |
175 | fMonitor.setCanceled(true); | |
176 | super.handleCancel(); | |
7b79ee46 FLN |
177 | } |
178 | } | |
179 | ||
1e706b1d | 180 | private static final class SyscallNameAspect implements ISegmentAspect { |
18c18ee0 BH |
181 | public static final ISegmentAspect INSTANCE = new SyscallNameAspect(); |
182 | ||
183 | private SyscallNameAspect() { } | |
184 | ||
185 | @Override | |
186 | public String getHelpText() { | |
187 | return checkNotNull(Messages.SegmentAspectHelpText_SystemCall); | |
188 | } | |
189 | @Override | |
190 | public String getName() { | |
191 | return checkNotNull(Messages.SegmentAspectName_SystemCall); | |
192 | } | |
193 | @Override | |
6ad9d1cb BH |
194 | public @Nullable Comparator<?> getComparator() { |
195 | return null; | |
196 | } | |
197 | @Override | |
18c18ee0 BH |
198 | public @Nullable String resolve(ISegment segment) { |
199 | if (segment instanceof SystemCall) { | |
200 | return ((SystemCall) segment).getName(); | |
201 | } | |
202 | return EMPTY_STRING; | |
203 | } | |
204 | } | |
205 | ||
7b79ee46 | 206 | } |