lttng: Fix ust memory analysis help text display
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / latency / SystemCallLatencyAnalysis.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;
bbadfd0a
AM
20import java.util.function.Function;
21import java.util.stream.Collectors;
7b79ee46 22
07b705e8 23import org.eclipse.jdt.annotation.NonNull;
7b79ee46
FLN
24import org.eclipse.jdt.annotation.Nullable;
25import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelTidAspect;
26import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
27import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelTrace;
152630e0 28import org.eclipse.tracecompass.analysis.timing.core.segmentstore.AbstractSegmentStoreAnalysisModule;
7b79ee46
FLN
29import org.eclipse.tracecompass.segmentstore.core.ISegment;
30import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
7b79ee46 31import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
18c18ee0 32import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect;
7b79ee46 33
18c18ee0 34import com.google.common.collect.ImmutableList;
7b79ee46
FLN
35
36/**
37 * @author Alexandre Montplaisir
fb3a499b 38 * @since 2.0
7b79ee46 39 */
aa65365a 40public class SystemCallLatencyAnalysis extends AbstractSegmentStoreAnalysisModule {
7b79ee46
FLN
41
42 /**
43 * The ID of this analysis
44 */
aa65365a 45 public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.latency.syscall"; //$NON-NLS-1$
7b79ee46
FLN
46
47 private static final String DATA_FILENAME = "latency-analysis.dat"; //$NON-NLS-1$
48
18c18ee0 49 private static final Collection<ISegmentAspect> BASE_ASPECTS =
0e4f957e 50 ImmutableList.of(SyscallNameAspect.INSTANCE);
18c18ee0 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
07b705e8 63 public @NonNull String getDataFileName() {
152630e0 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) {
0e4f957e 91 IKernelTrace trace = (IKernelTrace) event.getTrace();
152630e0
BH
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());
bbadfd0a
AM
111
112 Map<String, String> args = event.getContent().getFieldNames().stream()
113 .collect(Collectors.toMap(Function.identity(),
114 input -> checkNotNull(event.getContent().getField(input).getValue().toString())));
115
116 SystemCall.InitialInfo newSysCall = new SystemCall.InitialInfo(startTime, checkNotNull(syscallName), checkNotNull(args));
7b79ee46
FLN
117 fOngoingSystemCalls.put(tid, newSysCall);
118
152630e0 119 } else if (eventName.startsWith(layout.eventSyscallExitPrefix())) {
7b79ee46
FLN
120 /* This is a system call exit event */
121
122 Integer tid = KernelTidAspect.INSTANCE.resolve(event);
123 if (tid == null) {
124 return;
125 }
126
127 SystemCall.InitialInfo info = fOngoingSystemCalls.remove(tid);
128 if (info == null) {
129 /*
130 * We have not seen the entry event corresponding to this
131 * exit (lost event, or before start of trace).
132 */
133 return;
134 }
135
136 long endTime = event.getTimestamp().getValue();
137 int ret = ((Long) event.getContent().getField("ret").getValue()).intValue(); //$NON-NLS-1$
138 ISegment syscall = new SystemCall(info, endTime, ret);
152630e0 139 getSegmentStore().add(syscall);
7b79ee46
FLN
140 }
141 }
142
143 @Override
144 public void handleCompleted() {
145 fOngoingSystemCalls.clear();
146 }
147 }
148
18c18ee0
BH
149 private static class SyscallNameAspect implements ISegmentAspect {
150 public static final ISegmentAspect INSTANCE = new SyscallNameAspect();
151
152 private SyscallNameAspect() { }
153
154 @Override
155 public String getHelpText() {
156 return checkNotNull(Messages.SegmentAspectHelpText_SystemCall);
157 }
158 @Override
159 public String getName() {
160 return checkNotNull(Messages.SegmentAspectName_SystemCall);
161 }
162 @Override
6ad9d1cb
BH
163 public @Nullable Comparator<?> getComparator() {
164 return null;
165 }
166 @Override
18c18ee0
BH
167 public @Nullable String resolve(ISegment segment) {
168 if (segment instanceof SystemCall) {
169 return ((SystemCall) segment).getName();
170 }
171 return EMPTY_STRING;
172 }
173 }
174
7b79ee46 175}
This page took 0.0405 seconds and 5 git commands to generate.