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
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.internal
;
15 import static java
.util
.Objects
.requireNonNull
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
23 import org
.lttng
.scope
.lttng
.kernel
.core
.activator
.internal
.Activator
;
24 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.IPIEntryHandler
;
25 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.IPIExitHandler
;
26 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.IrqEntryHandler
;
27 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.IrqExitHandler
;
28 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.KernelEventHandler
;
29 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.PiSetprioHandler
;
30 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.ProcessExitHandler
;
31 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.ProcessForkHandler
;
32 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.ProcessFreeHandler
;
33 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SchedMigrateTaskHandler
;
34 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SchedSwitchHandler
;
35 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SchedWakeupHandler
;
36 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SoftIrqEntryHandler
;
37 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SoftIrqExitHandler
;
38 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SoftIrqRaiseHandler
;
39 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.StateDumpHandler
;
40 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SysEntryHandler
;
41 import org
.lttng
.scope
.lttng
.kernel
.core
.analysis
.os
.handlers
.internal
.SysExitHandler
;
42 import org
.lttng
.scope
.lttng
.kernel
.core
.trace
.layout
.ILttngKernelEventLayout
;
44 import com
.google
.common
.collect
.ImmutableMap
;
46 import ca
.polymtl
.dorsal
.libdelorean
.ITmfStateSystemBuilder
;
47 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.AttributeNotFoundException
;
48 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.StateValueTypeException
;
49 import ca
.polymtl
.dorsal
.libdelorean
.exceptions
.TimeRangeException
;
52 * This is the state change input plugin for the state system which handles the
59 * | |- <CPU number> -> CPU Status
60 * | | |- CURRENT_THREAD
62 * | | | |- <Soft IRQ number> -> Soft IRQ Status
64 * | | | |- <IRQ number> -> IRQ Status
66 * | |- <Thread number> -> Thread Status
71 * | | |- CURRENT_CPU_RQ
74 * @author Alexandre Montplaisir
76 public class KernelStateProvider
extends AbstractTmfStateProvider
{
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 * Version number of this state provider. Please bump this if you modify the
84 * contents of the generated state history in some way.
86 private static final int VERSION
= 27;
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
92 private final Map
<String
, KernelEventHandler
> fEventNames
;
93 private final ILttngKernelEventLayout fLayout
;
95 private final KernelEventHandler fSysEntryHandler
;
96 private final KernelEventHandler fSysExitHandler
;
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
103 * Instantiate a new state provider plugin.
106 * The LTTng 2.0 kernel trace directory
108 * The event layout to use for this state provider. Usually
109 * depending on the tracer implementation.
111 public KernelStateProvider(ITmfTrace trace
, ILttngKernelEventLayout layout
) {
112 super(trace
, "Kernel"); //$NON-NLS-1$
114 fEventNames
= buildEventNames(layout
);
116 fSysEntryHandler
= new SysEntryHandler(fLayout
);
117 fSysExitHandler
= new SysExitHandler(fLayout
);
120 // ------------------------------------------------------------------------
121 // Event names management
122 // ------------------------------------------------------------------------
124 private static Map
<String
, KernelEventHandler
> buildEventNames(ILttngKernelEventLayout layout
) {
125 ImmutableMap
.Builder
<String
, KernelEventHandler
> builder
= ImmutableMap
.builder();
127 builder
.put(layout
.eventIrqHandlerEntry(), new IrqEntryHandler(layout
));
128 builder
.put(layout
.eventIrqHandlerExit(), new IrqExitHandler(layout
));
129 builder
.put(layout
.eventSoftIrqEntry(), new SoftIrqEntryHandler(layout
));
130 builder
.put(layout
.eventSoftIrqExit(), new SoftIrqExitHandler(layout
));
131 builder
.put(layout
.eventSoftIrqRaise(), new SoftIrqRaiseHandler(layout
));
132 builder
.put(layout
.eventSchedSwitch(), new SchedSwitchHandler(layout
));
133 builder
.put(layout
.eventSchedPiSetprio(), new PiSetprioHandler(layout
));
134 builder
.put(layout
.eventSchedProcessFork(), new ProcessForkHandler(layout
));
135 builder
.put(layout
.eventSchedProcessExit(), new ProcessExitHandler(layout
));
136 builder
.put(layout
.eventSchedProcessFree(), new ProcessFreeHandler(layout
));
137 builder
.put(layout
.eventSchedProcessWaking(), new SchedWakeupHandler(layout
));
138 builder
.put(layout
.eventSchedMigrateTask(), new SchedMigrateTaskHandler(layout
));
140 for (String s
: layout
.getIPIIrqVectorsEntries()) {
141 builder
.put(s
, new IPIEntryHandler(layout
));
143 for (String s
: layout
.getIPIIrqVectorsExits()) {
144 builder
.put(s
, new IPIExitHandler(layout
));
147 final String eventStatedumpProcessState
= layout
.eventStatedumpProcessState();
148 if (eventStatedumpProcessState
!= null) {
149 builder
.put(eventStatedumpProcessState
, new StateDumpHandler(layout
));
152 for (String eventSchedWakeup
: layout
.eventsSchedWakeup()) {
153 builder
.put(eventSchedWakeup
, new SchedWakeupHandler(layout
));
156 return builder
.build();
159 // ------------------------------------------------------------------------
161 // ------------------------------------------------------------------------
164 public int getVersion() {
169 public KernelStateProvider
getNewInstance() {
170 return new KernelStateProvider(this.getTrace(), fLayout
);
174 protected void eventHandle(@Nullable ITmfEvent event
) {
179 final String eventName
= event
.getName();
182 final ITmfStateSystemBuilder ss
= requireNonNull(getStateSystemBuilder());
184 * Feed event to the history system if it's known to cause a state
187 KernelEventHandler handler
= fEventNames
.get(eventName
);
188 if (handler
== null) {
189 if (isSyscallExit(eventName
)) {
190 handler
= fSysExitHandler
;
191 } else if (isSyscallEntry(eventName
)) {
192 handler
= fSysEntryHandler
;
195 if (handler
!= null) {
196 handler
.handleEvent(ss
, event
);
199 } catch (AttributeNotFoundException ae
) {
201 * This would indicate a problem with the logic of the manager here,
202 * so it shouldn't happen.
204 Activator
.instance().logError("Attribute not found: " + ae
.getMessage(), ae
); //$NON-NLS-1$
206 } catch (TimeRangeException tre
) {
208 * This would happen if the events in the trace aren't ordered
209 * chronologically, which should never be the case ...
211 Activator
.instance().logError("TimeRangeExcpetion caught in the state system's event manager.\n" + //$NON-NLS-1$
212 "Are the events in the trace correctly ordered?\n" + tre
.getMessage(), tre
); //$NON-NLS-1$
214 } catch (StateValueTypeException sve
) {
216 * This would happen if we were trying to push/pop attributes not of
217 * type integer. Which, once again, should never happen.
219 Activator
.instance().logError("State value error: " + sve
.getMessage(), sve
); //$NON-NLS-1$
223 private boolean isSyscallEntry(String eventName
) {
224 return (eventName
.startsWith(fLayout
.eventSyscallEntryPrefix())
225 || eventName
.startsWith(fLayout
.eventCompatSyscallEntryPrefix()));
228 private boolean isSyscallExit(String eventName
) {
229 return (eventName
.startsWith(fLayout
.eventSyscallExitPrefix()) ||
230 eventName
.startsWith(fLayout
.eventCompatSyscallExitPrefix()));