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;
}
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);
}
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);
}
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;
}
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);
}
Aggregations