tmf.core: make Analyses with experiments add children analyses when available.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 20 Apr 2016 21:21:51 +0000 (17:21 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 13 May 2016 18:27:49 +0000 (14:27 -0400)
This is a feature that allows experiments to use the analyses of their children.
The analyses are in a list so that the parent trace is always the first one.

Change-Id: I0f6ba6d38fecb49e4575bd0a4dd1d8602970f4d6
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/71100
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/TmfTraceUtils.java

index f2473991ae29d6fa2ec066b8f1b1618c0128a901..c0626db807036dbb7c9c7f1b184e528adeaff0b8 100644 (file)
@@ -18,17 +18,20 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.common.core.StreamUtils;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.component.ITmfEventProvider;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 
+import com.google.common.collect.Iterables;
+
 /**
  * Utility methods for ITmfTrace's.
  *
@@ -43,8 +46,8 @@ public final class TmfTraceUtils {
     }
 
     /**
-     * Get an analysis module belonging to this trace, with the specified ID and
-     * class.
+     * Return the first result of the first analysis module belonging to this trace or its children,
+     * with the specified ID and class.
      *
      * @param trace
      *            The trace for which you want the modules
@@ -67,23 +70,31 @@ public final class TmfTraceUtils {
     }
 
     /**
-     * Return the analysis modules that are of a given class. Module will be
-     * casted to the requested class.
+     * Return the analysis modules that are of a given class. The modules will be
+     * cast to the requested class. If the trace has children, the childrens modules
+     * are also returned.
      *
      * @param trace
-     *            The trace for which you want the modules
+     *            The trace for which you want the modules, the children trace modules
+     *            are added as well.
      * @param moduleClass
      *            Returned modules must extend this class
      * @return List of modules of class moduleClass
      */
     public static <T> Iterable<@NonNull T> getAnalysisModulesOfClass(ITmfTrace trace, Class<T> moduleClass) {
         Iterable<IAnalysisModule> analysisModules = trace.getAnalysisModules();
-        Set<@NonNull T> modules = new HashSet<>();
+        List<@NonNull T> modules = new ArrayList<>();
         for (IAnalysisModule module : analysisModules) {
             if (moduleClass.isAssignableFrom(module.getClass())) {
                 modules.add(checkNotNull(moduleClass.cast(module)));
             }
         }
+        for (ITmfEventProvider child : trace.getChildren()) {
+            if (child instanceof ITmfTrace) {
+                ITmfTrace childTrace = (ITmfTrace) child;
+                Iterables.addAll(modules, getAnalysisModulesOfClass(childTrace, moduleClass));
+            }
+        }
         return modules;
     }
 
This page took 0.026766 seconds and 5 git commands to generate.