Search in sources :

Example 1 with TmfStateInterval

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

the class InMemoryBackendTest method testQueryAttribute.

/**
 * Test single attribute then compare it to a full query
 */
@Test
public void testQueryAttribute() {
    try {
        IStateHistoryBackend backend = fixture;
        assertNotNull(backend);
        ITmfStateInterval[] interval = new TmfStateInterval[10];
        for (int i = 0; i < 10; i++) {
            interval[i] = backend.doSingularQuery(950, i);
        }
        testInterval(interval[0], 900, 990, 9);
        testInterval(interval[1], 901, 991, 9);
        testInterval(interval[2], 902, 992, 9);
        testInterval(interval[3], 903, 993, 9);
        testInterval(interval[4], 904, 994, 9);
        testInterval(interval[5], 905, 995, 9);
        testInterval(interval[6], 906, 996, 9);
        testInterval(interval[7], 907, 997, 9);
        testInterval(interval[8], 908, 998, 9);
        testInterval(interval[9], 909, 999, 9);
        List<@Nullable ITmfStateInterval> intervalQuery = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
        for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
            intervalQuery.add(null);
        }
        backend.doQuery(intervalQuery, 950);
        ITmfStateInterval[] ref = intervalQuery.toArray(new ITmfStateInterval[0]);
        assertArrayEquals(ref, interval);
    } catch (TimeRangeException | StateSystemDisposedException e) {
        fail(e.getMessage());
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 2 with TmfStateInterval

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

the class StateHistoryBackendTestBase method testFullIntervals.

/**
 * Test the full query method by filling a small backend with intervals that
 * take the full time range, like this:
 *
 * <pre>
 * |x-------------x|
 * |x-------------x|
 * |x-------------x|
 * |x-------------x|
 * |      ...      |
 * </pre>
 *
 * and then querying at every single timestamp, making sure all, and only,
 * the expected intervals are returned.
 */
@Test
public void testFullIntervals() {
    final int nbAttr = 1000;
    final long startTime = 0;
    final long endTime = 1000;
    List<ITmfStateInterval> intervals = new ArrayList<>();
    for (int attr = 0; attr < nbAttr; attr++) {
        intervals.add(new TmfStateInterval(startTime, endTime, attr, attr));
    }
    buildAndQueryFullRange(startTime, endTime, nbAttr, intervals, false);
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with TmfStateInterval

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

the class TmfIntervalDeserializer method deserialize.

@Override
public ITmfStateInterval deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
    JsonObject object = json.getAsJsonObject();
    long start = object.get(TmfIntervalStrings.START).getAsLong();
    long end = object.get(TmfIntervalStrings.END).getAsLong();
    int quark = object.get(TmfIntervalStrings.QUARK).getAsInt();
    String type = object.get(TmfIntervalStrings.TYPE).getAsString();
    if (type.equals(TmfIntervalStrings.NULL)) {
        return new TmfStateInterval(start, end, quark, (Object) null);
    }
    JsonElement value = object.get(TmfIntervalStrings.VALUE);
    try {
        Class<?> typeClass = Class.forName(type);
        if (typeClass.isAssignableFrom(CustomStateValue.class)) {
            String encoded = value.getAsString();
            byte[] serialized = Base64.getDecoder().decode(encoded);
            ByteBuffer buffer = ByteBuffer.wrap(serialized);
            ISafeByteBufferReader sbbr = SafeByteBufferFactory.wrapReader(buffer, serialized.length);
            TmfStateValue sv = CustomStateValue.readSerializedValue(sbbr);
            return new TmfStateInterval(start, end, quark, sv.unboxValue());
        }
        if (typeClass.isAssignableFrom(Integer.class)) {
            return new TmfStateInterval(start, end, quark, value.getAsInt());
        } else if (typeClass.isAssignableFrom(Long.class)) {
            return new TmfStateInterval(start, end, quark, value.getAsLong());
        } else if (typeClass.isAssignableFrom(Double.class)) {
            return new TmfStateInterval(start, end, quark, value.getAsDouble());
        } else if (typeClass.isAssignableFrom(String.class)) {
            return new TmfStateInterval(start, end, quark, value.getAsString());
        }
    } catch (ClassNotFoundException e) {
    // Fall through
    }
    // last ditch attempt
    return new TmfStateInterval(start, end, quark, value.toString());
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) JsonObject(com.google.gson.JsonObject) ByteBuffer(java.nio.ByteBuffer) ISafeByteBufferReader(org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferReader) JsonElement(com.google.gson.JsonElement) TmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue)

Example 4 with TmfStateInterval

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

