Search in sources :

Example 21 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class DataDrivenXYDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    if (filter == null) {
        return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    long[] xValues = filter.getTimesRequested();
    filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    Map<DisplayElement, IYModel> map = initSeries(filter);
    if (map.isEmpty()) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    ITmfStateSystem ss = null;
    for (DisplayElement de : map.keySet()) {
        ss = de.fStateSystem;
    }
    if (ss == null) {
        return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
    }
    long currentEnd = ss.getCurrentEndTime();
    try {
        for (int i = 0; i < xValues.length; i++) {
            if (monitor != null && monitor.isCanceled()) {
                return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
            }
            long time = xValues[i];
            if (time > currentEnd) {
                break;
            } else if (ss.getStartTime() <= time) {
                List<@NonNull ITmfStateInterval> full = ss.queryFullState(time);
                for (Entry<DisplayElement, IYModel> series : map.entrySet()) {
                    int attributeQuark = series.getKey().fQuark;
                    if (attributeQuark >= 0 && attributeQuark < full.size()) {
                        Object value = full.get(attributeQuark).getValue();
                        series.getValue().getData()[i] = extractValue(value);
                    }
                }
            }
        }
        // Update the series value if delta is requested
        for (Entry<DisplayElement, IYModel> series : map.entrySet()) {
            if (series.getKey().fDisplayType.equals(DisplayType.DELTA)) {
                getSeriesDelta(series.getValue().getData());
            }
        }
    } catch (StateSystemDisposedException e) {
        return TmfXyResponseFactory.createFailedResponse(e.getMessage());
    }
    boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
    return TmfXyResponseFactory.create(TITLE, xValues, ImmutableList.copyOf(map.values()), complete);
}
Also used : IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) Entry(java.util.Map.Entry) NonNull(org.eclipse.jdt.annotation.NonNull) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 22 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class TmfMipmapStateProviderTest method testQueryMipMax.

/**
 * Test a single query to the state system for a max
 *
 * Make sure the state system has data.
 *
 * Hint: the value read should always be greater than(t / 1000)
 */
@Test
public void testQueryMipMax() {
    assertNotNull(ssq);
    try {
        List<ITmfStateInterval> intervals = ssq.queryFullState(TEST_TIMESTAMP);
        int mipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.MAX_STRING);
        assertEquals("max nblevels", NB_LEVELS, intervals.get(mipmapQuark).getStateValue().unboxInt());
        for (int level = 1; level < NB_LEVELS; level++) {
            long width = (long) Math.pow(RESOLUTION, level);
            int levelQuark = ssq.getQuarkRelative(mipmapQuark, String.valueOf(level));
            ITmfStateInterval interval = intervals.get(levelQuark);
            long valueLong = interval.getStateValue().unboxLong();
            assertEquals("max value @ level " + level, width + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width, valueLong);
            assertEquals("max start time @ level " + level, START_TIME + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getStartTime());
            assertEquals("max end time @ level " + level, START_TIME + (INTERVAL * width) + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getEndTime() + 1);
        }
    } catch (TimeRangeException e) {
        fail(e.getMessage());
    } catch (StateSystemDisposedException e) {
        fail(e.getMessage());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
    assertTrue(true);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) Test(org.junit.Test)

Example 23 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class TmfMipmapStateProviderTest method testMaxLevel.

/**
 * Test a single query to the state system for the maxLevel.
 *
 * Make sure the state system has data.
 */
@Test
public void testMaxLevel() {
    assertNotNull(ssq);
    try {
        Random rn = new Random();
        long time = Math.max(INTERVAL, rn.nextLong() % END_TIME);
        List<ITmfStateInterval> intervals = ssq.queryFullState(time);
        int maxMipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.MAX_STRING);
        int nbLevelMax = intervals.get(maxMipmapQuark).getStateValue().unboxInt();
        assertEquals(NB_LEVELS, nbLevelMax);
        int minMipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.MIN_STRING);
        int nbLevelMin = intervals.get(minMipmapQuark).getStateValue().unboxInt();
        assertEquals(NB_LEVELS, nbLevelMin);
        int avgMipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.AVG_STRING);
        int nbLevelAvg = intervals.get(avgMipmapQuark).getStateValue().unboxInt();
        assertEquals(NB_LEVELS, nbLevelAvg);
    } catch (TimeRangeException e) {
        fail(e.getMessage());
    } catch (StateSystemDisposedException e) {
        fail(e.getMessage());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
    assertTrue(true);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) Random(java.util.Random) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) Test(org.junit.Test)

Example 24 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class TmfMipmapStateProviderTest method testQueryEventField.

/**
 * Test a single query to the state system for a mip
 *
 * Make sure the state system has data.
 */
@Test
public void testQueryEventField() {
    assertNotNull(ssq);
    try {
        List<ITmfStateInterval> intervals = ssq.queryFullState(TEST_TIMESTAMP);
        int eventFieldQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME);
        ITmfStateInterval interval = intervals.get(eventFieldQuark);
        long valueLong = interval.getStateValue().unboxLong();
        assertEquals(TEST_TIMESTAMP / INTERVAL, valueLong);
    } catch (TimeRangeException e) {
        fail(e.getMessage());
    } catch (StateSystemDisposedException e) {
        fail(e.getMessage());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
    assertTrue(true);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) Test(org.junit.Test)

Example 25 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class TmfMipmapStateProviderTest method testQueryMipMin.

/**
 * Test a single query to the state system for a min
 *
 * Make sure the state system has data.
 *
 * Hint: the value read should always be less than(t / 1000)
 */
@Test
public void testQueryMipMin() {
    assertNotNull(ssq);
    try {
        List<ITmfStateInterval> intervals = ssq.queryFullState(TEST_TIMESTAMP);
        int mipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.MIN_STRING);
        assertEquals("min nblevels", NB_LEVELS, intervals.get(mipmapQuark).getStateValue().unboxInt());
        for (int level = 1; level < NB_LEVELS; level++) {
            long width = (long) Math.pow(RESOLUTION, level);
            int levelQuark = ssq.getQuarkRelative(mipmapQuark, String.valueOf(level));
            ITmfStateInterval interval = intervals.get(levelQuark);
            long valueLong = interval.getStateValue().unboxLong();
            assertEquals("min value @ level " + level, 1 + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width, valueLong);
            assertEquals("min start time @ level " + level, START_TIME + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getStartTime());
            assertEquals("min end time @ level " + level, START_TIME + (INTERVAL * width) + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getEndTime() + 1);
        }
    } catch (TimeRangeException e) {
        fail(e.getMessage());
    } catch (StateSystemDisposedException e) {
        fail(e.getMessage());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
    assertTrue(true);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) Test(org.junit.Test)

Aggregations

StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)96 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)78 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)51 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)40 Test (org.junit.Test)38 NonNull (org.eclipse.jdt.annotation.NonNull)25 ArrayList (java.util.ArrayList)24 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)16 HashMap (java.util.HashMap)15 Nullable (org.eclipse.jdt.annotation.Nullable)15 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)11 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)9 Map (java.util.Map)7