lttng: Track the CPU statuses in the event handler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core / src / org / eclipse / linuxtools / internal / lttng2 / kernel / core / stateprovider / CtfKernelHandler.java
index d4b8aa961e80bdbc058d8daddfabae44f05e1b8d..f3f5d4ef6f6346801a37f84831f90ed7e7303bc9 100644 (file)
@@ -96,6 +96,9 @@ class CtfKernelHandler implements Runnable {
 
     private void closeStateSystem() {
         /* Close the History system, if there is one */
+        if (currentEvent == null) {
+            return;
+        }
         try {
             ss.closeHistory(currentEvent.getTimestamp().getValue());
         } catch (TimeRangeException e) {
@@ -172,6 +175,11 @@ class CtfKernelHandler implements Runnable {
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
                 value = TmfStateValue.newValueInt(Attributes.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(Attributes.CPU_STATUS_INTERRUPTED);\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -187,6 +195,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);\r
             }
                 break;
 
@@ -205,6 +216,11 @@ class CtfKernelHandler implements Runnable {
                 quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATUS);
                 value = TmfStateValue.newValueInt(Attributes.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(Attributes.CPU_STATUS_INTERRUPTED);\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -220,6 +236,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);\r
             }
                 break;
 
@@ -252,14 +271,22 @@ class CtfKernelHandler implements Runnable {
                 Integer newCurrentThreadNode = ss.getQuarkRelativeAndAdd(threadsNode, nextTid.toString());
                 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 new scheduled process */
                 setProcessToRunning(ts, newCurrentThreadNode);
 
-                /* Set the status of the process that got scheduled out */
-                quark = ss.getQuarkRelativeAndAdd(threadsNode, prevTid.toString(), Attributes.STATUS);
-                value = TmfStateValue.newValueInt(Attributes.STATUS_WAIT);
-                ss.modifyAttribute(ts, value, quark);
-
                 /* Set the exec name of the new process */
                 quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.EXEC_NAME);
                 value = TmfStateValue.newValueString(nextProcessName);
@@ -270,7 +297,7 @@ class CtfKernelHandler implements Runnable {
                  * the new process (in case we haven't seen this process before)
                  */
                 quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL);
-                if (quark == ss.getNbAttributes()) {
+                if (quark == ss.getNbAttributes()) { /* Did we just add this attribute? */
                     value = TmfStateValue.nullValue();
                     ss.modifyAttribute(ts, value, quark);
                 }
@@ -284,6 +311,15 @@ 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 */\r
+                quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATUS);\r
+                if (nextTid > 0) {\r
+                    value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_BUSY);\r
+                } else {\r
+                    value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_IDLE);\r
+                }\r
+                ss.modifyAttribute(ts, value, quark);\r
             }
                 break;
 
@@ -482,4 +518,29 @@ class CtfKernelHandler implements Runnable {
         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)\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 */\r
+            value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_BUSY);\r
+        } else {\r
+            /* There was no real process scheduled, CPU was idle */\r
+            value = TmfStateValue.newValueInt(Attributes.CPU_STATUS_IDLE);\r
+        }\r
+        quark = ss.getQuarkRelativeAndAdd(currentCpuNode, Attributes.STATUS);\r
+        ss.modifyAttribute(ts, value, quark);\r
+    }\r
 }
This page took 0.025745 seconds and 5 git commands to generate.