Commit | Line | Data |
---|---|---|
efc403bb | 1 | /******************************************************************************* |
94cce698 | 2 | * Copyright (c) 2012, 2013 Ericsson |
efc403bb AM |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
d85d2a6d | 5 | * |
efc403bb AM |
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 | |
d85d2a6d | 10 | * |
efc403bb AM |
11 | *******************************************************************************/ |
12 | ||
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider; | |
14 | ||
79e0a1df | 15 | import java.util.HashMap; |
efc403bb | 16 | |
79e0a1df AM |
17 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; |
18 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.LttngStrings; | |
19 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; | |
efc403bb AM |
20 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; |
21 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; | |
2c2f900e | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
79e0a1df AM |
23 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; | |
25 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; | |
26 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
27 | import org.eclipse.linuxtools.tmf.core.statesystem.AbstractStateChangeInput; | |
f1f86dfb | 28 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemBuilder; |
79e0a1df AM |
29 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
30 | import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; | |
efc403bb AM |
31 | |
32 | /** | |
33 | * This is the state change input plugin for TMF's state system which handles | |
34 | * the LTTng 2.0 kernel traces in CTF format. | |
d85d2a6d | 35 | * |
efc403bb | 36 | * It uses the reference handler defined in CTFKernelHandler.java. |
d85d2a6d | 37 | * |
efc403bb | 38 | * @author alexmont |
d85d2a6d | 39 | * |
efc403bb | 40 | */ |
79e0a1df | 41 | public class CtfKernelStateInput extends AbstractStateChangeInput { |
efc403bb | 42 | |
a96cc6be AM |
43 | /** |
44 | * Version number of this state provider. Please bump this if you modify the | |
45 | * contents of the generated state history in some way. | |
46 | */ | |
47 | private static final int VERSION = 0; | |
48 | ||
79e0a1df AM |
49 | /* Event names HashMap. TODO: This can be discarded once we move to Java 7 */ |
50 | private final HashMap<String, Integer> knownEventNames; | |
efc403bb | 51 | |
6383e95d AM |
52 | // ------------------------------------------------------------------------ |
53 | // Constructor | |
54 | // ------------------------------------------------------------------------ | |
efc403bb AM |
55 | |
56 | /** | |
57 | * Instantiate a new state provider plugin. | |
d85d2a6d AM |
58 | * |
59 | * @param trace | |
efc403bb | 60 | * The LTTng 2.0 kernel trace directory |
efc403bb | 61 | */ |
dc0f7bfe | 62 | public CtfKernelStateInput(CtfTmfTrace trace) { |
71f2da63 | 63 | super(trace, CtfTmfEvent.class, "LTTng Kernel"); //$NON-NLS-1$ |
79e0a1df | 64 | knownEventNames = fillEventNames(); |
2c2f900e | 65 | } |
efc403bb | 66 | |
6383e95d AM |
67 | // ------------------------------------------------------------------------ |
68 | // IStateChangeInput | |
69 | // ------------------------------------------------------------------------ | |
70 | ||
a96cc6be AM |
71 | @Override |
72 | public int getVersion() { | |
73 | return VERSION; | |
74 | } | |
75 | ||
2c2f900e | 76 | @Override |
f1f86dfb | 77 | public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) { |
79e0a1df AM |
78 | /* We can only set up the locations once the state system is assigned */ |
79 | super.assignTargetStateSystem(ssb); | |
2c2f900e | 80 | } |
efc403bb | 81 | |
e96ab5c4 AM |
82 | @Override |
83 | public CtfKernelStateInput getNewInstance() { | |
84 | return new CtfKernelStateInput((CtfTmfTrace) this.getTrace()); | |
85 | } | |
86 | ||
efc403bb | 87 | @Override |
79e0a1df | 88 | protected void eventHandle(ITmfEvent ev) { |
79044a66 AM |
89 | /* |
90 | * AbstractStateChangeInput should have already checked for the correct | |
91 | * class type | |
92 | */ | |
79e0a1df AM |
93 | CtfTmfEvent event = (CtfTmfEvent) ev; |
94 | ||
95 | int quark; | |
96 | ITmfStateValue value; | |
97 | ||
98 | final ITmfEventField content = event.getContent(); | |
99 | final String eventName = event.getEventName(); | |
100 | final long ts = event.getTimestamp().getValue(); | |
101 | ||
2c2f900e | 102 | try { |
79e0a1df | 103 | /* Shortcut for the "current CPU" attribute node */ |
6383e95d | 104 | final Integer currentCPUNode = ss.getQuarkRelativeAndAdd(getNodeCPUs(), String.valueOf(event.getCPU())); |
79e0a1df AM |
105 | |
106 | /* | |
107 | * Shortcut for the "current thread" attribute node. It requires | |
108 | * querying the current CPU's current thread. | |
109 | */ | |
110 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD); | |
111 | value = ss.queryOngoingState(quark); | |
112 | int thread = value.unboxInt(); | |
6383e95d | 113 | final Integer currentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(thread)); |
79e0a1df AM |
114 | |
115 | /* | |
116 | * Feed event to the history system if it's known to cause a state | |
117 | * transition. | |
118 | */ | |
119 | switch (getEventIndex(eventName)) { | |
120 | ||
121 | case 1: // "exit_syscall": | |
122 | /* Fields: int64 ret */ | |
123 | { | |
124 | /* Clear the current system call on the process */ | |
125 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
126 | value = TmfStateValue.nullValue(); | |
127 | ss.modifyAttribute(ts, value, quark); | |
128 | ||
129 | /* Put the process' status back to user mode */ | |
130 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
131 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_USERMODE); | |
132 | ss.modifyAttribute(ts, value, quark); | |
133 | ||
134 | /* Put the CPU's status back to user mode */ | |
135 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
136 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE); | |
137 | ss.modifyAttribute(ts, value, quark); | |
138 | } | |
139 | break; | |
140 | ||
141 | case 2: // "irq_handler_entry": | |
142 | /* Fields: int32 irq, string name */ | |
143 | { | |
144 | Integer irqId = ((Long) content.getField(LttngStrings.IRQ).getValue()).intValue(); | |
145 | ||
146 | /* Mark this IRQ as active in the resource tree. | |
147 | * The state value = the CPU on which this IRQ is sitting */ | |
6383e95d | 148 | quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString()); |
79e0a1df AM |
149 | value = TmfStateValue.newValueInt(event.getCPU()); |
150 | ss.modifyAttribute(ts, value, quark); | |
151 | ||
152 | /* Change the status of the running process to interrupted */ | |
153 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
154 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_INTERRUPTED); | |
155 | ss.modifyAttribute(ts, value, quark); | |
156 | ||
157 | /* Change the status of the CPU to interrupted */ | |
158 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
159 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IRQ); | |
160 | ss.modifyAttribute(ts, value, quark); | |
161 | } | |
162 | break; | |
163 | ||
164 | case 3: // "irq_handler_exit": | |
165 | /* Fields: int32 irq, int32 ret */ | |
166 | { | |
167 | Integer irqId = ((Long) content.getField(LttngStrings.IRQ).getValue()).intValue(); | |
168 | ||
169 | /* Put this IRQ back to inactive in the resource tree */ | |
6383e95d | 170 | quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString()); |
79e0a1df AM |
171 | value = TmfStateValue.nullValue(); |
172 | ss.modifyAttribute(ts, value, quark); | |
173 | ||
174 | /* Set the previous process back to running */ | |
175 | setProcessToRunning(ts, currentThreadNode); | |
176 | ||
177 | /* Set the CPU status back to running or "idle" */ | |
178 | cpuExitInterrupt(ts, currentCPUNode, currentThreadNode); | |
179 | } | |
180 | break; | |
181 | ||
182 | case 4: // "softirq_entry": | |
183 | /* Fields: int32 vec */ | |
184 | { | |
185 | Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue(); | |
186 | ||
187 | /* Mark this SoftIRQ as active in the resource tree. | |
188 | * The state value = the CPU on which this SoftIRQ is processed */ | |
6383e95d | 189 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
79e0a1df AM |
190 | value = TmfStateValue.newValueInt(event.getCPU()); |
191 | ss.modifyAttribute(ts, value, quark); | |
192 | ||
193 | /* Change the status of the running process to interrupted */ | |
194 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
195 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_INTERRUPTED); | |
196 | ss.modifyAttribute(ts, value, quark); | |
197 | ||
198 | /* Change the status of the CPU to interrupted */ | |
199 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
200 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_SOFTIRQ); | |
201 | ss.modifyAttribute(ts, value, quark); | |
202 | } | |
203 | break; | |
204 | ||
205 | case 5: // "softirq_exit": | |
206 | /* Fields: int32 vec */ | |
207 | { | |
208 | Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue(); | |
209 | ||
210 | /* Put this SoftIRQ back to inactive (= -1) in the resource tree */ | |
6383e95d | 211 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
79e0a1df AM |
212 | value = TmfStateValue.nullValue(); |
213 | ss.modifyAttribute(ts, value, quark); | |
214 | ||
215 | /* Set the previous process back to running */ | |
216 | setProcessToRunning(ts, currentThreadNode); | |
217 | ||
218 | /* Set the CPU status back to "busy" or "idle" */ | |
219 | cpuExitInterrupt(ts, currentCPUNode, currentThreadNode); | |
220 | } | |
221 | break; | |
222 | ||
223 | case 6: // "softirq_raise": | |
224 | /* Fields: int32 vec */ | |
225 | { | |
226 | Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue(); | |
227 | ||
228 | /* Mark this SoftIRQ as *raised* in the resource tree. | |
229 | * State value = -2 */ | |
6383e95d | 230 | quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString()); |
79e0a1df AM |
231 | value = TmfStateValue.newValueInt(StateValues.SOFT_IRQ_RAISED); |
232 | ss.modifyAttribute(ts, value, quark); | |
233 | } | |
234 | break; | |
235 | ||
236 | case 7: // "sched_switch": | |
237 | /* | |
238 | * Fields: string prev_comm, int32 prev_tid, int32 prev_prio, int64 prev_state, | |
239 | * string next_comm, int32 next_tid, int32 next_prio | |
240 | */ | |
241 | { | |
242 | Integer prevTid = ((Long) content.getField(LttngStrings.PREV_TID).getValue()).intValue(); | |
f2338178 | 243 | Long prevState = (Long) content.getField(LttngStrings.PREV_STATE).getValue(); |
79e0a1df AM |
244 | String nextProcessName = (String) content.getField(LttngStrings.NEXT_COMM).getValue(); |
245 | Integer nextTid = ((Long) content.getField(LttngStrings.NEXT_TID).getValue()).intValue(); | |
246 | ||
6383e95d AM |
247 | Integer formerThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), prevTid.toString()); |
248 | Integer newCurrentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), nextTid.toString()); | |
79e0a1df AM |
249 | |
250 | /* Set the status of the process that got scheduled out. */ | |
251 | quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS); | |
f2338178 MD |
252 | if (prevState != 0) { |
253 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_BLOCKED); | |
254 | } else { | |
255 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_FOR_CPU); | |
256 | } | |
79e0a1df AM |
257 | ss.modifyAttribute(ts, value, quark); |
258 | ||
259 | /* Set the status of the new scheduled process */ | |
260 | setProcessToRunning(ts, newCurrentThreadNode); | |
261 | ||
262 | /* Set the exec name of the new process */ | |
263 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.EXEC_NAME); | |
264 | value = TmfStateValue.newValueString(nextProcessName); | |
265 | ss.modifyAttribute(ts, value, quark); | |
266 | ||
267 | /* | |
268 | * Check if we need to set the syscall state and the PPID of | |
269 | * the new process (in case we haven't seen this process before) | |
270 | */ | |
271 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL); | |
272 | if (ss.isLastAttribute(quark)) { /* Did we just add this attribute? */ | |
273 | value = TmfStateValue.nullValue(); | |
274 | ss.modifyAttribute(ts, value, quark); | |
275 | } | |
276 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.PPID); | |
277 | if (ss.isLastAttribute(quark)) { | |
278 | value = TmfStateValue.nullValue(); | |
279 | ss.modifyAttribute(ts, value, quark); | |
280 | } | |
281 | ||
282 | /* Set the current scheduled process on the relevant CPU */ | |
283 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD); | |
284 | value = TmfStateValue.newValueInt(nextTid); | |
285 | ss.modifyAttribute(ts, value, quark); | |
286 | ||
287 | /* Set the status of the CPU itself */ | |
288 | if (nextTid > 0) { | |
289 | /* Check if the entering process is in kernel or user mode */ | |
290 | quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL); | |
291 | if (ss.queryOngoingState(quark).isNull()) { | |
292 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE); | |
293 | } else { | |
294 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL); | |
295 | } | |
296 | } else { | |
297 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IDLE); | |
298 | } | |
299 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
300 | ss.modifyAttribute(ts, value, quark); | |
301 | } | |
302 | break; | |
303 | ||
304 | case 8: // "sched_process_fork": | |
305 | /* Fields: string parent_comm, int32 parent_tid, | |
306 | * string child_comm, int32 child_tid */ | |
307 | { | |
308 | // String parentProcessName = (String) event.getFieldValue("parent_comm"); | |
309 | String childProcessName = (String) content.getField(LttngStrings.CHILD_COMM).getValue(); | |
310 | // assert ( parentProcessName.equals(childProcessName) ); | |
311 | ||
312 | Integer parentTid = ((Long) content.getField(LttngStrings.PARENT_TID).getValue()).intValue(); | |
313 | Integer childTid = ((Long) content.getField(LttngStrings.CHILD_TID).getValue()).intValue(); | |
314 | ||
6383e95d AM |
315 | Integer parentTidNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), parentTid.toString()); |
316 | Integer childTidNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), childTid.toString()); | |
79e0a1df AM |
317 | |
318 | /* Assign the PPID to the new process */ | |
319 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.PPID); | |
320 | value = TmfStateValue.newValueInt(parentTid); | |
321 | ss.modifyAttribute(ts, value, quark); | |
322 | ||
323 | /* Set the new process' exec_name */ | |
324 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.EXEC_NAME); | |
325 | value = TmfStateValue.newValueString(childProcessName); | |
326 | ss.modifyAttribute(ts, value, quark); | |
327 | ||
328 | /* Set the new process' status */ | |
329 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.STATUS); | |
f2338178 | 330 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_FOR_CPU); |
79e0a1df AM |
331 | ss.modifyAttribute(ts, value, quark); |
332 | ||
333 | /* Set the process' syscall name, to be the same as the parent's */ | |
334 | quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL); | |
335 | value = ss.queryOngoingState(quark); | |
336 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL); | |
337 | ss.modifyAttribute(ts, value, quark); | |
338 | } | |
339 | break; | |
340 | ||
341 | case 9: // "sched_process_exit": | |
342 | /* Fields: string comm, int32 tid, int32 prio */ | |
343 | break; | |
344 | ||
345 | case 10: // "sched_process_free": | |
346 | /* Fields: string comm, int32 tid, int32 prio */ | |
347 | /* | |
348 | * A sched_process_free will always happen after the sched_switch | |
349 | * that will remove the process from the cpu for the last time. So | |
350 | * this is when we should delete everything wrt to the process. | |
351 | */ | |
352 | { | |
353 | Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); | |
354 | /* | |
355 | * Remove the process and all its sub-attributes from the | |
356 | * current state | |
357 | */ | |
6383e95d | 358 | quark = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString()); |
79e0a1df AM |
359 | ss.removeAttribute(ts, quark); |
360 | } | |
361 | break; | |
362 | ||
363 | case 11: // "lttng_statedump_process_state": | |
364 | /* Fields: | |
365 | * int32 type, int32 mode, int32 pid, int32 submode, int32 vpid, | |
366 | * int32 ppid, int32 tid, string name, int32 status, int32 vtid */ | |
367 | { | |
368 | Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); | |
369 | int ppid = ((Long) content.getField(LttngStrings.PPID).getValue()).intValue(); | |
370 | int status = ((Long) content.getField(LttngStrings.STATUS).getValue()).intValue(); | |
371 | String name = (String) content.getField(LttngStrings.NAME).getValue(); | |
372 | /* | |
373 | * "mode" could be interesting too, but it doesn't seem to be | |
374 | * populated with anything relevant for now. | |
375 | */ | |
376 | ||
6383e95d | 377 | int curThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString()); |
79e0a1df AM |
378 | |
379 | /* Set the process' name */ | |
380 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.EXEC_NAME); | |
381 | if (ss.queryOngoingState(quark).isNull()) { | |
382 | /* If the value didn't exist previously, set it */ | |
383 | value = TmfStateValue.newValueString(name); | |
384 | ss.modifyAttribute(ts, value, quark); | |
385 | } | |
386 | ||
387 | /* Set the process' PPID */ | |
388 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.PPID); | |
389 | if (ss.queryOngoingState(quark).isNull()) { | |
390 | value = TmfStateValue.newValueInt(ppid); | |
391 | ss.modifyAttribute(ts, value, quark); | |
392 | } | |
393 | ||
394 | /* Set the process' status */ | |
395 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.STATUS); | |
396 | if (ss.queryOngoingState(quark).isNull()) { | |
f2338178 MD |
397 | /* "2" here means "WAIT_FOR_CPU", and "5" "WAIT_BLOCKED" in the LTTng kernel. */ |
398 | if (status == 2) { | |
399 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_FOR_CPU); | |
400 | } else if (status == 5) { | |
401 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_BLOCKED); | |
79e0a1df AM |
402 | } else { |
403 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_UNKNOWN); | |
404 | } | |
405 | ss.modifyAttribute(ts, value, quark); | |
406 | } | |
407 | } | |
408 | break; | |
409 | ||
410 | default: | |
411 | /* Other event types not covered by the main switch */ | |
412 | { | |
413 | if (eventName.startsWith(LttngStrings.SYSCALL_PREFIX) | |
414 | || eventName.startsWith(LttngStrings.COMPAT_SYSCALL_PREFIX)) { | |
415 | /* | |
416 | * This is a replacement for the old sys_enter event. Now | |
417 | * syscall names are listed into the event type | |
418 | */ | |
419 | ||
420 | /* Assign the new system call to the process */ | |
421 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
422 | value = TmfStateValue.newValueString(eventName); | |
423 | ss.modifyAttribute(ts, value, quark); | |
424 | ||
425 | /* Put the process in system call mode */ | |
426 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
427 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_SYSCALL); | |
428 | ss.modifyAttribute(ts, value, quark); | |
429 | ||
430 | /* Put the CPU in system call (kernel) mode */ | |
431 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
432 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL); | |
433 | ss.modifyAttribute(ts, value, quark); | |
434 | } | |
435 | } | |
436 | break; | |
437 | } // End of big switch | |
438 | ||
79e0a1df AM |
439 | } catch (AttributeNotFoundException ae) { |
440 | /* | |
441 | * This would indicate a problem with the logic of the manager here, | |
442 | * so it shouldn't happen. | |
443 | */ | |
444 | ae.printStackTrace(); | |
445 | ||
446 | } catch (TimeRangeException tre) { | |
447 | /* | |
448 | * This would happen if the events in the trace aren't ordered | |
449 | * chronologically, which should never be the case ... | |
450 | */ | |
451 | System.err.println("TimeRangeExcpetion caught in the state system's event manager."); //$NON-NLS-1$ | |
452 | System.err.println("Are the events in the trace correctly ordered?"); //$NON-NLS-1$ | |
453 | tre.printStackTrace(); | |
454 | ||
455 | } catch (StateValueTypeException sve) { | |
456 | /* | |
457 | * This would happen if we were trying to push/pop attributes not of | |
458 | * type integer. Which, once again, should never happen. | |
459 | */ | |
460 | sve.printStackTrace(); | |
2c2f900e AM |
461 | } |
462 | } | |
463 | ||
6383e95d AM |
464 | // ------------------------------------------------------------------------ |
465 | // Convenience methods for commonly-used attribute tree locations | |
466 | // ------------------------------------------------------------------------ | |
467 | ||
468 | private int getNodeCPUs() { | |
469 | return ss.getQuarkAbsoluteAndAdd(Attributes.CPUS); | |
79e0a1df AM |
470 | } |
471 | ||
6383e95d AM |
472 | private int getNodeThreads() { |
473 | return ss.getQuarkAbsoluteAndAdd(Attributes.THREADS); | |
474 | } | |
475 | ||
476 | private int getNodeIRQs() { | |
477 | return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.IRQS); | |
478 | } | |
479 | ||
480 | private int getNodeSoftIRQs() { | |
481 | return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.SOFT_IRQS); | |
482 | } | |
483 | ||
484 | // ------------------------------------------------------------------------ | |
485 | // Workaround for the lack of switch-on-strings in Java < 7 | |
486 | // ------------------------------------------------------------------------ | |
487 | ||
79e0a1df AM |
488 | private static HashMap<String, Integer> fillEventNames() { |
489 | /* | |
490 | * TODO Replace with straight strings in the switch/case once we move to | |
491 | * Java 7 | |
492 | */ | |
493 | HashMap<String, Integer> map = new HashMap<String, Integer>(); | |
494 | ||
495 | map.put(LttngStrings.EXIT_SYSCALL, 1); | |
496 | map.put(LttngStrings.IRQ_HANDLER_ENTRY, 2); | |
497 | map.put(LttngStrings.IRQ_HANDLER_EXIT, 3); | |
498 | map.put(LttngStrings.SOFTIRQ_ENTRY, 4); | |
499 | map.put(LttngStrings.SOFTIRQ_EXIT, 5); | |
500 | map.put(LttngStrings.SOFTIRQ_RAISE, 6); | |
501 | map.put(LttngStrings.SCHED_SWITCH, 7); | |
502 | map.put(LttngStrings.SCHED_PROCESS_FORK, 8); | |
503 | map.put(LttngStrings.SCHED_PROCESS_EXIT, 9); | |
504 | map.put(LttngStrings.SCHED_PROCESS_FREE, 10); | |
505 | map.put(LttngStrings.STATEDUMP_PROCESS_STATE, 11); | |
506 | ||
507 | return map; | |
508 | } | |
509 | ||
510 | private int getEventIndex(String eventName) { | |
511 | Integer ret = knownEventNames.get(eventName); | |
512 | return (ret != null) ? ret : -1; | |
513 | } | |
514 | ||
6383e95d AM |
515 | // ------------------------------------------------------------------------ |
516 | // Advanced state-setting methods | |
517 | // ------------------------------------------------------------------------ | |
518 | ||
79e0a1df AM |
519 | /** |
520 | * When we want to set a process back to a "running" state, first check | |
521 | * its current System_call attribute. If there is a system call active, we | |
522 | * put the process back in the syscall state. If not, we put it back in | |
523 | * user mode state. | |
524 | */ | |
525 | private void setProcessToRunning(long ts, int currentThreadNode) | |
526 | throws AttributeNotFoundException, TimeRangeException, | |
527 | StateValueTypeException { | |
528 | int quark; | |
529 | ITmfStateValue value; | |
530 | ||
531 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
532 | if (ss.queryOngoingState(quark).isNull()) { | |
533 | /* We were in user mode before the interruption */ | |
534 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_USERMODE); | |
535 | } else { | |
536 | /* We were previously in kernel mode */ | |
537 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_SYSCALL); | |
538 | } | |
539 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
540 | ss.modifyAttribute(ts, value, quark); | |
541 | } | |
542 | ||
543 | /** | |
544 | * Similar logic as above, but to set the CPU's status when it's coming out | |
545 | * of an interruption. | |
546 | */ | |
547 | private void cpuExitInterrupt(long ts, int currentCpuNode, int currentThreadNode) | |
548 | throws StateValueTypeException, AttributeNotFoundException, | |
549 | TimeRangeException { | |
550 | int quark; | |
551 | ITmfStateValue value; | |
552 | ||
553 | quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.CURRENT_THREAD); | |
554 | if (ss.queryOngoingState(quark).unboxInt() > 0) { | |
555 | /* There was a process on the CPU */ | |
556 | quark = ss.getQuarkRelative(currentThreadNode, Attributes.SYSTEM_CALL); | |
557 | if (ss.queryOngoingState(quark).isNull()) { | |
558 | /* That process was in user mode */ | |
559 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE); | |
560 | } else { | |
561 | /* That process was in a system call */ | |
562 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL); | |
563 | } | |
564 | } else { | |
565 | /* There was no real process scheduled, CPU was idle */ | |
566 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IDLE); | |
2c2f900e | 567 | } |
79e0a1df AM |
568 | quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.STATUS); |
569 | ss.modifyAttribute(ts, value, quark); | |
efc403bb AM |
570 | } |
571 | } |