lami: Implement a custom chart data provider
authorGabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com>
Thu, 7 Jul 2016 19:11:20 +0000 (15:11 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Fri, 10 Mar 2017 14:57:54 +0000 (09:57 -0500)
This patch adds a data model for a LAMI analysis. It also implements a data
provider into the result table.

This allows the creation of custom charts using the tmf.chart plugin

Change-Id: I1375c81c6e99538d4b2e86afb517c4014b0a8a98
Signed-off-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com>
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/76899
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.lami.core.tests/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.lami.core/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.lami.core/src/org/eclipse/tracecompass/internal/provisional/analysis/lami/core/module/LamiResultTable.java
analysis/org.eclipse.tracecompass.analysis.lami.ui/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.chart.core/META-INF/MANIFEST.MF

index b9f09a58019bf6c6b399e772cd13618107b11a5b..d61053cf36cd06dd49d997a04ebacc707c7fe6e2 100644 (file)
@@ -13,7 +13,8 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
  org.eclipse.tracecompass.common.core,
  org.eclipse.tracecompass.analysis.lami.core,
  org.eclipse.tracecompass.tmf.core,
- org.eclipse.tracecompass.tmf.core.tests
+ org.eclipse.tracecompass.tmf.core.tests,
+ org.eclipse.tracecompass.tmf.chart.core
 Export-Package: org.eclipse.tracecompass.analysis.lami.core.tests
 Bundle-Activator: org.eclipse.tracecompass.analysis.lami.core.tests.Activator
 Import-Package: com.google.common.collect
index 9849a30561d12a26af1dd281c95d4ccc160ba594..30ca0d0f5d4eeaf33ec4a412b82a646143a426ed 100644 (file)
@@ -10,6 +10,7 @@ Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.tracecompass.common.core,
+ org.eclipse.tracecompass.tmf.chart.core,
  org.eclipse.tracecompass.tmf.core
 Export-Package: org.eclipse.tracecompass.internal.analysis.lami.core;x-internal:=true,
  org.eclipse.tracecompass.internal.provisional.analysis.lami.core;x-friends:="org.eclipse.tracecompass.analysis.lami.ui,org.eclipse.tracecompass.lttng2.kernel.core,org.eclipse.tracecompass.analysis.lami.core.tests",
index 73ee821d6e18eee424413b8da488acb4872aa27f..a4a32b9a7fce0cbd5e2817a10584c611c8da71dd 100644 (file)
@@ -9,22 +9,50 @@
 
 package org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.ArrayList;
 import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Stream;
 
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.aspect.LamiEmptyAspect;
+import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.aspect.LamiTableEntryAspect;
 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.types.LamiTimeRange;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartStringDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartTimestampDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.model.IDataChartProvider;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractDoubleResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.IStringResolver;
 
 import com.google.common.collect.ImmutableList;
 
 /**
- * Class holding the results contained in one table outputted by a LAMI analysis.
+ * Class holding the results contained in one table outputted by a LAMI
+ * analysis.
  *
  * @author Alexandre Montplaisir
+ * @author Gabriel-Andrew Pollo-Guilbert
  */
-public class LamiResultTable {
+public class LamiResultTable implements IDataChartProvider<LamiTableEntry> {
+
+    // ------------------------------------------------------------------------
+    // Members
+    // ------------------------------------------------------------------------
 
     private final LamiTimeRange fTimeRange;
     private final LamiTableClass fTableClass;
     private final List<LamiTableEntry> fEntries;
+    private final List<IDataChartDescriptor<LamiTableEntry, ?>> fDescriptors;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
 
     /**
      * Construct a new table from its components.
@@ -42,8 +70,64 @@ public class LamiResultTable {
         fTimeRange = timeRange;
         fTableClass = tableClass;
         fEntries = ImmutableList.copyOf(entries);
+        fDescriptors = new ArrayList<>();
+
+        for (LamiTableEntryAspect aspect : getTableClass().getAspects()) {
+            if (aspect instanceof LamiEmptyAspect) {
+                continue;
+            }
+
+            /**
+             * Differenciation of lami aspect types for use by the custom charts
+             * is made by continuity or timestamp. There is no special treatment
+             * for time durations, or at least there was none in the original
+             * lami charts.
+             */
+            if (aspect.isContinuous()) {
+                if (aspect.isTimeStamp()) {
+                    /* Create descriptors for timestamps */
+                    fDescriptors.add(new DataChartTimestampDescriptor<>(aspect.getName(), new LamiDataLongResolver(aspect)));
+                } else if (aspect.isTimeDuration()) {
+                    /*
+                     * Create descriptors for numbers with units. We do not use
+                     * duration descriptor since in the case of lami charts, we
+                     * want the durations and numerical data to be compatible
+                     */
+                    fDescriptors.add(new DataChartNumericalDescriptor<>(aspect.getName(), new LamiDataDoubleResolver(aspect), aspect.getUnits()));
+                } else {
+                    /* Create descriptors for general numbers */
+                    fDescriptors.add(new DataChartNumericalDescriptor<>(aspect.getName(), new LamiDataDoubleResolver(aspect)));
+                }
+            } else {
+                /* Create descriptors for general strings */
+                fDescriptors.add(new DataChartStringDescriptor<>(aspect.getName(), new LamiDataStringResolver(aspect)));
+            }
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Overriden methods
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String getName() {
+        return getTableClass().getTableTitle();
+    }
+
+    @Override
+    public Stream<@NonNull LamiTableEntry> getSource() {
+        return checkNotNull(fEntries.stream());
     }
 
+    @Override
+    public List<IDataChartDescriptor<LamiTableEntry, ?>> getDataDescriptors() {
+        return ImmutableList.copyOf(fDescriptors);
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
     /**
      * Get the time range of this table.
      *
@@ -70,4 +154,60 @@ public class LamiResultTable {
     public List<LamiTableEntry> getEntries() {
         return fEntries;
     }
+
+    // ------------------------------------------------------------------------
+    // Data resolvers
+    // ------------------------------------------------------------------------
+
+    private final class LamiDataLongResolver extends AbstractLongResolver<LamiTableEntry> {
+        LamiTableEntryAspect fAspect;
+
+        public LamiDataLongResolver(LamiTableEntryAspect aspect) {
+            fAspect = aspect;
+        }
+
+        @Override
+        public Function<LamiTableEntry, @Nullable Long> getMapper() {
+            return o -> {
+                Number res = fAspect.resolveNumber(o);
+                if (res == null) {
+                    return null;
+                }
+                return res.longValue();
+            };
+        }
+    }
+
+    private final class LamiDataDoubleResolver extends AbstractDoubleResolver<LamiTableEntry> {
+        LamiTableEntryAspect fAspect;
+
+        public LamiDataDoubleResolver(LamiTableEntryAspect aspect) {
+            fAspect = aspect;
+        }
+
+        @Override
+        public Function<LamiTableEntry, @Nullable Double> getMapper() {
+            return o -> {
+                Number res = fAspect.resolveNumber(o);
+                if (res == null) {
+                    return null;
+                }
+                return res.doubleValue();
+            };
+        }
+    }
+
+    private final class LamiDataStringResolver implements IStringResolver<LamiTableEntry> {
+        LamiTableEntryAspect fAspect;
+
+        public LamiDataStringResolver(LamiTableEntryAspect aspect) {
+            fAspect = aspect;
+        }
+
+        @Override
+        public Function<@NonNull LamiTableEntry, @Nullable String> getMapper() {
+            return o -> fAspect.resolveString(o);
+        }
+    }
+
 }
index 3c119d8b8c04c2f377c26a0f5100e9e274b69b17..a8afd45142cfda559c2b55cc554c1432ab6a632d 100644 (file)
@@ -15,7 +15,8 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.tracecompass.common.core,
  org.eclipse.tracecompass.tmf.core,
  org.eclipse.tracecompass.tmf.ui,
- org.eclipse.tracecompass.analysis.lami.core
+ org.eclipse.tracecompass.analysis.lami.core,
+ org.eclipse.tracecompass.tmf.chart.core
 Export-Package: org.eclipse.tracecompass.internal.analysis.lami.ui;x-internal:=true,
  org.eclipse.tracecompass.internal.provisional.analysis.lami.ui.format;x-internal:=true,
  org.eclipse.tracecompass.internal.provisional.analysis.lami.ui.handler;x-internal:=true,
index 5f4e6d036662fc9670ad489d84b105b0fb53f897..403b65f41736f6d9d3a551bc25967e8506358c40 100644 (file)
@@ -16,13 +16,18 @@ Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.chart.core.cha
    org.eclipse.tracecompass.tmf.chart.core.tests",
  org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor;
   x-friends:="org.eclipse.tracecompass.tmf.chart.ui,
-   org.eclipse.tracecompass.tmf.chart.core.tests",
+   org.eclipse.tracecompass.tmf.chart.core.tests,
+   org.eclipse.tracecompass.analysis.lami.core,
+   org.eclipse.tracecompass.analysis.lami.ui",
  org.eclipse.tracecompass.internal.provisional.tmf.chart.core.model;
   x-friends:="org.eclipse.tracecompass.tmf.chart.ui,
-   org.eclipse.tracecompass.tmf.chart.core.tests",
+   org.eclipse.tracecompass.tmf.chart.core.tests,
+   org.eclipse.tracecompass.analysis.lami.core,
+   org.eclipse.tracecompass.analysis.lami.ui",
  org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver;
   x-friends:="org.eclipse.tracecompass.tmf.chart.ui,
-   org.eclipse.tracecompass.tmf.chart.core.tests",
+   org.eclipse.tracecompass.tmf.chart.core.tests,
+   org.eclipse.tracecompass.analysis.lami.core",
  org.eclipse.tracecompass.internal.provisional.tmf.chart.core.signal;x-friends:="org.eclipse.tracecompass.tmf.chart.ui",
  org.eclipse.tracecompass.internal.tmf.chart.core;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.chart.core.aggregator;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests",
This page took 0.030247 seconds and 5 git commands to generate.