the class TmfMipmapFeature method updateAndCloseMipmap.

@Override
public void updateAndCloseMipmap() {
    if (!currentValue.isNull()) {
        ITmfStateInterval interval = new TmfStateInterval(currentStartTime, currentStartTime, getLevelQuark(0), currentValue.unboxValue());
        intervals.get(0).add(interval);
    }
    for (int level = 1; level <= getNbLevels(); level++) {
        updateMipmapLevel(level, currentStartTime);
    }
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

Example 5 with TmfStateInterval

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

the class KernelThreadInformationProviderTest method testGetStatusIntervalsForThread.

/**
 * Test the
 * {@link KernelThreadInformationProvider#getStatusIntervalsForThread(KernelAnalysisModule, Integer, long, long, long, IProgressMonitor)}
 * method
 */
@Test
public void testGetStatusIntervalsForThread() {
    KernelAnalysisModule module = checkNotNull(fModule);
    IProgressMonitor monitor = new NullProgressMonitor();
    Integer process21 = 21;
    Integer process20 = 20;
    /* Check invalid time ranges */
    List<ITmfStateInterval> intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process21, -15, -5, 3, monitor);
    assertTrue(intervals.isEmpty());
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process21, 90, 1500000000L, 50, monitor);
    assertTrue(intervals.isEmpty());
    /* Check invalid quarks */
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, -1, 0, 70L, 3, monitor);
    assertTrue(intervals.isEmpty());
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, 0, 0, 70L, 3, monitor);
    assertTrue(intervals.isEmpty());
    /* Check different time ranges and resolutions */
    ProcessStatus[] values = { ProcessStatus.NOT_ALIVE, ProcessStatus.WAIT_CPU, ProcessStatus.RUN, ProcessStatus.WAIT_CPU, ProcessStatus.RUN };
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process21, 0, 70L, 3, monitor);
    testIntervals("tid 21 [0,70,3]", intervals, values);
    ProcessStatus[] values2 = { ProcessStatus.NOT_ALIVE, ProcessStatus.RUN, ProcessStatus.RUN };
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process21, 1, 70L, 30, monitor);
    testIntervals("tid 21 [0,70,30]", intervals, values2);
    ProcessStatus[] values3 = { ProcessStatus.WAIT_CPU, ProcessStatus.RUN };
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process21, 25, 50L, 3, monitor);
    testIntervals("tid 21 [25,50,3]", intervals, values3);
    ImmutableList<ITmfStateInterval> expectedIntervals = ImmutableList.of(new TmfStateInterval(1, 9, 0, ProcessStatus.NOT_ALIVE.getStateValue().unboxValue()), new TmfStateInterval(10, 19, 0, ProcessStatus.WAIT_UNKNOWN.getStateValue().unboxValue()), new TmfStateInterval(20, 29, 0, ProcessStatus.RUN.getStateValue().unboxValue()), new TmfStateInterval(30, 69, 0, ProcessStatus.WAIT_BLOCKED.getStateValue().unboxValue()));
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process20, 0, 70L, 3, monitor);
    compareIntervals(expectedIntervals, intervals);
    expectedIntervals = ImmutableList.of(new TmfStateInterval(1, 9, 0, ProcessStatus.NOT_ALIVE.getStateValue().unboxValue()), new TmfStateInterval(30, 69, 0, ProcessStatus.WAIT_BLOCKED.getStateValue().unboxValue()));
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process20, 1, 70L, 30, monitor);
    compareIntervals(expectedIntervals, intervals);
    ProcessStatus[] values6 = { ProcessStatus.RUN, ProcessStatus.WAIT_BLOCKED };
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process20, 25, 50L, 3, monitor);
    testIntervals("tid 20 [25,50,3]", intervals, values6);
    ProcessStatus[] values7 = { ProcessStatus.WAIT_CPU };
    intervals = KernelThreadInformationProvider.getStatusIntervalsForThread(module, process20, 80L, 85L, 3, monitor);
    testIntervals("tid 20 [80,85,3]", intervals, values7);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) ProcessStatus(org.eclipse.tracecompass.analysis.os.linux.core.model.ProcessStatus) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) KernelAnalysisModule(org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule) Test(org.junit.Test)

Aggregations

ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)11 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)11 Test (org.junit.Test)5 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)4 ArrayList (java.util.ArrayList)3 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)2 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)2 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 KernelAnalysisModule (org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule)1 ProcessStatus (org.eclipse.tracecompass.analysis.os.linux.core.model.ProcessStatus)1 ISafeByteBufferReader (org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferReader)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1