use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class CpuUsageDataProviderTest method testTree.
/**
* Test the
* {@link CpuUsageDataProvider#fetchTree(Map, IProgressMonitor)}
* method.
* <p>
*/
@Test
public void testTree() {
CpuUsageDataProvider dataProvider = fDataProvider;
IProgressMonitor monitor = new NullProgressMonitor();
/* This range should query the total range */
TimeQueryFilter filter = new SelectedCpuQueryFilter(0L, 30L, 2, Collections.emptyList(), Collections.emptySet());
@NonNull Map<@NonNull String, @NonNull Object> parameters = new HashMap<>();
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
parameters.put(DataProviderParameterUtils.REQUESTED_ITEMS_KEY, Collections.emptyList());
parameters.put("cpus", Collections.emptySet());
TmfModelResponse<@NonNull TmfTreeModel<@NonNull CpuUsageEntryModel>> response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
TmfTreeModel<@NonNull CpuUsageEntryModel> model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
Map<Integer, Long> expected = new HashMap<>();
expected.put(1, 5L);
expected.put(2, 19L);
expected.put(3, 11L);
expected.put(4, 13L);
expected.put(-2, 48L);
compareModel(expected, model);
/* Verify a range when a process runs at the start */
filter = new SelectedCpuQueryFilter(22L, 25L, 2, Collections.emptyList(), Collections.emptySet());
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
expected.clear();
expected.put(3, 3L);
expected.put(4, 3L);
expected.put(-2, 6L);
compareModel(expected, model);
/* Verify a range when a process runs at the end */
filter = new SelectedCpuQueryFilter(1L, 4L, 2, Collections.emptyList(), Collections.emptySet());
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
expected.clear();
expected.put(2, 3L);
expected.put(3, 1L);
expected.put(4, 2L);
expected.put(-2, 6L);
compareModel(expected, model);
/* Verify a range when a process runs at start and at the end */
filter = new SelectedCpuQueryFilter(4L, 13L, 2, Collections.emptyList(), Collections.emptySet());
parameters.put(DataProviderParameterUtils.REQUESTED_TIME_KEY, getTimeRequested(filter));
response = dataProvider.fetchTree(parameters, monitor);
assertTrue(response.getStatus() == Status.COMPLETED);
model = response.getModel();
assertNotNull(model);
/* Maps a tid to the total time */
expected.clear();
expected.put(2, 9L);
expected.put(3, 5L);
expected.put(4, 4L);
expected.put(-2, 18L);
compareModel(expected, model);
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class ThreadStatusDataProviderTest method assertArrows.
private static void assertArrows(ThreadStatusDataProvider provider, Map<Long, String> idsToNames) throws IOException {
TmfModelResponse<List<ITimeGraphArrow>> arrowResponse = provider.fetchArrows(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(1, 80, 80)), null);
assertNotNull(arrowResponse);
assertEquals(ITmfResponse.Status.COMPLETED, arrowResponse.getStatus());
List<ITimeGraphArrow> arrows = arrowResponse.getModel();
assertNotNull(arrows);
List<String> expectedStrings = Files.readAllLines(Paths.get("testfiles/kernel_analysis/expectedThreadStatusArrows"));
assertEquals(expectedStrings.size(), arrows.size());
for (int i = 0; i < expectedStrings.size(); i++) {
String expectedString = expectedStrings.get(i);
String[] split = expectedString.split(",");
ITimeGraphArrow arrow = arrows.get(i);
assertEquals(split[0], idsToNames.get(arrow.getSourceId()));
assertEquals(split[1], idsToNames.get(arrow.getDestinationId()));
assertEquals(Long.parseLong(split[2]), arrow.getStartTime());
assertEquals(Long.parseLong(split[3]), arrow.getDuration());
}
}
use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.
the class ThreadStatusDataProvider method fetchArrows.
@Override
@NonNull
public TmfModelResponse<@NonNull List<@NonNull ITimeGraphArrow>> fetchArrows(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, IProgressMonitor monitor) {
ITmfStateSystem ss = fModule.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
List<@NonNull ITimeGraphArrow> linkList = new ArrayList<>();
/**
* MultiMap of the current thread intervals, grouped by CPU, by increasing start
* time.
*/
TreeMultimap<Integer, ITmfStateInterval> currentThreadIntervalsMap = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(ITmfStateInterval::getStartTime));
List<Integer> quarks = ss.getQuarks(Attributes.CPUS, WILDCARD, Attributes.CURRENT_THREAD);
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
Collection<Long> times = getTimes(ss, filter);
try {
/* Do the actual query */
for (ITmfStateInterval interval : ss.query2D(quarks, times)) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
currentThreadIntervalsMap.put(interval.getAttribute(), interval);
}
/* Get the arrows. */
for (Collection<ITmfStateInterval> currentThreadIntervals : currentThreadIntervalsMap.asMap().values()) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
linkList.addAll(createCpuArrows(ss, (NavigableSet<ITmfStateInterval>) currentThreadIntervals));
}
} catch (TimeRangeException | StateSystemDisposedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, String.valueOf(e.getMessage()));
}
return new TmfModelResponse<>(linkList, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Aggregations