use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue 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.statevalue.ITmfStateValue 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.statevalue.ITmfStateValue in project tracecompass by tracecompass.
the class StateSystemTest method testSetAndQueryOngoing.
/**
* Test modifying or updating the state value, then querying it
*/
@Test
public void testSetAndQueryOngoing() {
ITmfStateSystemBuilder ss = fSs;
assertNotNull(ss);
long time = 10;
int quark = ss.getQuarkAbsoluteAndAdd("Test");
// Modify the attribute, then query the ongoing value
long val = 10L;
ss.modifyAttribute(time, val, quark);
// Query the state value
ITmfStateValue ongoingState = ss.queryOngoingState(quark);
assertTrue(ongoingState.getType() == Type.LONG);
assertEquals(val, ongoingState.unboxLong());
// Query the value
Object ongoing = ss.queryOngoing(quark);
assertTrue(ongoing instanceof Long);
assertEquals(val, ongoing);
// Modify with a state value, the query the ongoing value
val = 12L;
ss.modifyAttribute(time + 1, val, quark);
// Query the state value
ongoingState = ss.queryOngoingState(quark);
assertTrue(ongoingState.getType() == Type.LONG);
assertEquals(val, ongoingState.unboxLong());
// Query the value
ongoing = ss.queryOngoing(quark);
assertTrue(ongoing instanceof Long);
assertEquals(val, ongoing);
// Update the ongoing value with a state value, then query
val = 14L;
ss.updateOngoingState(TmfStateValue.newValue(val), quark);
// Query the state value
ongoingState = ss.queryOngoingState(quark);
assertTrue(ongoingState.getType() == Type.LONG);
assertEquals(val, ongoingState.unboxLong());
// Query the value
ongoing = ss.queryOngoing(quark);
assertTrue(ongoing instanceof Long);
assertEquals(val, ongoing);
// Update the ongoing value, then query
val = 16L;
ss.updateOngoingState(val, quark);
// Query the state value
ongoingState = ss.queryOngoingState(quark);
assertTrue(ongoingState.getType() == Type.LONG);
assertEquals(val, ongoingState.unboxLong());
// Query the value
ongoing = ss.queryOngoing(quark);
assertTrue(ongoing instanceof Long);
assertEquals(val, ongoing);
}
use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue in project tracecompass by tracecompass.
the class TmfStateValueScenarioTest method testAttributePool.
/**
* Test that attribute pool are generated and populated correctly
*
* @throws StateSystemDisposedException
* Exceptions thrown during state system verification
* @throws AttributeNotFoundException
* Exceptions thrown during state system verification
*/
@Test
public void testAttributePool() throws AttributeNotFoundException, StateSystemDisposedException {
XmlPatternAnalysis module = fModule;
assertNotNull(module);
ITmfStateSystem ss = module.getStateSystem(module.getId());
assertNotNull(ss);
int quark = ss.getQuarkAbsolute("Operations");
List<Integer> subAttributes = ss.getSubAttributes(quark, false);
assertEquals("Number of attribute pool children", 2, subAttributes.size());
final int[] expectedStarts = { 1, 2, 3, 5, 7, 10, 14, 20, 20 };
ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("op1"), TmfStateValue.newValueString("op2"), TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.newValueString("op2"), TmfStateValue.nullValue() };
XmlUtilsTest.verifyStateIntervals("testAttributePool", ss, subAttributes.get(0), expectedStarts, expectedValues);
final int[] expectedStarts2 = { 1, 2, 3, 4, 20 };
ITmfStateValue[] expectedValues2 = { TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.newValueString("op2"), TmfStateValue.nullValue() };
XmlUtilsTest.verifyStateIntervals("testAttributePool", ss, subAttributes.get(1), expectedStarts2, expectedValues2);
}
use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue in project tracecompass by tracecompass.
the class TmfStateValueTest method testStateValueHostId.
/**
* Test using the HostID event field. It should give the host ID for value
*
* @throws StateSystemDisposedException
* Exceptions thrown during state system verification
* @throws AttributeNotFoundException
* Exceptions thrown during state system verification
*/
@Test
public void testStateValueHostId() throws AttributeNotFoundException, StateSystemDisposedException {
DataDrivenAnalysisModule module = fModule;
assertNotNull(module);
ITmfStateSystem ss = module.getStateSystem();
assertNotNull(ss);
int quark = ss.getQuarkAbsolute("hostID");
final int[] expectedStarts = { 1, 20 };
ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("testTrace4.xml") };
XmlUtilsTest.verifyStateIntervals("testHostId", ss, quark, expectedStarts, expectedValues);
}
Aggregations