Search in sources :

Example 26 with TimeQueryFilter

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);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) SelectedCpuQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCpuQueryFilter) CpuUsageDataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.cpuusage.CpuUsageDataProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel) Test(org.junit.Test)

Example 27 with TimeQueryFilter

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());
    }
}
Also used : ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) List(java.util.List) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)

Example 28 with TimeQueryFilter

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);
}
Also used : NavigableSet(java.util.NavigableSet) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITimeGraphArrow(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)28 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)16 NonNull (org.eclipse.jdt.annotation.NonNull)14 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)14 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)4 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 CpuUsageEntryModel (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)3 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)3 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)3 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)3 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)3 ITimeGraphArrow (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow)3