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
.IPIEntryHandler
;
22 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.IPIExitHandler
;
23 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.IrqEntryHandler
;
24 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.IrqExitHandler
;
25 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.KernelEventHandler
;
26 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.PiSetprioHandler
;
27 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.ProcessExitHandler
;
28 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.ProcessForkHandler
;
29 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.ProcessFreeHandler
;
30 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SchedSwitchHandler
;
31 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SchedWakeupHandler
;
32 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SoftIrqEntryHandler
;
33 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SoftIrqExitHandler
;
34 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SoftIrqRaiseHandler
;
35 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.StateDumpHandler
;
36 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SysEntryHandler
;
37 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.handlers
.SysExitHandler
;
38 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
39 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
40 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
41 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
46 import com
.google
.common
.collect
.ImmutableMap
;
49 * This is the state change input plugin for the state system which handles the
56 * | |- <CPU number> -> CPU Status
57 * | | |- CURRENT_THREAD
59 * | | | |- <Soft IRQ number> -> Soft IRQ Status
61 * | | | |- <IRQ number> -> IRQ Status
63 * | |- <Thread number> -> Thread Status
70 * @author Alexandre Montplaisir
72 public class KernelStateProvider
extends AbstractTmfStateProvider
{
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * Version number of this state provider. Please bump this if you modify the
80 * contents of the generated state history in some way.
82 private static final int VERSION
= 21;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
88 private final Map
<String
, KernelEventHandler
> fEventNames
;
89 private final IKernelAnalysisEventLayout fLayout
;
91 private final KernelEventHandler fSysEntryHandler
;
92 private final KernelEventHandler fSysExitHandler
;
94 // ------------------------------------------------------------------------
96 // ------------------------------------------------------------------------
99 * Instantiate a new state provider plugin.
102 * The LTTng 2.0 kernel trace directory
104 * The event layout to use for this state provider. Usually
105 * depending on the tracer implementation.
107 public KernelStateProvider(ITmfTrace trace
, IKernelAnalysisEventLayout layout
) {
108 super(trace
, "Kernel"); //$NON-NLS-1$
110 fEventNames
= buildEventNames(layout
);
112 fSysEntryHandler
= new SysEntryHandler(fLayout
);
113 fSysExitHandler
= new SysExitHandler(fLayout
);
116 // ------------------------------------------------------------------------
117 // Event names management
118 // ------------------------------------------------------------------------
120 private static Map
<String
, KernelEventHandler
> buildEventNames(IKernelAnalysisEventLayout layout
) {
121 ImmutableMap
.Builder
<String
, KernelEventHandler
> builder
= ImmutableMap
.builder();
123 builder
.put(layout
.eventIrqHandlerEntry(), new IrqEntryHandler(layout
));
124 builder
.put(layout
.eventIrqHandlerExit(), new IrqExitHandler(layout
));
125 builder
.put(layout
.eventSoftIrqEntry(), new SoftIrqEntryHandler(layout
));
126 builder
.put(layout
.eventSoftIrqExit(), new SoftIrqExitHandler(layout
));
127 builder
.put(layout
.eventSoftIrqRaise(), new SoftIrqRaiseHandler(layout
));
128 builder
.put(layout
.eventSchedSwitch(), new SchedSwitchHandler(layout
));
129 builder
.put(layout
.eventSchedPiSetprio(), new PiSetprioHandler(layout
));
130 builder
.put(layout
.eventSchedProcessFork(), new ProcessForkHandler(layout
));
131 builder
.put(layout
.eventSchedProcessExit(), new ProcessExitHandler(layout
));
132 builder
.put(layout
.eventSchedProcessFree(), new ProcessFreeHandler(layout
));
133 for( String s
: layout
.getIPIIrqVectorsEntries()) {
134 builder
.put(s
, new IPIEntryHandler(layout
));
136 for( String s
: layout
.getIPIIrqVectorsExits()) {
137 builder
.put(s
, new IPIExitHandler(layout
));
140 final String eventStatedumpProcessState
= layout
.eventStatedumpProcessState();
141 if (eventStatedumpProcessState
!= null) {
142 builder
.put(eventStatedumpProcessState
, new StateDumpHandler(layout
));
145 for (String eventSchedWakeup
: layout
.eventsSchedWakeup()) {
146 builder
.put(eventSchedWakeup
, new SchedWakeupHandler(layout
));
149 return builder
.build();
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
157 public int getVersion() {
162 public KernelStateProvider
getNewInstance() {
163 return new KernelStateProvider(this.getTrace(), fLayout
);
167 protected void eventHandle(@Nullable ITmfEvent event
) {
172 final String eventName
= event
.getName();
175 final ITmfStateSystemBuilder ss
= NonNullUtils
.checkNotNull(getStateSystemBuilder());
177 * Feed event to the history system if it's known to cause a state
180 KernelEventHandler handler
= fEventNames
.get(eventName
);
181 if (handler
== null) {
182 if (isSyscallExit(eventName
)) {
183 handler
= fSysExitHandler
;
184 } else if (isSyscallEntry(eventName
)) {
185 handler
= fSysEntryHandler
;
188 if (handler
!= null) {
189 handler
.handleEvent(ss
, event
);
192 } catch (AttributeNotFoundException ae
) {
194 * This would indicate a problem with the logic of the manager here,
195 * so it shouldn't happen.
197 Activator
.getDefault().logError("Attribute not found: " + ae
.getMessage(), ae
); //$NON-NLS-1$
199 } catch (TimeRangeException tre
) {
201 * This would happen if the events in the trace aren't ordered
202 * chronologically, which should never be the case ...
204 Activator
.getDefault().logError("TimeRangeExcpetion caught in the state system's event manager.\n" + //$NON-NLS-1$
205 "Are the events in the trace correctly ordered?\n" + tre
.getMessage(), tre
); //$NON-NLS-1$
207 } catch (StateValueTypeException sve
) {
209 * This would happen if we were trying to push/pop attributes not of
210 * type integer. Which, once again, should never happen.
212 Activator
.getDefault().logError("State value error: " + sve
.getMessage(), sve
); //$NON-NLS-1$
216 private boolean isSyscallEntry(String eventName
) {
217 return (eventName
.startsWith(fLayout
.eventSyscallEntryPrefix())
218 || eventName
.startsWith(fLayout
.eventCompatSyscallEntryPrefix()));
221 private boolean isSyscallExit(String eventName
) {
222 return (eventName
.startsWith(fLayout
.eventSyscallExitPrefix()) ||
223 eventName
.startsWith(fLayout
.eventCompatSyscallExitPrefix()));