aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Giraldeau2014-03-25 12:00:48 (EDT)
committerGenevieve Bastien2014-03-28 15:53:43 (EDT)
commitb563ade208cb281d5be17dcfd54429063d1e5ef6 (patch)
tree25c1c17834bc19b0c0c6b76a557e0d789a81611a
parenta13004a9acfae165b676bf7080f8a8e9c1e6e6bf (diff)
downloadorg.eclipse.linuxtools-b563ade208cb281d5be17dcfd54429063d1e5ef6.zip
org.eclipse.linuxtools-b563ade208cb281d5be17dcfd54429063d1e5ef6.tar.gz
org.eclipse.linuxtools-b563ade208cb281d5be17dcfd54429063d1e5ef6.tar.bz2
TMF: Add get parent to state systemrefs/changes/26/24026/3
It is possible to get the children of an attribute. This patch add also required methods to query the parent attributes. * Add getParent() method to Attribute, AttributeTree and StateSystem * Add unit test to check the functionality * Provides the required documentation Change-Id: I635326068c2a298b32952599e09b2426b2e1fbb0 Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com> Reviewed-on: https://git.eclipse.org/r/24026 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net> IP-Clean: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java21
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java18
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java16
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java5
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java11
5 files changed, 71 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java
index 2f46cc3..8a3708a 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemTest.java
@@ -422,4 +422,25 @@ public abstract class StateSystemTest {
fail();
}
}
+
+ @Test
+ public void testParentAttribute() {
+ String[] path = { "CPUs/0/Current_thread",
+ "CPUs/0",
+ "CPUs" };
+ try {
+ int q = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
+ for (int i = 0; i < path.length; i++) {
+ String name = ssq.getFullAttributePath(q);
+ assertEquals(path[i], name);
+ q = ssq.getParentAttributeQuark(q);
+ }
+ assertEquals(-1, q);
+ q = ssq.getParentAttributeQuark(q);
+ assertEquals(-1, q);
+ } catch (AttributeNotFoundException e) {
+ fail();
+ }
+ }
+
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
index 4cd830d..6f42a3a 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
@@ -129,6 +129,24 @@ public abstract class Attribute {
return targetNode.getQuark();
}
+ /**
+ * Get the parent attribute of this attribute
+ *
+ * @return The parent attribute
+ */
+ public Attribute getParentAttribute() {
+ return this.parent;
+ }
+
+ /**
+ * Get the parent quark of this attribute
+ *
+ * @return The quark of the parent attribute
+ */
+ public int getParentAttributeQuark() {
+ return this.parent.getQuark();
+ }
+
/* The methods how to access children are left to derived classes */
/**
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
index 3d897c6..958c867 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
@@ -357,6 +357,22 @@ public final class AttributeTree {
return listOfChildren;
}
+ /**
+ * Returns the parent quark of the attribute. The root attribute has no
+ * parent and will return <code>-1</code>
+ *
+ * @param quark
+ * The quark of the attribute
+ * @return Quark of the parent attribute or <code>-1</code> for the root
+ * attribute
+ */
+ public int getParentAttributeQuark(int quark) {
+ if (quark == -1) {
+ return quark;
+ }
+ return attributeList.get(quark).getParentAttributeQuark();
+ }
+
private void addSubAttributes(List<Integer> list, Attribute curAttribute,
boolean recursive) {
for (Attribute childNode : curAttribute.getSubAttributes()) {
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
index 981467f..00871e8 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
@@ -278,6 +278,11 @@ public class StateSystem implements ITmfStateSystemBuilder {
}
@Override
+ public int getParentAttributeQuark(int quark) {
+ return getAttributeTree().getParentAttributeQuark(quark);
+ }
+
+ @Override
public List<Integer> getQuarks(String... pattern) {
List<Integer> quarks = new LinkedList<>();
List<String> prefix = new LinkedList<>();
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java
index 4682c15..05f662b 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateSystem.java
@@ -249,6 +249,17 @@ public interface ITmfStateSystem {
String getFullAttributePath(int attributeQuark);
/**
+ * Returns the parent quark of the attribute.
+ *
+ * @param attributeQuark
+ * The quark of the attribute
+ * @return Quark of the parent attribute or <code>-1</code> if root quark or
+ * no parent.
+ * @since 3.0
+ */
+ int getParentAttributeQuark(int attributeQuark);
+
+ /**
* @name Query methods
*/