lttng: Move LttngStrings to the internal package
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core / src / org / eclipse / linuxtools / internal / lttng2 / kernel / core / stateprovider / CtfKernelHandler.java
index b91d05825d3b96a8dc3fc88bdfd11b0925a06bca..453b7f1f68a81a0a23a40b676d57c48b83206e1c 100644 (file)
 
 package org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider;
 
+import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Vector;
+import java.util.List;
 import java.util.concurrent.BlockingQueue;
 
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.Attributes;
-import org.eclipse.linuxtools.lttng2.kernel.core.trace.LttngStrings;
+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.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
@@ -44,8 +46,8 @@ class CtfKernelHandler implements Runnable {
      * We can keep handles to some Attribute Nodes so these don't need to be
      * re-found (re-hashed Strings etc.) every new event
      */
-    Vector<Integer> currentCPUNodes;
-    Vector<Integer> currentThreadNodes;
+    List<Integer> currentCPUNodes;
+    List<Integer> currentThreadNodes;
 
     /* Event names HashMap. TODO: This can be discarded once we move to Java 7 */
     private final HashMap<String, Integer> knownEventNames;
@@ -59,8 +61,8 @@ class CtfKernelHandler implements Runnable {
     CtfKernelHandler(BlockingQueue<CtfTmfEvent> eventsQueue) {
         assert (eventsQueue != null);
         this.inQueue = eventsQueue;
-        currentCPUNodes = new Vector<Integer>();
-        currentThreadNodes = new Vector<Integer>();
+        currentCPUNodes = new ArrayList<Integer>();
+        currentThreadNodes = new ArrayList<Integer>();
 
         knownEventNames = fillEventNames();
     }
@@ -119,7 +121,7 @@ class CtfKernelHandler implements Runnable {
         int quark;
         ITmfStateValue value;
         Integer eventCpu = event.getCPU();
-        Integer currentCPUNode, currentThreadNode, tidNode;
+        Integer currentCPUNode, currentThreadNode;
 
         /* Adjust the current nodes Vectors if we see a new CPU in an event */
         if (eventCpu >= currentCPUNodes.size()) {
@@ -155,7 +157,12 @@ class CtfKernelHandler implements Runnable {
 
                 /* Put the process' status back to user mode */
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
-                value = TmfStateValue.newValueInt(Attributes.STATUS_RUN_USERMODE);
+                value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_USERMODE);
+                ss.modifyAttribute(ts, value, quark);
+
+                /* Put the CPU's status back to user mode */
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);
+                value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE);
                 ss.modifyAttribute(ts, value, quark);
             }
                 break;
@@ -173,8 +180,13 @@ class CtfKernelHandler implements Runnable {
 
                 /* Change the status of the running process to interrupted */
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
-                value = TmfStateValue.newValueInt(Attributes.STATUS_INTERRUPTED);
+                value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_INTERRUPTED);
                 ss.modifyAttribute(ts, value, quark);
+\r
+                /* Change the status of the CPU to interrupted */\r
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);\r
+                value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IRQ);\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -190,6 +202,9 @@ class CtfKernelHandler implements Runnable {
 
                 /* Set the previous process back to running */
                 setProcessToRunning(ts, currentThreadNode);
+\r
+                /* Set the CPU status back to running or "idle" */\r
+                cpuExitInterrupt(ts, currentCPUNode, currentThreadNode);\r
             }
                 break;
 
@@ -206,8 +221,13 @@ class CtfKernelHandler implements Runnable {
 
                 /* Change the status of the running process to interrupted */
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
-                value = TmfStateValue.newValueInt(Attributes.STATUS_INTERRUPTED);
+                value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_INTERRUPTED);
                 ss.modifyAttribute(ts, value, quark);
+\r
+                /* Change the status of the CPU to interrupted */\r
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);\r
+                value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_SOFTIRQ);\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -223,6 +243,9 @@ class CtfKernelHandler implements Runnable {
 
                 /* Set the previous process back to running */
                 setProcessToRunning(ts, currentThreadNode);
+\r
+                /* Set the CPU status back to "busy" or "idle" */\r
+                cpuExitInterrupt(ts, currentCPUNode, currentThreadNode);\r
             }
                 break;
 
