Search in sources :

Example 1 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class CounterDataProvider method internalFetch.

@Nullable
private Collection<IYModel> internalFetch(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    SelectedCounterQueryFilter filter = createCounterQuery(fetchParameters);
    if (filter == null) {
        return null;
    }
    long stateSystemEndTime = ss.getCurrentEndTime();
    Collection<Long> times = extractRequestedTimes(ss, filter, stateSystemEndTime);
    Map<Long, Integer> entries = Maps.filterValues(getSelectedEntries(filter), q -> ss.getSubAttributes(q, false).isEmpty());
    TreeMultimap<Integer, ITmfStateInterval> countersIntervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparingLong(ITmfStateInterval::getStartTime));
    Iterable<@NonNull ITmfStateInterval> query2d = ss.query2D(entries.values(), times);
    for (ITmfStateInterval interval : query2d) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        countersIntervals.put(interval.getAttribute(), interval);
    }
    ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder();
    for (Entry<Long, Integer> entry : entries.entrySet()) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        int quark = entry.getValue();
        double[] yValues = buildYValues(countersIntervals.get(quark), filter);
        String seriesName = getTrace().getName() + '/' + ss.getFullAttributePath(quark);
        ySeries.add(new YModel(entry.getKey(), seriesName, yValues));
    }
    return ySeries.build();
}
Also used : YModel(org.eclipse.tracecompass.tmf.core.model.YModel) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) ImmutableList(com.google.common.collect.ImmutableList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) SelectedCounterQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectedCounterQueryFilter) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class CounterDataProvider method buildYValues.

private static double[] buildYValues(NavigableSet<ITmfStateInterval> countersIntervals, SelectedCounterQueryFilter filter) {
    long[] times = filter.getTimesRequested();
    boolean isCumulative = filter.isCumulative();
    double[] yValues = new double[times.length];
    long prevValue = 0L;
    if (!countersIntervals.isEmpty()) {
        Object value = countersIntervals.first().getValue();
        if (value instanceof Number) {
            prevValue = ((Number) value).longValue();
        }
    }
    int to = 0;
    for (ITmfStateInterval interval : countersIntervals) {
        int from = Arrays.binarySearch(times, interval.getStartTime());
        from = (from >= 0) ? from : -1 - from;
        Number value = (Number) interval.getValue();
        long l = value != null ? value.longValue() : 0l;
        if (isCumulative) {
            /* Fill in all the time stamps that the interval overlaps */
            to = Arrays.binarySearch(times, interval.getEndTime());
            to = (to >= 0) ? to + 1 : -1 - to;
            Arrays.fill(yValues, from, to, l);
        } else {
            yValues[from] = (l - prevValue);
        }
        prevValue = l;
    }
    /* Fill the time stamps after the state system, if any. */
    if (isCumulative) {
        Arrays.fill(yValues, to, yValues.length, prevValue);
    }
    return yValues;
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

Example 3 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemTest method testFullQuery1.

@Test
public void testFullQuery1() {
    List<ITmfStateInterval> list;
    ITmfStateInterval interval;
    int quark, valueInt;
    String valueStr;
    try {
        list = fixture.queryFullState(interestingTimestamp1);
        quark = fixture.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
        interval = list.get(quark);
        valueInt = interval.getStateValue().unboxInt();
        assertEquals(1397, valueInt);
        quark = fixture.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME);
        interval = list.get(quark);
        valueStr = interval.getStateValue().unboxStr();
        assertEquals("gdbus", valueStr);
        quark = fixture.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.SYSTEM_CALL);
        interval = list.get(quark);
        valueStr = interval.getStateValue().unboxStr();
        assertEquals("poll", valueStr);
    } catch (AttributeNotFoundException | StateSystemDisposedException e) {
        fail();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) Test(org.junit.Test)

Example 4 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemTest method testQueryInvalidValuetype1.

/**
 * Query but with the wrong State Value type
 */
@Test(expected = StateValueTypeException.class)
public void testQueryInvalidValuetype1() throws StateValueTypeException {
    List<ITmfStateInterval> list;
    ITmfStateInterval interval;
    int quark;
    try {
        list = fixture.queryFullState(interestingTimestamp1);
        quark = fixture.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
        interval = list.get(quark);
        /* This is supposed to be an int value */
        interval.getStateValue().unboxStr();
    } catch (AttributeNotFoundException | StateSystemDisposedException e) {
        fail();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) Test(org.junit.Test)

Example 5 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemTest method testRangeQuery2.

/**
 * Range query, but with a t2 far off the end of the trace. The result
 * should still be valid.
 */
@Test
public void testRangeQuery2() {
    List<ITmfStateInterval> intervals;
    final ITmfStateSystem ss = fixture;
    assertNotNull(ss);
    try {
        int quark = ss.getQuarkAbsolute(Attributes.CPUS, Integer.toString(0), Attributes.IRQS, "1");
        long ts1 = ss.getStartTime();
        /* start of the trace */
        long ts2 = startTime + 20L * NANOSECS_PER_SEC;
        /* invalid, but ignored */
        intervals = StateSystemUtils.queryHistoryRange(ss, quark, ts1, ts2);
        /* Activity of IRQ 1 over the whole trace */
        assertEquals(65, intervals.size());
    } catch (AttributeNotFoundException | StateSystemDisposedException e) {
        fail();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Aggregations

ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)155 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)78 Test (org.junit.Test)56 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)52 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)41 ArrayList (java.util.ArrayList)37 NonNull (org.eclipse.jdt.annotation.NonNull)27 Nullable (org.eclipse.jdt.annotation.Nullable)20 HashMap (java.util.HashMap)19 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)16 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)15 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)14 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)12 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)12 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)12 ImmutableList (com.google.common.collect.ImmutableList)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)11 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)11