[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [linuxtools-dev] [PATCH] TMF: Add get parent to state system
|
Hi Francis,
Can you push this patch to Gerrit? Here's a page with information about
Gerrit:
https://wiki.eclipse.org/Gerrit
Marc-André
On 14-03-25 01:59 PM, Francis Giraldeau wrote:
> 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@xxxxxxxxx>
> ---
> .../core/tests/stateprovider/StateSystemTest.java | 19 +++++++++++++++++++
> .../internal/tmf/core/statesystem/Attribute.java | 16 ++++++++++++++++
> .../internal/tmf/core/statesystem/AttributeTree.java | 11 +++++++++++
> .../internal/tmf/core/statesystem/StateSystem.java | 5 +++++
> .../tmf/core/statesystem/ITmfStateSystem.java | 9 +++++++++
> 5 files changed, 60 insertions(+)
>
> 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..7370c1a 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,23 @@ 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);
> + } 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..a238a0c 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,22 @@ 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..49d6dcc 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,17 @@ public final class AttributeTree {
> return listOfChildren;
> }
>
> + /**
> + * Returns the parent quark of the attribute. The root attribute
> + * has no parent.
> + *
> + * @param attributeQuark The quark of the attribute
> + * @return Quark of the parent attribute
> + */
> + public int getParentAttributeQuark(int 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..3d24b7a 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,15 @@ public interface ITmfStateSystem {
> String getFullAttributePath(int attributeQuark);
>
> /**
> + * Returns the parent quark of the attribute. The root attribute
> + * has no parent.
> + *
> + * @param attributeQuark The quark of the attribute
> + * @return Quark of the parent attribute
> + */
> + int getParentAttributeQuark(int attributeQuark);
> +
> + /**
> * @name Query methods
> */
>