use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemTest method testRangeQuery1.
/**
* Test a range query (with no resolution parameter, so all intervals)
*/
@Test
public void testRangeQuery1() {
long time1 = interestingTimestamp1;
long time2 = time1 + 1L * NANOSECS_PER_SEC;
int quark;
List<ITmfStateInterval> intervals;
final ITmfStateSystem ss = fixture;
assertNotNull(ss);
try {
quark = ss.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
intervals = StateSystemUtils.queryHistoryRange(ss, quark, time1, time2);
assertEquals(487, intervals.size());
/* Number of context switches! */
assertEquals(1685, intervals.get(100).getStateValue().unboxInt());
assertEquals(1331668248427681372L, intervals.get(205).getEndTime());
} catch (AttributeNotFoundException | StateSystemDisposedException e) {
fail();
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class AbstractProviderTest method getCallStack.
/**
* Get the callstack for the given timestamp, for this particular trace
*/
private static String[] getCallStack(ITmfStateSystem ss, int pid, String threadName, long timestamp) {
try {
String processName = (pid == CallStackStateProvider.UNKNOWN_PID) ? CallStackStateProvider.UNKNOWN : Integer.toString(pid);
int stackAttribute = ss.getQuarkAbsolute("Processes", processName, threadName, "CallStack");
List<ITmfStateInterval> state = ss.queryFullState(timestamp);
int depth = state.get(stackAttribute).getStateValue().unboxInt();
int stackTop = ss.getQuarkRelative(stackAttribute, String.valueOf(depth));
ITmfStateValue expectedValue = state.get(stackTop).getStateValue();
ITmfStateInterval interval = StateSystemUtils.querySingleStackTop(ss, timestamp, stackAttribute);
assertNotNull(interval);
assertEquals(expectedValue, interval.getStateValue());
String[] ret = new String[depth];
for (int i = 0; i < depth; i++) {
int quark = ss.getQuarkRelative(stackAttribute, String.valueOf(i + 1));
ret[i] = Long.toHexString(state.get(quark).getStateValue().unboxLong());
}
return ret;
} catch (AttributeNotFoundException e) {
fail(e.getMessage());
} catch (StateSystemDisposedException e) {
fail(e.getMessage());
}
fail();
return null;
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class UstMemoryUsageDataProvider method getYSeriesModels.
/**
* @since 3.3
*/
@Override
@Nullable
protected Collection<IYModel> getYSeriesModels(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return null;
}
long[] xValues = filter.getTimesRequested();
long currentEnd = ss.getCurrentEndTime();
Map<Integer, IYModel> models = initYModels(ss, filter);
for (ITmfStateInterval interval : ss.query2D(models.keySet(), getTimes(filter, ss.getStartTime(), currentEnd))) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
IYModel model = models.get(interval.getAttribute());
Object value = interval.getValue();
if (model != null && value instanceof Number) {
int from = Arrays.binarySearch(xValues, interval.getStartTime());
from = (from >= 0) ? from : -1 - from;
int to = Arrays.binarySearch(xValues, interval.getEndTime());
to = (to >= 0) ? to + 1 : -1 - to;
Arrays.fill(model.getData(), from, to, ((Number) value).doubleValue());
}
}
return models.values();
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class UstDebugInfoAnalysisModule method getMatchingFile.
/**
* Get the binary file (executable or library) that corresponds to a given
* instruction pointer, at a given time.
*
* @param ts
* The timestamp
* @param vpid
* The VPID of the process we are querying for
* @param ip
* The instruction pointer of the trace event. Normally comes
* from a 'ip' context.
* @return A {@link UstDebugInfoLoadedBinaryFile} object, describing the
* binary file and its base address.
* @noreference Meant to be used internally by
* {@link UstDebugInfoBinaryAspect} only.
*/
@VisibleForTesting
@Nullable
public UstDebugInfoLoadedBinaryFile getMatchingFile(long ts, long vpid, long ip) {
try {
final ITmfStateSystem ss = getStateSystem();
if (ss == null) {
/* State system might not yet be initialized */
return null;
}
// $NON-NLS-1$
List<Integer> possibleBaddrQuarks = ss.getQuarks(String.valueOf(vpid), "*");
List<ITmfStateInterval> state = ss.queryFullState(ts);
/* Get the most probable base address from all the known ones */
OptionalLong potentialBaddr = possibleBaddrQuarks.stream().filter(quark -> Objects.equals(1, state.get(quark).getValue())).map(ss::getAttributeName).mapToLong(Long::parseLong).filter(baddr -> baddr <= ip).max();
if (!potentialBaddr.isPresent()) {
return null;
}
long baddr = potentialBaddr.getAsLong();
final int baddrQuark = ss.getQuarkAbsolute(String.valueOf(vpid), String.valueOf(baddr));
final int memszQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.MEMSZ_ATTRIB);
final long memsz = state.get(memszQuark).getStateValue().unboxLong();
/* Make sure the 'ip' fits the range of this object. */
if (!(ip < baddr + memsz)) {
/*
* Not the correct memory range after all. We do not have
* information about the library that was loaded here.
*/
return null;
}
final int pathQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.PATH_ATTRIB);
String filePath = state.get(pathQuark).getStateValue().unboxStr();
final int buildIdQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.BUILD_ID_ATTRIB);
ITmfStateValue buildIdValue = state.get(buildIdQuark).getStateValue();
String buildId = unboxStrOrNull(buildIdValue);
final int debugLinkQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.DEBUG_LINK_ATTRIB);
ITmfStateValue debugLinkValue = state.get(debugLinkQuark).getStateValue();
String debugLink = unboxStrOrNull(debugLinkValue);
final int isPicQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.IS_PIC_ATTRIB);
boolean isPic = state.get(isPicQuark).getStateValue().unboxInt() != 0;
// The baddrQuark interval lasts for the time this file is loaded
ITmfStateInterval validityInterval = state.get(baddrQuark);
return new UstDebugInfoLoadedBinaryFile(baddr, filePath, buildId, debugLink, isPic, validityInterval.getStartTime(), validityInterval.getEndTime());
} catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException e) {
/* Either the data is not available yet, or incomplete. */
return null;
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtilsTest method testIteratorOverQuarkSubrange.
/**
* Test that getIteratorOverQuark returns the correct intervals for a range
* included in the state system range
*/
@Test
public void testIteratorOverQuarkSubrange() {
ITmfStateSystem ss = fStateSystem;
assertNotNull(ss);
int quark;
try {
quark = ss.getQuarkAbsolute(DUMMY_STRING);
QuarkIterator iterator = new QuarkIterator(ss, quark, 1800L);
/* There should be one interval ranging from 1500L to 2000L */
assertTrue(iterator.hasNext());
ITmfStateInterval interval = iterator.next();
assertNotNull(interval);
assertEquals(1500L, interval.getStartTime());
assertEquals(2000L, interval.getEndTime());
/* There should not be a next interval */
assertFalse(iterator.hasNext());
} catch (AttributeNotFoundException e) {
fail(e.getMessage());
}
}
Aggregations