1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
6 * All rights reserved. This program and the accompanying materials are
7 * made available under the terms of the Eclipse Public License v1.0 which
8 * accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.trace
.IKernelAnalysisEventLayout
;
19 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
20 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.Activator
;
21 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.IrqEntryHandler
;
22 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.IrqExitHandler
;
23 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.KernelEventHandler
;
24 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.PiSetprioHandler
;
25 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.ProcessExitHandler
;
26 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.ProcessForkHandler
;
27 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.ProcessFreeHandler
;
28 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SchedSwitchHandler
;
29 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SchedWakeupHandler
;
30 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SoftIrqEntryHandler
;
31 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SoftIrqExitHandler
;
32 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SoftIrqRaiseHandler
;
33 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.StateDumpHandler
;
34 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SysEntryHandler
;
35 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SysExitHandler
;
36 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
37 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
38 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
39 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
41 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
44 import com
.google
.common
.collect
.ImmutableMap
;
47 * This is the state change input plugin for TMF's state system which handles
48 * the LTTng 2.0 kernel traces in CTF format.
50 * It uses the reference handler defined in CTFKernelHandler.java.
52 * @author Alexandre Montplaisir
54 public class KernelStateProvider
extends AbstractTmfStateProvider
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Version number of this state provider. Please bump this if you modify the
62 * contents of the generated state history in some way.
64 private static final int VERSION
= 10;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 private final Map
<String
, KernelEventHandler
> fEventNames
;
71 private final IKernelAnalysisEventLayout fLayout
;
73 private final KernelEventHandler fSysEntryHandler
;
74 private final KernelEventHandler fSysExitHandler
;
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * Instantiate a new state provider plugin.
84 * The LTTng 2.0 kernel trace directory
86 * The event layout to use for this state provider. Usually
87 * depending on the tracer implementation.
89 public KernelStateProvider(ITmfTrace trace
, IKernelAnalysisEventLayout layout
) {
90 super(trace
, "Kernel"); //$NON-NLS-1$
92 fEventNames
= buildEventNames(layout
);
94 fSysEntryHandler
= new SysEntryHandler(fLayout
);
95 fSysExitHandler
= new SysExitHandler(fLayout
);
98 // ------------------------------------------------------------------------
99 // Event names management
100 // ------------------------------------------------------------------------
102 private static Map
<String
, KernelEventHandler
> buildEventNames(IKernelAnalysisEventLayout layout
) {
103 ImmutableMap
.Builder
<String
, KernelEventHandler
> builder
= ImmutableMap
.builder();
105 builder
.put(layout
.eventIrqHandlerEntry(), new IrqEntryHandler(layout
));
106 builder
.put(layout
.eventIrqHandlerExit(), new IrqExitHandler(layout
));
107 builder
.put(layout
.eventSoftIrqEntry(), new SoftIrqEntryHandler(layout
));
108 builder
.put(layout
.eventSoftIrqExit(), new SoftIrqExitHandler(layout
));
109 builder
.put(layout
.eventSoftIrqRaise(), new SoftIrqRaiseHandler(layout
));
110 builder
.put(layout
.eventSchedSwitch(), new SchedSwitchHandler(layout
));
111 builder
.put(layout
.eventSchedPiSetprio(), new PiSetprioHandler(layout
));
112 builder
.put(layout
.eventSchedProcessFork(), new ProcessForkHandler(layout
));
113 builder
.put(layout
.eventSchedProcessExit(), new ProcessExitHandler(layout
));
114 builder
.put(layout
.eventSchedProcessFree(), new ProcessFreeHandler(layout
));
116 final String eventStatedumpProcessState
= layout
.eventStatedumpProcessState();
117 if (eventStatedumpProcessState
!= null) {
118 builder
.put(eventStatedumpProcessState
, new StateDumpHandler(layout
));
121 for (String eventSchedWakeup
: layout
.eventsSchedWakeup()) {
122 builder
.put(eventSchedWakeup
, new SchedWakeupHandler(layout
));
125 return NonNullUtils
.checkNotNull(builder
.build());
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 public int getVersion() {
138 public KernelStateProvider
getNewInstance() {
139 return new KernelStateProvider(this.getTrace(), fLayout
);
143 protected void eventHandle(@Nullable ITmfEvent event
) {
148 final String eventName
= event
.getName();
151 final ITmfStateSystemBuilder ss
= NonNullUtils
.checkNotNull(getStateSystemBuilder());
153 * Feed event to the history system if it's known to cause a state
156 KernelEventHandler handler
= fEventNames
.get(eventName
);
157 if (handler
== null) {
158 if (isSyscallExit(eventName
)) {
159 handler
= fSysExitHandler
;
160 } else if (isSyscallEntry(eventName
)) {
161 handler
= fSysEntryHandler
;
164 if (handler
!= null) {
165 handler
.handleEvent(ss
, event
);
168 } catch (AttributeNotFoundException ae
) {
170 * This would indicate a problem with the logic of the manager here,
171 * so it shouldn't happen.
173 Activator
.getDefault().logError("Attribute not found: " + ae
.getMessage(), ae
); //$NON-NLS-1$
175 } catch (TimeRangeException tre
) {
177 * This would happen if the events in the trace aren't ordered
178 * chronologically, which should never be the case ...
180 Activator
.getDefault().logError("TimeRangeExcpetion caught in the state system's event manager.\n" + //$NON-NLS-1$
181 "Are the events in the trace correctly ordered?\n" + tre
.getMessage(), tre
); //$NON-NLS-1$
183 } catch (StateValueTypeException sve
) {
185 * This would happen if we were trying to push/pop attributes not of
186 * type integer. Which, once again, should never happen.
188 Activator
.getDefault().logError("State value error: " + sve
.getMessage(), sve
); //$NON-NLS-1$
192 private boolean isSyscallEntry(@Nullable String eventName
) {
193 return (eventName
!= null) && (eventName
.startsWith(fLayout
.eventSyscallEntryPrefix())
194 || eventName
.startsWith(fLayout
.eventCompatSyscallEntryPrefix()));
197 private boolean isSyscallExit(@Nullable String eventName
) {
198 return (eventName
!= null) && (eventName
.startsWith(fLayout
.eventSyscallExitPrefix()));