tmf: Insert null values for newly-created attributes
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 26 Apr 2013 17:52:37 +0000 (13:52 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 26 Apr 2013 20:17:21 +0000 (16:17 -0400)
Instead of requiring every state provider to explicitely insert
a value when creating a new attribute, we can have the attribute
tree do it for them. Then, if the provider wants to set it to
something else, it's just changing a variable in memory.

This fixes a potential problem in the LTTng-kernel state provider,
where a value could get reset to null if no new attributes are
created between two sched_switch events.

Change-Id: I600125f560f0362671379848c572359be2f74cc7
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/12249
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>

org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java

index 0ea30d5f73f8e31a226360a4f41a6f24917bf979..d57cbdc13740cda0b67c02697098f01bd5d557a4 100644 (file)
@@ -44,7 +44,7 @@ public class CtfKernelStateInput extends AbstractStateChangeInput {
      * 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 = 1;
+    private static final int VERSION = 2;
 
     /* Event names HashMap. TODO: This can be discarded once we move to Java 7 */
     private final HashMap<String, Integer> knownEventNames;
@@ -264,20 +264,9 @@ public class CtfKernelStateInput extends AbstractStateChangeInput {
                 value = TmfStateValue.newValueString(nextProcessName);
                 ss.modifyAttribute(ts, value, quark);
 
-                /*
-                 * Check if we need to set the syscall state and the PPID of
-                 * the new process (in case we haven't seen this process before)
-                 */
-                quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL);
-                if (ss.isLastAttribute(quark)) { /* Did we just add this attribute? */
-                    value = TmfStateValue.nullValue();
-                    ss.modifyAttribute(ts, value, quark);
-                }
-                quark = ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.PPID);
-                if (ss.isLastAttribute(quark)) {
-                    value = TmfStateValue.nullValue();
-                    ss.modifyAttribute(ts, value, quark);
-                }
+                /* Make sure the PPID and system_call sub-attributes exist */
+                ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.SYSTEM_CALL);
+                ss.getQuarkRelativeAndAdd(newCurrentThreadNode, Attributes.PPID);
 
                 /* Set the current scheduled process on the relevant CPU */
                 quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
index 69407898e7e536acf255e428d29722d54201b29a..da525a96b8fee92fb6dcd98dd96739831195e908 100644 (file)
@@ -19,6 +19,9 @@ import java.util.Collections;
 import java.util.List;
 
 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.statevalue.TmfStateValue;
 
 /**
  * The Attribute Tree is the /proc-like filesystem used to organize attributes.
@@ -284,7 +287,26 @@ public class AttributeTree {
                 }
                 prevNode = nextNode;
             }
-            return attributeList.size() - 1;
+            /*
+             * Insert an initial null value for this attribute in the state
+             * system (in case the state provider doesn't set one).
+             */
+            final int newAttrib = attributeList.size() - 1;
+            try {
+                ss.modifyAttribute(ss.getStartTime(), TmfStateValue.nullValue(), newAttrib);
+            } catch (TimeRangeException e) {
+                /* Should not happen, we're inserting at ss's start time */
+                throw new RuntimeException();
+            } catch (AttributeNotFoundException e) {
+                /* Should not happen, we just created this attribute! */
+                throw new RuntimeException();
+            } catch (StateValueTypeException e) {
+                /* Should not happen, there is no existing state value, and the
+                 * one we insert is a null value anyway. */
+                throw new RuntimeException();
+            }
+
+            return newAttrib;
         }
         /*
          * The attribute was already existing, return the quark of that
This page took 0.028449 seconds and 5 git commands to generate.