From 25e4374955ed2df65126d5d5d4d377ea26858128 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 26 Apr 2013 13:52:37 -0400 Subject: [PATCH] tmf: Insert null values for newly-created attributes 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 Reviewed-on: https://git.eclipse.org/r/12249 Reviewed-by: Genevieve Bastien Tested-by: Hudson CI Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse --- .../stateprovider/CtfKernelStateInput.java | 19 ++++----------- .../tmf/core/statesystem/AttributeTree.java | 24 ++++++++++++++++++- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java index 0ea30d5f73..d57cbdc137 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java @@ -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 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); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java index 69407898e7..da525a96b8 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java @@ -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 -- 2.34.1