Search in sources :

Example 1 with TimeLinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent in project tracecompass by tracecompass.

the class BaseDataProviderTimeGraphView method getLinkList.

@Override
protected List<@NonNull ILinkEvent> getLinkList(long zoomStartTime, long zoomEndTime, long resolution, @NonNull IProgressMonitor monitor) {
    Collection<ITimeGraphDataProvider<? extends @NonNull TimeGraphEntryModel>> providers = getProviders(getTrace());
    if (providers.isEmpty()) {
        return Collections.emptyList();
    }
    List<@NonNull ILinkEvent> linkList = new ArrayList<>();
    List<@NonNull Long> times = StateSystemUtils.getTimes(zoomStartTime, zoomEndTime, resolution);
    Map<@NonNull String, @NonNull Object> parameters = getFetchArrowsParameters(times);
    for (ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider : providers) {
        TmfModelResponse<List<ITimeGraphArrow>> response = provider.fetchArrows(parameters, monitor);
        List<ITimeGraphArrow> model = response.getModel();
        if (model != null) {
            for (ITimeGraphArrow arrow : model) {
                ITimeGraphEntry prevEntry;
                ITimeGraphEntry nextEntry;
                synchronized (fEntries) {
                    prevEntry = fEntries.get(provider, arrow.getSourceId());
                    nextEntry = fEntries.get(provider, arrow.getDestinationId());
                }
                if (prevEntry != null && nextEntry != null) {
                    linkList.add(new TimeLinkEvent(arrow, prevEntry, nextEntry));
                }
            }
        }
    }
    return linkList;
}
Also used : ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) ArrayList(java.util.ArrayList) ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) TimeLinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent)

Example 2 with TimeLinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent in project tracecompass by tracecompass.

the class ControlFlowOptimizerTest method testMany.

/**
 * This is a smoke test, it makes sure that the algorithm scales moderately
 * well. The typical dataset is about 100-500 elements to sort, so we add a
 * factor of safety here.
 */
@Test
public void testMany() {
    Random rnd = new Random();
    // The same combination as my luggage
    rnd.setSeed(12345);
    Function<Collection<ILinkEvent>, Map<Integer, Long>> oa = getOptimizationMethod();
    List<ILinkEvent> links = new ArrayList<>();
    int count = 25000;
    for (int i = 0; i < count; i++) {
        int src = rnd.nextInt(10000);
        int dst = rnd.nextInt(1000);
        links.add(new TimeLinkEvent(generateCFVEntry(src), generateCFVEntry(dst), src, dst));
    }
    Map<Integer, Long> result = oa.apply(links);
    assertNotNull(result);
    // calculate weight
    long initialWeight = 0;
    long optimalWeight = 0;
    for (ILinkEvent link : links) {
        long src = link.getTime();
        long dst = link.getDuration();
        initialWeight += Math.abs(src - dst);
        Long newSrc = result.get((int) src);
        Long newDst = result.get((int) dst);
        assertNotNull(newSrc);
        assertNotNull(newDst);
        optimalWeight += Math.abs(newSrc - newDst);
    }
    assertTrue(optimalWeight <= initialWeight);
}
Also used : ArrayList(java.util.ArrayList) ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) Random(java.util.Random) Collection(java.util.Collection) TimeLinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with TimeLinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent in project tracecompass by tracecompass.

the class ControlFlowOptimizerTest method testSinglePartiallyInvalid.

/**
 * Test a single partially invalid link.
 */
