os.linux: Create PPID and SYSTEM_CALL attributes on demand
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / internal / analysis / os / linux / core / kernel / KernelStateProvider.java
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>
5 *
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
10 *
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel;
14
15 import java.util.Map;
16
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;
45
46 import com.google.common.collect.ImmutableMap;
47
48 /**
49 * This is the state change input plugin for the state system which handles the
50 * kernel traces.
51 *
52 * @author Alexandre Montplaisir
53 */
54 public class KernelStateProvider extends AbstractTmfStateProvider {
55
56 // ------------------------------------------------------------------------
57 // Static fields
58 // ------------------------------------------------------------------------
59
60 /**
61 * Version number of this state provider. Please bump this if you modify the
62 * contents of the generated state history in some way.
63 */
64 private static final int VERSION = 21;
65
66 // ------------------------------------------------------------------------
67 // Fields
68 // ------------------------------------------------------------------------
69
70 private final Map<String, KernelEventHandler> fEventNames;
71 private final IKernelAnalysisEventLayout fLayout;
72
73 private final KernelEventHandler fSysEntryHandler;
74 private final KernelEventHandler fSysExitHandler;
75
76 // ------------------------------------------------------------------------
77 // Constructor
78 // ------------------------------------------------------------------------
79
80 /**
81 * Instantiate a new state provider plugin.
82 *
83 * @param trace
84 * The LTTng 2.0 kernel trace directory
85 * @param layout
86 * The event layout to use for this state provider. Usually
87 * depending on the tracer implementation.
88 */
89 public KernelStateProvider(ITmfTrace trace, IKernelAnalysisEventLayout layout) {
90 super(trace, "Kernel"); //$NON-NLS-1$
91 fLayout = layout;
92 fEventNames = buildEventNames(layout);
93
94 fSysEntryHandler = new SysEntryHandler(fLayout);
95 fSysExitHandler = new SysExitHandler(fLayout);
96 }
97
98 // ------------------------------------------------------------------------
99 // Event names management
100 // ------------------------------------------------------------------------
101
102 private static Map<String, KernelEventHandler> buildEventNames(IKernelAnalysisEventLayout layout) {
103 ImmutableMap.Builder<String, KernelEventHandler> builder = ImmutableMap.builder();
104
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));
115 for( String s : layout.getIPIIrqVectorsEntries()) {
116 builder.put(s, new IPIEntryHandler(layout));
117 }
118 for( String s : layout.getIPIIrqVectorsExits()) {
119 builder.put(s, new IPIExitHandler(layout));
120 }
121
122 final String eventStatedumpProcessState = layout.eventStatedumpProcessState();
123 if (eventStatedumpProcessState != null) {
124 builder.put(eventStatedumpProcessState, new StateDumpHandler(layout));
125 }
126
127 for (String eventSchedWakeup : layout.eventsSchedWakeup()) {
128 builder.put(eventSchedWakeup, new SchedWakeupHandler(layout));
129 }
130
131 return builder.build();
132 }
133
134 // ------------------------------------------------------------------------
135 // IStateChangeInput
136 // ------------------------------------------------------------------------
137
138 @Override
139 public int getVersion() {
140 return VERSION;
141 }
142
143 @Override
144 public KernelStateProvider getNewInstance() {
145 return new KernelStateProvider(this.getTrace(), fLayout);
146 }
147
148 @Override
149 protected void eventHandle(@Nullable ITmfEvent event) {
150 if (event == null) {
151 return;
152 }
153
154 final String eventName = event.getName();
155
156 try {
157 final ITmfStateSystemBuilder ss = NonNullUtils.checkNotNull(getStateSystemBuilder());
158 /*
159 * Feed event to the history system if it's known to cause a state
160 * transition.
161 */
162 KernelEventHandler handler = fEventNames.get(eventName);
163 if (handler == null) {
164 if (isSyscallExit(eventName)) {
165 handler = fSysExitHandler;
166 } else if (isSyscallEntry(eventName)) {
167 handler = fSysEntryHandler;
168 }
169 }
170 if (handler != null) {
171 handler.handleEvent(ss, event);
172 }
173
174 } catch (AttributeNotFoundException ae) {
175 /*
176 * This would indicate a problem with the logic of the manager here,
177 * so it shouldn't happen.
178 */
179 Activator.getDefault().logError("Attribute not found: " + ae.getMessage(), ae); //$NON-NLS-1$
180
181 } catch (TimeRangeException tre) {
182 /*
183 * This would happen if the events in the trace aren't ordered
184 * chronologically, which should never be the case ...
185 */
186 Activator.getDefault().logError("TimeRangeExcpetion caught in the state system's event manager.\n" + //$NON-NLS-1$
187 "Are the events in the trace correctly ordered?\n" + tre.getMessage(), tre); //$NON-NLS-1$
188
189 } catch (StateValueTypeException sve) {
190 /*
191 * This would happen if we were trying to push/pop attributes not of
192 * type integer. Which, once again, should never happen.
193 */
194 Activator.getDefault().logError("State value error: " + sve.getMessage(), sve); //$NON-NLS-1$
195 }
196 }
197
198 private boolean isSyscallEntry(String eventName) {
199 return (eventName.startsWith(fLayout.eventSyscallEntryPrefix())
200 || eventName.startsWith(fLayout.eventCompatSyscallEntryPrefix()));
201 }
202
203 private boolean isSyscallExit(String eventName) {
204 return (eventName.startsWith(fLayout.eventSyscallExitPrefix()) ||
205 eventName.startsWith(fLayout.eventCompatSyscallExitPrefix()));
206 }
207
208 }
This page took 0.041316 seconds and 5 git commands to generate.