@@ -234,7 +257,7 @@ class CtfKernelHandler implements Runnable {
                 /* Mark this SoftIRQ as *raised* in the resource tree.
                  * State value = -2 */
                 quark = ss.getQuarkRelativeAndAdd(softIrqsNode, softIrqId.toString());
-                value = TmfStateValue.newValueInt(Attributes.SOFT_IRQ_RAISED);
+                value = TmfStateValue.newValueInt(StateValues.SOFT_IRQ_RAISED);
                 ss.modifyAttribute(ts, value, quark);
             }
                 break;
@@ -247,26 +270,19 @@ class CtfKernelHandler implements Runnable {
             {
                 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();
                 Integer nextTid = ((Long) content.getField(LttngStrings.NEXT_TID).getValue()).intValue();
 
-                /* Update the currentThreadNodes pointer */
+                Integer formerThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, prevTid.toString());
                 Integer newCurrentThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, nextTid.toString());
+
+                /* Update the currentThreadNodes pointer */
                 currentThreadNodes.set(eventCpu, newCurrentThreadNode);
 
-                /*
-                 * Set the status of the process that got scheduled out, but
-                 * only in the case where that process is currently active.
-                 */
-                Integer formerThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, prevTid.toString());
-                quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.EXEC_NAME);
-                value = ss.queryOngoingState(quark);
-                if (!value.isNull()) {
-                    quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS);
-                    value = TmfStateValue.newValueInt(Attributes.STATUS_WAIT);
-                    ss.modifyAttribute(ts, value, quark);
-                }
+                /* Set the status of the process that got scheduled out. */
+                quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS);
+                value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT);
+                ss.modifyAttribute(ts, value, quark);
 
                 /* Set the status of the new scheduled process */
                 setProcessToRunning(ts, newCurrentThreadNode);
@@ -295,6 +311,21 @@ class CtfKernelHandler implements Runnable {
                 quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
                 value = TmfStateValue.newValueInt(nextTid);
                 ss.modifyAttribute(ts, value, quark);
+\r
+                /* Set the status of the CPU itself */
+                if (nextTid > 0) {
+                    /* Check if the entering process is in kernel or user mode */
+                    quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL);
+                    if (ss.queryOngoingState(quark).isNull()) {
+                        value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE);
+                    } else {
+                        value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL);
+                    }\r
+                } else {\r
+                    value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IDLE);\r
+                }
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -302,50 +333,52 @@ class CtfKernelHandler implements Runnable {
             /* Fields: string parent_comm, int32 parent_tid,
              *         string child_comm, int32 child_tid */
             {
-                // String parentProcessName = (String)
-                // event.getFieldValue("parent_comm");
-                String childProcessName;
-                childProcessName = (String) content.getField(LttngStrings.CHILD_COMM).getValue();
+                // String parentProcessName = (String) event.getFieldValue("parent_comm");
+                String childProcessName = (String) content.getField(LttngStrings.CHILD_COMM).getValue();
                 // assert ( parentProcessName.equals(childProcessName) );
 
                 Integer parentTid = ((Long) content.getField(LttngStrings.PARENT_TID).getValue()).intValue();
                 Integer childTid = ((Long) content.getField(LttngStrings.CHILD_TID).getValue()).intValue();
 
-                tidNode = ss.getQuarkRelativeAndAdd(threadsNode, childTid.toString());
+                Integer parentTidNode = ss.getQuarkRelativeAndAdd(threadsNode, parentTid.toString());
+                Integer childTidNode = ss.getQuarkRelativeAndAdd(threadsNode, childTid.toString());
 
                 /* Assign the PPID to the new process */
-                quark = ss.getQuarkRelativeAndAdd(tidNode, Attributes.PPID);
+                quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.PPID);
                 value = TmfStateValue.newValueInt(parentTid);
                 ss.modifyAttribute(ts, value, quark);
 
                 /* Set the new process' exec_name */
-                quark = ss.getQuarkRelativeAndAdd(tidNode, Attributes.EXEC_NAME);
+                quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.EXEC_NAME);
                 value = TmfStateValue.newValueString(childProcessName);
                 ss.modifyAttribute(ts, value, quark);
 
                 /* Set the new process' status */
-                quark = ss.getQuarkRelativeAndAdd(tidNode, Attributes.STATUS);
-                value = TmfStateValue.newValueInt(Attributes.STATUS_WAIT);
+                quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.STATUS);
+                value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT);
                 ss.modifyAttribute(ts, value, quark);
 
