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