/*******************************************************************************
- * Copyright (c) 2012, 2013 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
* Copyright (c) 2010, 2011 École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
*
package org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider;
-import java.util.HashMap;
-
import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
import org.eclipse.linuxtools.internal.lttng2.kernel.core.LttngStrings;
import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystemBuilder;
+import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.statesystem.core.statevalue.TmfStateValue;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemBuilder;
-import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
-import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
+import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
/**
* This is the state change input plugin for TMF's state system which handles
* Version number of this state provider. Please bump this if you modify the
* contents of the generated state history in some way.
*/
- private static final int VERSION = 3;
-
- /* Event names HashMap. TODO: This can be discarded once we move to Java 7 */
- private final HashMap<String, Integer> knownEventNames;
+ private static final int VERSION = 4;
// ------------------------------------------------------------------------
// Constructor
*/
public LttngKernelStateProvider(CtfTmfTrace trace) {
super(trace, CtfTmfEvent.class, "LTTng Kernel"); //$NON-NLS-1$
- knownEventNames = fillEventNames();
}
// ------------------------------------------------------------------------
* AbstractStateChangeInput should have already checked for the correct
* class type
*/
- CtfTmfEvent event = (CtfTmfEvent) ev;
-
- int quark;
- ITmfStateValue value;
+ final CtfTmfEvent event = (CtfTmfEvent) ev;
- final ITmfEventField content = event.getContent();
- final String eventName = event.getEventName();
+ final String eventName = event.getType().getName();
final long ts = event.getTimestamp().getValue();
try {
* Shortcut for the "current thread" attribute node. It requires
* querying the current CPU's current thread.
*/
- quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
- value = ss.queryOngoingState(quark);
- int thread = value.unboxInt();
+ int quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
+ ITmfStateValue value = ss.queryOngoingState(quark);
+ int thread = value.isNull() ? -1 : value.unboxInt();
final Integer currentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(thread));
/*
* Feed event to the history system if it's known to cause a state
* transition.
*/
- switch (getEventIndex(eventName)) {
+ switch (eventName) {
- case 1: // "exit_syscall":
+ case LttngStrings.EXIT_SYSCALL:
/* Fields: int64 ret */
{
/* Clear the current system call on the process */
}
break;
- case 2: // "irq_handler_entry":
+ case LttngStrings.IRQ_HANDLER_ENTRY:
/* Fields: int32 irq, string name */
{
- Integer irqId = ((Long) content.getField(LttngStrings.IRQ).getValue()).intValue();
+ Integer irqId = ((Long) event.getContent().getField(LttngStrings.IRQ).getValue()).intValue();
/* Mark this IRQ as active in the resource tree.
* The state value = the CPU on which this IRQ is sitting */
}
break;
- case 3: // "irq_handler_exit":
+ case LttngStrings.IRQ_HANDLER_EXIT:
/* Fields: int32 irq, int32 ret */
{
- Integer irqId = ((Long) content.getField(LttngStrings.IRQ).getValue()).intValue();
+ Integer irqId = ((Long) event.getContent().getField(LttngStrings.IRQ).getValue()).intValue();
/* Put this IRQ back to inactive in the resource tree */
quark = ss.getQuarkRelativeAndAdd(getNodeIRQs(), irqId.toString());
}
break;
- case 4: // "softirq_entry":
+ case LttngStrings.SOFTIRQ_ENTRY:
/* Fields: int32 vec */
{
- Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue();
+ Integer softIrqId = ((Long) event.getContent().getField(LttngStrings.VEC).getValue()).intValue();
/* Mark this SoftIRQ as active in the resource tree.
* The state value = the CPU on which this SoftIRQ is processed */
}
break;
- case 5: // "softirq_exit":
+ case LttngStrings.SOFTIRQ_EXIT:
/* Fields: int32 vec */
{
- Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue();
+ Integer softIrqId = ((Long) event.getContent().getField(LttngStrings.VEC).getValue()).intValue();
/* Put this SoftIRQ back to inactive (= -1) in the resource tree */
quark = ss.getQuarkRelativeAndAdd(getNodeSoftIRQs(), softIrqId.toString());
}
break;
- case 6: // "softirq_raise":
+ case LttngStrings.SOFTIRQ_RAISE:
/* Fields: int32 vec */
{
- Integer softIrqId = ((Long) content.getField(LttngStrings.VEC).getValue()).intValue();
+ Integer softIrqId = ((Long) event.getContent().getField(LttngStrings.VEC).getValue()).intValue();
/* Mark this SoftIRQ as *raised* in the resource tree.
* State value = -2 */
}
break;
- case 7: // "sched_switch":
+ case LttngStrings.SCHED_SWITCH:
/*
* Fields: string prev_comm, int32 prev_tid, int32 prev_prio, int64 prev_state,
* string next_comm, int32 next_tid, int32 next_prio
*/
{
+ ITmfEventField content = event.getContent();
Integer prevTid = ((Long) content.getField(LttngStrings.PREV_TID).getValue()).intValue();
Long prevState = (Long) content.getField(LttngStrings.PREV_STATE).getValue();
String nextProcessName = (String) content.getField(LttngStrings.NEXT_COMM).getValue();
}
break;
- case 8: // "sched_process_fork":
+ case LttngStrings.SCHED_PROCESS_FORK:
/* Fields: string parent_comm, int32 parent_tid,
* string child_comm, int32 child_tid */
{
+ ITmfEventField content = event.getContent();
// String parentProcessName = (String) event.getFieldValue("parent_comm");
String childProcessName = (String) content.getField(LttngStrings.CHILD_COMM).getValue();
// assert ( parentProcessName.equals(childProcessName) );
}
break;
- case 9: // "sched_process_exit":
+ case LttngStrings.SCHED_PROCESS_EXIT:
/* Fields: string comm, int32 tid, int32 prio */
break;
- case 10: // "sched_process_free":
+ case LttngStrings.SCHED_PROCESS_FREE:
/* Fields: string comm, int32 tid, int32 prio */
/*
* A sched_process_free will always happen after the sched_switch
* this is when we should delete everything wrt to the process.
*/
{
- Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue();
+ Integer tid = ((Long) event.getContent().getField(LttngStrings.TID).getValue()).intValue();
/*
* Remove the process and all its sub-attributes from the
* current state
}
break;
- case 11: // "lttng_statedump_process_state":
+ case LttngStrings.STATEDUMP_PROCESS_STATE:
/* Fields:
* int32 type, int32 mode, int32 pid, int32 submode, int32 vpid,
* int32 ppid, int32 tid, string name, int32 status, int32 vtid */
{
- Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue();
+ ITmfEventField content = event.getContent();
+ int tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue();
+ int pid = ((Long) content.getField(LttngStrings.PID).getValue()).intValue();
int ppid = ((Long) content.getField(LttngStrings.PPID).getValue()).intValue();
int status = ((Long) content.getField(LttngStrings.STATUS).getValue()).intValue();
String name = (String) content.getField(LttngStrings.NAME).getValue();
* populated with anything relevant for now.
*/
- int curThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), tid.toString());
+ int curThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(tid));
/* Set the process' name */
quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.EXEC_NAME);
/* Set the process' PPID */
quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.PPID);
if (ss.queryOngoingState(quark).isNull()) {
- value = TmfStateValue.newValueInt(ppid);
+ if (pid == tid) {
+ /* We have a process. Use the 'PPID' field. */
+ value = TmfStateValue.newValueInt(ppid);
+ } else {
+ /* We have a thread, use the 'PID' field for the parent. */
+ value = TmfStateValue.newValueInt(pid);
+ }
ss.modifyAttribute(ts, value, quark);
}
}
break;
- case 12: // "sched_wakeup":
- case 13: // "sched_wakeup_new":
+ case LttngStrings.SCHED_WAKEUP:
+ case LttngStrings.SCHED_WAKEUP_NEW:
/* Fields (same fields for both types):
* string comm, int32 pid, int32 prio, int32 success,
* int32 target_cpu */
{
- final int tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue();
+ final int tid = ((Long) event.getContent().getField(LttngStrings.TID).getValue()).intValue();
final int threadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(tid));
/*
return ss.getQuarkAbsoluteAndAdd(Attributes.RESOURCES, Attributes.SOFT_IRQS);
}
- // ------------------------------------------------------------------------
- // Workaround for the lack of switch-on-strings in Java < 7
- // ------------------------------------------------------------------------
-
- private static HashMap<String, Integer> fillEventNames() {
- /*
- * TODO Replace with straight strings in the switch/case once we move to
- * Java 7
- */
- HashMap<String, Integer> map = new HashMap<String, Integer>();
-
- map.put(LttngStrings.EXIT_SYSCALL, 1);
- map.put(LttngStrings.IRQ_HANDLER_ENTRY, 2);
- map.put(LttngStrings.IRQ_HANDLER_EXIT, 3);
- map.put(LttngStrings.SOFTIRQ_ENTRY, 4);
- map.put(LttngStrings.SOFTIRQ_EXIT, 5);
- map.put(LttngStrings.SOFTIRQ_RAISE, 6);
- map.put(LttngStrings.SCHED_SWITCH, 7);
- map.put(LttngStrings.SCHED_PROCESS_FORK, 8);
- map.put(LttngStrings.SCHED_PROCESS_EXIT, 9);
- map.put(LttngStrings.SCHED_PROCESS_FREE, 10);
- map.put(LttngStrings.STATEDUMP_PROCESS_STATE, 11);
- map.put(LttngStrings.SCHED_WAKEUP, 12);
- map.put(LttngStrings.SCHED_WAKEUP_NEW, 13);
-
- return map;
- }
-
- private int getEventIndex(String eventName) {
- Integer ret = knownEventNames.get(eventName);
- return (ret != null) ? ret : -1;
- }
-
// ------------------------------------------------------------------------
// Advanced state-setting methods
// ------------------------------------------------------------------------