-                /* Set the process' syscall state */
-                quark = ss.getQuarkRelativeAndAdd(tidNode, Attributes.SYSTEM_CALL);
-                value = TmfStateValue.nullValue();
+                /* Set the process' syscall name, to be the same as the parent's */
+                quark = ss.getQuarkRelativeAndAdd(parentTidNode, Attributes.SYSTEM_CALL);
+                value = ss.queryOngoingState(quark);
+                quark = ss.getQuarkRelativeAndAdd(childTidNode, Attributes.SYSTEM_CALL);
                 ss.modifyAttribute(ts, value, quark);
             }
                 break;
 
             case 9: // "sched_process_exit":
             /* Fields: string comm, int32 tid, int32 prio */
+                break;
+
+            case 10: // "sched_process_free":
+            /* Fields: string comm, int32 tid, int32 prio */
+            /*
+             * A sched_process_free will always happen after the sched_switch
+             * that will remove the process from the cpu for the last time. So
+             * this is when we should delete everything wrt to the process.
+             */
             {
-                String processName = (String) content.getField(LttngStrings.COMM).getValue();
                 Integer tid = ((Long) content.getField(LttngStrings.TID).getValue()).intValue();
-
-                /* Update the process' name, if we don't have it */
-                quark = ss.getQuarkRelativeAndAdd(threadsNode, tid.toString(), Attributes.EXEC_NAME);
-                value = TmfStateValue.newValueString(processName);
-                ss.updateOngoingState(value, quark);
-
                 /*
                  * Remove the process and all its sub-attributes from the
                  * current state
@@ -355,10 +388,6 @@ class CtfKernelHandler implements Runnable {
             }
                 break;
 
-            case 10: // "sched_process_free":
-            /* Fields: string comm, int32 tid, int32 prio */
-                break;
-
             // FIXME In CTF it's as "syscall_exec". Will have to be adapted.
             // case LTT_EVENT_EXEC:
             // filename = new String((byte[]) event.getField(0));
@@ -386,7 +415,12 @@ class CtfKernelHandler implements Runnable {
 
                     /* Put the process in system call mode */
                     quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
-                    value = TmfStateValue.newValueInt(Attributes.STATUS_RUN_SYSCALL);
+                    value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_SYSCALL);
+                    ss.modifyAttribute(ts, value, quark);
+
+                    /* Put the CPU in system call (kernel) mode */
+                    quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);
+                    value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL);
                     ss.modifyAttribute(ts, value, quark);
                 }
             }
@@ -485,12 +519,44 @@ class CtfKernelHandler implements Runnable {
         quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.SYSTEM_CALL);
         if (ss.queryOngoingState(quark).isNull()) {
             /* We were in user mode before the interruption */
-            value = TmfStateValue.newValueInt(Attributes.STATUS_RUN_USERMODE);
+            value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_USERMODE);
         } else {
             /* We were previously in kernel mode */
-            value = TmfStateValue.newValueInt(Attributes.STATUS_RUN_SYSCALL);
+            value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_RUN_SYSCALL);
         }
         quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
         ss.modifyAttribute(ts, value, quark);
     }
+\r
+    /**\r
+     * Similar logic as above, but to set the CPU's status when it's coming out\r
+     * of an interruption.\r
+     * @throws AttributeNotFoundException \r
+     * @throws StateValueTypeException \r
+     * @throws TimeRangeException \r
+     */\r
+    private void cpuExitInterrupt(long ts, int currentCpuNode, int currentThreadNode)\r
+            throws StateValueTypeException, AttributeNotFoundException,\r
+            TimeRangeException {\r
+        int quark;\r
+        ITmfStateValue value;\r
+\r
+        quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.CURRENT_THREAD);\r
+        if (ss.queryOngoingState(quark).unboxInt() > 0) {\r
+            /* There was a process on the CPU */
+            quark = ss.getQuarkRelative(currentThreadNode, Attributes.SYSTEM_CALL);
+            if (ss.queryOngoingState(quark).isNull()) {
+                /* That process was in user mode */
+                value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_USERMODE);
+            } else {
+                /* That process was in a system call */
+                value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_RUN_SYSCALL);
+            }
+        } else {\r
+            /* There was no real process scheduled, CPU was idle */\r
+            value = TmfStateValue.newValueInt(StateValues.CPU_STATUS_IDLE);\r
+        }\r
+        quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.STATUS);\r
+        ss.modifyAttribute(ts, value, quark);\r
+    }\r
 }
This page took 0.02847 seconds and 5 git commands to generate.