Search in sources :

Example 1 with ILinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent 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 ILinkEvent

use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent 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 ILinkEvent

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

the class ControlFlowOptimizerTest method test9OutOfOrder.

/**
 * A typical use case, the links are out of order, this makes sure they
 * still are
 */
@Test
public void test9OutOfOrder() {
    Map<Integer, Long> expected = getExpected9();
    Random rnd = new Random();
    rnd.setSeed(0);
    Function<Collection<ILinkEvent>, Map<Integer, Long>> oa = getOptimizationMethod();
    List<ILinkEvent> links = getTestVector();
    Collections.shuffle(links, rnd);
    Map<Integer, Long> result = oa.apply(links);
    assertNotNull(result);
    assertEquals(expected, result);
}
Also used : ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) Random(java.util.Random) Collection(java.util.Collection) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ILinkEvent

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

the class TimeGraphControl method getArrow.

/**
 * Return the arrow event closest to the given point that is no further than a
 * maximum distance.
 *
 * @param pt
 *            a point in the widget
 * @return The closest arrow event, or null if there is none close enough.
 */
protected ILinkEvent getArrow(Point pt) {
    if (fHideArrows) {
        return null;
    }
    ILinkEvent linkEvent = null;
    double minDistance = Double.MAX_VALUE;
    Rectangle clientArea = getClientArea();
    for (ILinkEvent event : fItemData.fLinks) {
        Rectangle rect = getArrowRectangle(clientArea, event);
        if (rect != null) {
            int x1 = rect.x;
            int y1 = rect.y;
            int x2 = x1 + rect.width;
            int y2 = y1 + rect.height;
            double d = Utils.distance(pt.x, pt.y, x1, y1, x2, y2);
            if (minDistance > d) {
                minDistance = d;
                linkEvent = event;
            }
        }
    }
    if (minDistance <= ARROW_HOVER_MAX_DIST) {
        return linkEvent;
    }
    return null;
}
Also used : ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) LongPoint(org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)

Example 5 with ILinkEvent

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

the class TimeGraphControl method followArrowFwd.

/**
 * Follow the arrow forward
 *
 * @param extend
 *            true to extend selection range, false for single selection
 * @since 1.0
 */
public void followArrowFwd(boolean extend) {
    ITimeGraphEntry trace = getSelectedTrace();
    if (trace == null) {
        return;
    }
    long selectedTime = fTimeProvider.getSelectionEnd();
    for (ILinkEvent link : fItemData.fLinks) {
        if (link.getEntry() == trace && link.getTime() == selectedTime) {
            selectItem(link.getDestinationEntry(), false);
            if (link.getDuration() != 0) {
                if (extend) {
                    fTimeProvider.setSelectionRangeNotify(fTimeProvider.getSelectionBegin(), link.getTime() + link.getDuration(), true);
                } else {
                    fTimeProvider.setSelectedTimeNotify(link.getTime() + link.getDuration(), true);
                }
                // Notify if visible time window has been adjusted
                fTimeProvider.setStartFinishTimeNotify(fTimeProvider.getTime0(), fTimeProvider.getTime1());
            }
            fireSelectionChanged();
            updateStatusLine(STATUS_WITHOUT_CURSOR_TIME);
            return;
        }
    }
    selectNextEvent(extend);
}
Also used : ILinkEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)

Aggregations

ILinkEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent)12 ArrayList (java.util.ArrayList)6 ITimeGraphEntry (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry)6 TimeLinkEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent)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)4 List (java.util.List)2 Random (java.util.Random)2 Point (org.eclipse.swt.graphics.Point)2 ITimeGraphArrow (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow)2 ITimeGraphDataProvider (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMap (java.util.LinkedHashMap)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)1 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)1 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)1