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 | */ | |
b46ea93c | 47 | private static final int VERSION = 1; |
a96cc6be | 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); | |
b46ea93c AM |
336 | if (value.isNull()) { |
337 | /* | |
338 | * Maybe we were missing info about the parent? At least we | |
339 | * will set the child right. Let's suppose "sys_clone". | |
340 | */ | |
341 | value = TmfStateValue.newValueString(LttngStrings.SYS_CLONE); | |
342 | } | |
79e0a1df AM |
343 | quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL); |
344 | ss.modifyAttribute(ts, value, quark); | |
345 | } | |
346 | break; | |
347 | ||
348 | case 9: // "sched_process_exit": | |
349 | /* Fields: string comm, int32 tid, int32 prio */ | |
350 | break; | |
351 | ||
352 | case 10: // "sched_process_free": | |
353 | /* Fields: string comm, int32 tid, int32 prio */ | |
354 | /* | |
355 | * A sched_process_free will always happen after the sched_switch | |
356 | * that will remove the process from the cpu for the last time. So | |
357 | * this is when we should delete everything wrt to the process. | |
358 | */ | |
359 | { | |
360 | Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); | |
361 | /* | |
362 | * Remove the process and all its sub-attributes from the | |
363 | * current state | |
364 | */ | |
6383e95d | 365 | quark = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString()); |
79e0a1df AM |
366 | ss.removeAttribute(ts, quark); |
367 | } | |
368 | break; | |
369 | ||
370 | case 11: // "lttng_statedump_process_state": | |
371 | /* Fields: | |
372 | * int32 type, int32 mode, int32 pid, int32 submode, int32 vpid, | |
373 | * int32 ppid, int32 tid, string name, int32 status, int32 vtid */ | |
374 | { | |
375 | Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue(); | |
376 | int ppid = ((Long) content.getField(LttngStrings.PPID).getValue()).intValue(); | |
377 | int status = ((Long) content.getField(LttngStrings.STATUS).getValue()).intValue(); | |
378 | String name = (String) content.getField(LttngStrings.NAME).getValue(); | |
379 | /* | |
380 | * "mode" could be interesting too, but it doesn't seem to be | |
381 | * populated with anything relevant for now. | |
382 | */ | |
383 | ||
6383e95d | 384 | int curThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString()); |
79e0a1df AM |
385 | |
386 | /* Set the process' name */ | |
387 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.EXEC_NAME); | |
388 | if (ss.queryOngoingState(quark).isNull()) { | |
389 | /* If the value didn't exist previously, set it */ | |
390 | value = TmfStateValue.newValueString(name); | |
391 | ss.modifyAttribute(ts, value, quark); | |
392 | } | |
393 | ||
394 | /* Set the process' PPID */ | |
395 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.PPID); | |
396 | if (ss.queryOngoingState(quark).isNull()) { | |
397 | value = TmfStateValue.newValueInt(ppid); | |
398 | ss.modifyAttribute(ts, value, quark); | |
399 | } | |
400 | ||
401 | /* Set the process' status */ | |
402 | quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.STATUS); | |
403 | if (ss.queryOngoingState(quark).isNull()) { | |
f2338178 MD |
404 | /* "2" here means "WAIT_FOR_CPU", and "5" "WAIT_BLOCKED" in the LTTng kernel. */ |
405 | if (status == 2) { | |
406 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_FOR_CPU); | |
407 | } else if (status == 5) { | |
408 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_BLOCKED); | |
79e0a1df AM |
409 | } else { |
410 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_UNKNOWN); | |
411 | } | |
412 | ss.modifyAttribute(ts, value, quark); | |
413 | } | |
414 | } | |
415 | break; | |
416 | ||
417 | default: | |
418 | /* Other event types not covered by the main switch */ | |
419 | { | |
420 | if (eventName.startsWith(LttngStrings.SYSCALL_PREFIX) | |
421 | || eventName.startsWith(LttngStrings.COMPAT_SYSCALL_PREFIX)) { | |
422 | /* | |
423 | * This is a replacement for the old sys_enter event. Now | |
424 | * syscall names are listed into the event type | |
425 | */ | |
426 | ||
427 | /* Assign the new system call to the process */ | |
428 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
429 | value = TmfStateValue.newValueString(eventName); | |
430 | ss.modifyAttribute(ts, value, quark); | |
431 | ||
432 | /* Put the process in system call mode */ | |
433 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
434 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_SYSCALL); | |
435 | ss.modifyAttribute(ts, value, quark); | |
436 | ||
437 | /* Put the CPU in system call (kernel) mode */ | |
438 | quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS); | |
439 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL); | |
440 | ss.modifyAttribute(ts, value, quark); | |
441 | } | |
442 | } | |
443 | break; | |
444 | } // End of big switch | |
445 | ||
79e0a1df AM |
446 | } catch (AttributeNotFoundException ae) { |
447 | /* | |
448 | * This would indicate a problem with the logic of the manager here, | |
449 | * so it shouldn't happen. | |
450 | */ | |
451 | ae.printStackTrace(); | |
452 | ||
453 | } catch (TimeRangeException tre) { | |
454 | /* | |
455 | * This would happen if the events in the trace aren't ordered | |
456 | * chronologically, which should never be the case ... | |
457 | */ | |
458 | System.err.println("TimeRangeExcpetion caught in the state system's event manager."); //$NON-NLS-1$ | |
459 | System.err.println("Are the events in the trace correctly ordered?"); //$NON-NLS-1$ | |
460 | tre.printStackTrace(); | |
461 | ||
462 | } catch (StateValueTypeException sve) { | |
463 | /* | |
464 | * This would happen if we were trying to push/pop attributes not of | |
465 | * type integer. Which, once again, should never happen. | |
466 | */ | |
467 | sve.printStackTrace(); | |
2c2f900e AM |
468 | } |
469 | } | |
470 | ||
6383e95d AM |
471 | // ------------------------------------------------------------------------ |
472 | // Convenience methods for commonly-used attribute tree locations | |
473 | // ------------------------------------------------------------------------ | |
474 | ||
475 | private int getNodeCPUs() { | |
476 | return ss.getQuarkAbsoluteAndAdd(Attributes.CPUS); | |
79e0a1df AM |
477 | } |
478 | ||
6383e95d AM |
479 | private int getNodeThreads() { |
480 | return ss.getQuarkAbsoluteAndAdd(Attributes.THREADS); | |
481 | } | |
482 | ||
483 | private int getNodeIRQs() { | |
484 | return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.IRQS); | |
485 | } | |
486 | ||
487 | private int getNodeSoftIRQs() { | |
488 | return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.SOFT_IRQS); | |
489 | } | |
490 | ||
491 | // ------------------------------------------------------------------------ | |
492 | // Workaround for the lack of switch-on-strings in Java < 7 | |
493 | // ------------------------------------------------------------------------ | |
494 | ||
79e0a1df AM |
495 | private static HashMap<String, Integer> fillEventNames() { |
496 | /* | |
497 | * TODO Replace with straight strings in the switch/case once we move to | |
498 | * Java 7 | |
499 | */ | |
500 | HashMap<String, Integer> map = new HashMap<String, Integer>(); | |
501 | ||
502 | map.put(LttngStrings.EXIT_SYSCALL, 1); | |
503 | map.put(LttngStrings.IRQ_HANDLER_ENTRY, 2); | |
504 | map.put(LttngStrings.IRQ_HANDLER_EXIT, 3); | |
505 | map.put(LttngStrings.SOFTIRQ_ENTRY, 4); | |
506 | map.put(LttngStrings.SOFTIRQ_EXIT, 5); | |
507 | map.put(LttngStrings.SOFTIRQ_RAISE, 6); | |
508 | map.put(LttngStrings.SCHED_SWITCH, 7); | |
509 | map.put(LttngStrings.SCHED_PROCESS_FORK, 8); | |
510 | map.put(LttngStrings.SCHED_PROCESS_EXIT, 9); | |
511 | map.put(LttngStrings.SCHED_PROCESS_FREE, 10); | |
512 | map.put(LttngStrings.STATEDUMP_PROCESS_STATE, 11); | |
513 | ||
514 | return map; | |
515 | } | |
516 | ||
517 | private int getEventIndex(String eventName) { | |
518 | Integer ret = knownEventNames.get(eventName); | |
519 | return (ret != null) ? ret : -1; | |
520 | } | |
521 | ||
6383e95d AM |
522 | // ------------------------------------------------------------------------ |
523 | // Advanced state-setting methods | |
524 | // ------------------------------------------------------------------------ | |
525 | ||
79e0a1df AM |
526 | /** |
527 | * When we want to set a process back to a "running" state, first check | |
528 | * its current System_call attribute. If there is a system call active, we | |
529 | * put the process back in the syscall state. If not, we put it back in | |
530 | * user mode state. | |
531 | */ | |
532 | private void setProcessToRunning(long ts, int currentThreadNode) | |
533 | throws AttributeNotFoundException, TimeRangeException, | |
534 | StateValueTypeException { | |
535 | int quark; | |
536 | ITmfStateValue value; | |
537 | ||
538 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL); | |
539 | if (ss.queryOngoingState(quark).isNull()) { | |
540 | /* We were in user mode before the interruption */ | |
541 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_USERMODE); | |
542 | } else { | |
543 | /* We were previously in kernel mode */ | |
544 | value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_SYSCALL); | |
545 | } | |
546 | quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS); | |
547 | ss.modifyAttribute(ts, value, quark); | |
548 | } | |
549 | ||
550 | /** | |
551 | * Similar logic as above, but to set the CPU's status when it's coming out | |
552 | * of an interruption. | |
553 | */ | |
554 | private void cpuExitInterrupt(long ts, int currentCpuNode, int currentThreadNode) | |
555 | throws StateValueTypeException, AttributeNotFoundException, | |
556 | TimeRangeException { | |
557 | int quark; | |
558 | ITmfStateValue value; | |
559 | ||
560 | quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.CURRENT_THREAD); | |
561 | if (ss.queryOngoingState(quark).unboxInt() > 0) { | |
562 | /* There was a process on the CPU */ | |
563 | quark = ss.getQuarkRelative(currentThreadNode, Attributes.SYSTEM_CALL); | |
564 | if (ss.queryOngoingState(quark).isNull()) { | |
565 | /* That process was in user mode */ | |
566 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE); | |
567 | } else { | |
568 | /* That process was in a system call */ | |
569 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL); | |
570 | } | |
571 | } else { | |
572 | /* There was no real process scheduled, CPU was idle */ | |
573 | value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IDLE); | |
2c2f900e | 574 | } |
79e0a1df AM |
575 | quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.STATUS); |
576 | ss.modifyAttribute(ts, value, quark); | |
efc403bb AM |
577 | } |
578 | } |