1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.latency
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
14 import java
.io
.IOException
;
15 import java
.io
.ObjectInputStream
;
16 import java
.util
.Collection
;
17 import java
.util
.Comparator
;
18 import java
.util
.HashMap
;
20 import java
.util
.function
.Function
;
21 import java
.util
.stream
.Collectors
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.jdt
.annotation
.Nullable
;
25 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelTidAspect
;
26 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
27 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelTrace
;
28 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.segmentstore
.AbstractSegmentStoreAnalysisEventBasedModule
;
29 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
30 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.segment
.ISegmentAspect
;
34 import com
.google
.common
.collect
.ImmutableList
;
37 * @author Alexandre Montplaisir
40 public class SystemCallLatencyAnalysis
extends AbstractSegmentStoreAnalysisEventBasedModule
{
43 * The ID of this analysis
45 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.latency.syscall"; //$NON-NLS-1$
47 private static final String DATA_FILENAME
= "latency-analysis.dat"; //$NON-NLS-1$
49 private static final Collection
<ISegmentAspect
> BASE_ASPECTS
=
50 ImmutableList
.of(SyscallNameAspect
.INSTANCE
);
53 public String
getId() {
58 public Iterable
<ISegmentAspect
> getSegmentAspects() {
63 public @NonNull String
getDataFileName() {
68 public AbstractSegmentStoreAnalysisRequest
createAnalysisRequest(ISegmentStore
<ISegment
> syscalls
) {
69 return new SyscallLatencyAnalysisRequest(syscalls
);
73 protected Object
[] readObject(ObjectInputStream ois
) throws ClassNotFoundException
, IOException
{
74 return checkNotNull((Object
[]) ois
.readObject());
77 private static class SyscallLatencyAnalysisRequest
extends AbstractSegmentStoreAnalysisRequest
{
79 private final Map
<Integer
, SystemCall
.InitialInfo
> fOngoingSystemCalls
= new HashMap
<>();
80 private @Nullable IKernelAnalysisEventLayout fLayout
;
82 public SyscallLatencyAnalysisRequest(ISegmentStore
<ISegment
> syscalls
) {
87 public void handleData(final ITmfEvent event
) {
88 super.handleData(event
);
89 IKernelAnalysisEventLayout layout
= fLayout
;
91 IKernelTrace trace
= (IKernelTrace
) event
.getTrace();
92 layout
= trace
.getKernelEventLayout();
95 final String eventName
= event
.getType().getName();
97 if (eventName
.startsWith(layout
.eventSyscallEntryPrefix()) ||
98 eventName
.startsWith(layout
.eventCompatSyscallEntryPrefix())) {
99 /* This is a system call entry event */
101 Integer tid
= KernelTidAspect
.INSTANCE
.resolve(event
);
103 // no information on this event/trace ?
107 /* Record the event's data into the intial system call info */
108 // String syscallName = fLayout.getSyscallNameFromEvent(event);
109 long startTime
= event
.getTimestamp().getValue();
110 String syscallName
= eventName
.substring(layout
.eventSyscallEntryPrefix().length());
112 Map
<String
, String
> args
= event
.getContent().getFieldNames().stream()
113 .collect(Collectors
.toMap(Function
.identity(),
114 input
-> checkNotNull(event
.getContent().getField(input
).getValue().toString())));
116 SystemCall
.InitialInfo newSysCall
= new SystemCall
.InitialInfo(startTime
, checkNotNull(syscallName
), checkNotNull(args
));
117 fOngoingSystemCalls
.put(tid
, newSysCall
);
119 } else if (eventName
.startsWith(layout
.eventSyscallExitPrefix())) {
120 /* This is a system call exit event */
122 Integer tid
= KernelTidAspect
.INSTANCE
.resolve(event
);
127 SystemCall
.InitialInfo info
= fOngoingSystemCalls
.remove(tid
);
130 * We have not seen the entry event corresponding to this
131 * exit (lost event, or before start of trace).
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
);
139 getSegmentStore().add(syscall
);
144 public void handleCompleted() {
145 fOngoingSystemCalls
.clear();
149 private static class SyscallNameAspect
implements ISegmentAspect
{
150 public static final ISegmentAspect INSTANCE
= new SyscallNameAspect();
152 private SyscallNameAspect() { }
155 public String
getHelpText() {
156 return checkNotNull(Messages
.SegmentAspectHelpText_SystemCall
);
159 public String
getName() {
160 return checkNotNull(Messages
.SegmentAspectName_SystemCall
);
163 public @Nullable Comparator
<?
> getComparator() {
167 public @Nullable String
resolve(ISegment segment
) {
168 if (segment
instanceof SystemCall
) {
169 return ((SystemCall
) segment
).getName();