public void testSinglePartiallyInvalid() {
    Function<Collection<ILinkEvent>, Map<Integer, Long>> oa = getOptimizationMethod();
    Map<Integer, Long> result = oa.apply(Collections.singleton(new TimeLinkEvent(new TimeGraphEntry("Hi", 0, 1), generateCFVEntry(0), 0, 0)));
    assertNotNull(result);
    assertEquals(Collections.emptyMap(), result);
    result = oa.apply(Collections.singleton(new TimeLinkEvent(generateCFVEntry(0), new TimeGraphEntry("Hi", 0, 1), 0, 0)));
    assertNotNull(result);
    assertEquals(Collections.emptyMap(), result);
    result = oa.apply(Collections.singleton(new TimeLinkEvent(generateCFVEntry(0), null, 0, 0)));
    assertNotNull(result);
    assertEquals(Collections.emptyMap(), result);
}
Also used : Collection(java.util.Collection) TimeLinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with TimeLinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent in project tracecompass by tracecompass.

the class CriticalPathView method getLinkList.

@Override
protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
    List<@NonNull TimeGraphEntry> traceEntries = getEntryList(getTrace());
    if (traceEntries == null) {
        return Collections.emptyList();
    }
    List<@NonNull ILinkEvent> linkList = new ArrayList<>();
    TimeQueryFilter queryFilter = new TimeQueryFilter(startTime, endTime, 2);
    /*
         * group entries by critical path data provider as several hosts may refer to
         * the same data provider
         */
    Table<ITimeGraphDataProvider<?>, Long, TimeGraphEntry> table = HashBasedTable.create();
    for (TraceEntry traceEntry : Iterables.filter(traceEntries, TraceEntry.class)) {
        for (TimeGraphEntry entry : Utils.flatten(traceEntry)) {
            table.put(traceEntry.getProvider(), entry.getEntryModel().getId(), entry);
        }
    }
    for (Map.Entry<ITimeGraphDataProvider<?>, Map<Long, TimeGraphEntry>> entry : table.rowMap().entrySet()) {
        ITimeGraphDataProvider<?> provider = entry.getKey();
        Map<Long, TimeGraphEntry> map = entry.getValue();
        TmfModelResponse<List<ITimeGraphArrow>> response = provider.fetchArrows(FetchParametersUtils.timeQueryToMap(queryFilter), monitor);
        List<ITimeGraphArrow> model = response.getModel();
        if (monitor.isCanceled()) {
            return null;
        }
        if (model != null) {
            for (ITimeGraphArrow arrow : model) {
                ITimeGraphEntry src = map.get(arrow.getSourceId());
                ITimeGraphEntry dst = map.get(arrow.getDestinationId());
                if (src != null && dst != null) {
                    linkList.add(new TimeLinkEvent(src, dst, arrow.getStartTime(), arrow.getDuration(), arrow.getValue()));
                }
            }
        }
    }
    return linkList;
}
Also used : ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) ArrayList(java.util.ArrayList) ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) ArrayList(java.util.ArrayList) List(java.util.List) TimeLinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent) Map(java.util.Map)

Example 5 with TimeLinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent in project tracecompass by tracecompass.

the class ControlFlowOptimizerTest method testDoubleOtherOrder.

/**
 * Test the same links as {@link #testDouble()} but in a different order.
 */
@Test
public void testDoubleOtherOrder() {
    Function<Collection<ILinkEvent>, Map<Integer, Long>> oa = getOptimizationMethod();
    List<ILinkEvent> links = new ArrayList<>();
    links.add(new TimeLinkEvent(generateCFVEntry(1), generateCFVEntry(0), 0, 0));
    links.add(new TimeLinkEvent(generateCFVEntry(2), generateCFVEntry(0), 0, 0));
    Map<Integer, Long> result = oa.apply(links);
    assertNotNull(result);
    assertEquals(ImmutableMap.of(0, 0L, 1, 1L, 2, 2L), result);
}
Also used : ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) ArrayList(java.util.ArrayList) Collection(java.util.Collection) TimeLinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

TimeLinkEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent)7 ArrayList (java.util.ArrayList)6 ILinkEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent)6 Map (java.util.Map)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)3 List (java.util.List)2 ITimeGraphArrow (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow)2 ITimeGraphDataProvider (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider)2 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)2 TimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry)2 ImmutableList (com.google.common.collect.ImmutableList)1 Random (java.util.Random)1 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)1 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)1