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();
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations