releng: Transition to jdt.annotation 2.0
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / latency / LatencyAnalysis.java
CommitLineData
7b79ee46
FLN
1/*******************************************************************************
2 * Copyright (c) 2015 EfficiOS Inc., Ericsson
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
10package org.eclipse.tracecompass.analysis.os.linux.core.latency;
11
12import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14import java.io.IOException;
15import java.io.ObjectInputStream;
18c18ee0 16import java.util.Collection;
6ad9d1cb 17import java.util.Comparator;
7b79ee46 18import java.util.HashMap;
7b79ee46 19import java.util.Map;
7b79ee46 20
7b79ee46
FLN
21import org.eclipse.jdt.annotation.Nullable;
22import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelTidAspect;
23import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
24import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
152630e0 25import org.eclipse.tracecompass.analysis.timing.core.segmentstore.AbstractSegmentStoreAnalysisModule;
7b79ee46
FLN
26import org.eclipse.tracecompass.common.core.NonNullUtils;
27import org.eclipse.tracecompass.segmentstore.core.ISegment;
28import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
7b79ee46 29import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
18c18ee0 30import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect;
7b79ee46
FLN
31
32import com.google.common.base.Function;
33import com.google.common.collect.FluentIterable;
18c18ee0 34import com.google.common.collect.ImmutableList;
7b79ee46
FLN
35
36/**
37 * @author Alexandre Montplaisir
fb3a499b 38 * @since 2.0
7b79ee46 39 */
152630e0 40public class LatencyAnalysis extends AbstractSegmentStoreAnalysisModule {
7b79ee46
FLN
41
42 /**
43 * The ID of this analysis
44 */
45 public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.latency"; //$NON-NLS-1$
46
47 private static final String DATA_FILENAME = "latency-analysis.dat"; //$NON-NLS-1$
48
18c18ee0
BH
49 private static final Collection<ISegmentAspect> BASE_ASPECTS =
50 checkNotNull(ImmutableList.of(SyscallNameAspect.INSTANCE));
51
7b79ee46
FLN
52 @Override
53 public String getId() {
54 return ID;
55 }
56
18c18ee0
BH
57 @Override
58 public Iterable<ISegmentAspect> getSegmentAspects() {
59 return BASE_ASPECTS;
60 }
61
7b79ee46 62 @Override
152630e0
BH
63 public String getDataFileName() {
64 return DATA_FILENAME;
7b79ee46
FLN
65 }
66
67 @Override
152630e0
BH
68 public AbstractSegmentStoreAnalysisRequest createAnalysisRequest(ISegmentStore<ISegment> syscalls) {
69 return new SyscallLatencyAnalysisRequest(syscalls);
7b79ee46
FLN
70 }
71
152630e0
BH
72 @Override
73 protected Object[] readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
74 return checkNotNull((Object[]) ois.readObject());
7b79ee46
FLN
75 }
76
152630e0 77 private static class SyscallLatencyAnalysisRequest extends AbstractSegmentStoreAnalysisRequest {
7b79ee46 78
7b79ee46 79 private final Map<Integer, SystemCall.InitialInfo> fOngoingSystemCalls = new HashMap<>();
152630e0 80 private @Nullable IKernelAnalysisEventLayout fLayout;
7b79ee46 81
152630e0
BH
82 public SyscallLatencyAnalysisRequest(ISegmentStore<ISegment> syscalls) {
83 super(syscalls);
7b79ee46
FLN
84 }
85
86 @Override
87 public void handleData(final ITmfEvent event) {
88 super.handleData(event);
152630e0
BH
89 IKernelAnalysisEventLayout layout = fLayout;
90 if (layout == null) {
91 IKernelTrace trace = checkNotNull((IKernelTrace) event.getTrace());
92 layout = trace.getKernelEventLayout();
93 fLayout = layout;
94 }
7b79ee46
FLN
95 final String eventName = event.getType().getName();
96
152630e0
BH
97 if (eventName.startsWith(layout.eventSyscallEntryPrefix()) ||
98 eventName.startsWith(layout.eventCompatSyscallEntryPrefix())) {
7b79ee46
FLN
99 /* This is a system call entry event */
100
101 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
102 if (tid == null) {
103 // no information on this event/trace ?
104 return;
105 }
106
107 /* Record the event's data into the intial system call info */
108 // String syscallName = fLayout.getSyscallNameFromEvent(event);
109 long startTime = event.getTimestamp().getValue();
152630e0 110 String syscallName = eventName.substring(layout.eventSyscallEntryPrefix().length());
7b79ee46
FLN
111 FluentIterable<String> argNames = FluentIterable.from(event.getContent().getFieldNames());
112 Map<String, String> args = argNames.toMap(new Function<String, String>() {
113 @Override
114 public String apply(@Nullable String input) {
115 return checkNotNull(event.getContent().getField(input).getValue().toString());
116 }
117 });
118 SystemCall.InitialInfo newSysCall = new SystemCall.InitialInfo(startTime, NonNullUtils.checkNotNull(syscallName), NonNullUtils.checkNotNull(args));
119 fOngoingSystemCalls.put(tid, newSysCall);
120
152630e0 121 } else if (eventName.startsWith(layout.eventSyscallExitPrefix())) {
7b79ee46
FLN
122 /* This is a system call exit event */
123
124 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
125 if (tid == null) {
126 return;
127 }
128
129 SystemCall.InitialInfo info = fOngoingSystemCalls.remove(tid);
130 if (info == null) {
131 /*
132 * We have not seen the entry event corresponding to this
133 * exit (lost event, or before start of trace).
134 */
135 return;
136 }
137
138 long endTime = event.getTimestamp().getValue();
139 int ret = ((Long) event.getContent().getField("ret").getValue()).intValue(); //$NON-NLS-1$
140 ISegment syscall = new SystemCall(info, endTime, ret);
152630e0 141 getSegmentStore().add(syscall);
7b79ee46
FLN
142 }
143 }
144
145 @Override
146 public void handleCompleted() {
147 fOngoingSystemCalls.clear();
148 }
149 }
150
18c18ee0
BH
151 private static class SyscallNameAspect implements ISegmentAspect {
152 public static final ISegmentAspect INSTANCE = new SyscallNameAspect();
153
154 private SyscallNameAspect() { }
155
156 @Override
157 public String getHelpText() {
158 return checkNotNull(Messages.SegmentAspectHelpText_SystemCall);
159 }
160 @Override
161 public String getName() {
162 return checkNotNull(Messages.SegmentAspectName_SystemCall);
163 }
164 @Override
6ad9d1cb
BH
165 public @Nullable Comparator<?> getComparator() {
166 return null;
167 }
168 @Override
18c18ee0
BH
169 public @Nullable String resolve(ISegment segment) {
170 if (segment instanceof SystemCall) {
171 return ((SystemCall) segment).getName();
172 }
173 return EMPTY_STRING;
174 }
175 }
176
7b79ee46 177}
This page took 0.034006 seconds and 5 git commands to generate.