use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException 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.exceptions.TimeRangeException in project tracecompass by tracecompass.
the class InMemoryBackendTest method init.
/**
* Test setup. make a state system that is moderately large
*/
@BeforeClass
public static void init() {
IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(SSID, 0);
for (int attribute = 0; attribute < NUMBER_OF_ATTRIBUTES; attribute++) {
for (int timeStart = 0; timeStart < 1000; timeStart++) {
try {
final int stateEndTime = (timeStart * 100) + 90 + attribute;
final int stateStartTime = timeStart * 100 + attribute;
backend.insertPastState(stateStartTime, stateEndTime, attribute, timeStart % 100);
if (timeStart != 999) {
backend.insertPastState(stateEndTime + 1, stateEndTime + 9, attribute, (Object) null);
}
} catch (TimeRangeException e) {
/* Should not happen here */
throw new IllegalStateException();
}
}
}
fixture = backend;
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException in project tracecompass by tracecompass.
the class InMemoryBackendTest method testDoQuery.
/**
* Query the state system
*/
@Test
public void testDoQuery() {
List<@Nullable ITmfStateInterval> interval = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
interval.add(null);
}
IStateHistoryBackend backend = fixture;
assertNotNull(backend);
try {
backend.doQuery(interval, 950);
} catch (TimeRangeException | StateSystemDisposedException e) {
fail(e.getMessage());
}
assertEquals(NUMBER_OF_ATTRIBUTES, interval.size());
testInterval(interval.get(0), 900, 990, 9);
testInterval(interval.get(1), 901, 991, 9);
testInterval(interval.get(2), 902, 992, 9);
testInterval(interval.get(3), 903, 993, 9);
testInterval(interval.get(4), 904, 994, 9);
testInterval(interval.get(5), 905, 995, 9);
testInterval(interval.get(6), 906, 996, 9);
testInterval(interval.get(7), 907, 997, 9);
testInterval(interval.get(8), 908, 998, 9);
testInterval(interval.get(9), 909, 999, 9);
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException 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());
}
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException in project tracecompass by tracecompass.
the class HTInterval method readFrom.
/**
* Reader factory method. Builds the interval using an already-allocated
* ByteBuffer, which normally comes from a NIO FileChannel.
*
* The interval is just a start, end, attribute and value, this is the
* layout of the HTInterval on disk
* <ul>
* <li>start (2-9 bytes)</li>
* <li>end (2-9 bytes)</li>
* <li>attribute (4 bytes)</li>
* <li>sv type (1 byte)</li>
* <li>sv ( 0 bytes for null, 4 for int , 8 for long and double, and the
* length of the string +2 for strings (it's variable))</li>
* </ul>
*
* @param buffer
* The ByteBuffer from which to read the information
* @param nodeStart
* The start time of the node this interval is linked to
* @return The interval object
* @throws IOException
* If there was an error reading from the buffer
*/
public static final HTInterval readFrom(ByteBuffer buffer, long nodeStart) throws IOException {
Object value;
int posStart = buffer.position();
/* Read the Data Section entry */
long intervalStart = HTVarInt.readLong(buffer) + nodeStart;
long intervalEnd = HTVarInt.readLong(buffer) + intervalStart;
int attribute = buffer.getInt();
/* Read the 'type' of the value, then react accordingly */
byte valueType = buffer.get();
switch(valueType) {
case TYPE_NULL:
value = null;
break;
case TYPE_INTEGER:
value = buffer.getInt();
break;
case TYPE_STRING:
{
/* the first short = the size to read */
int valueSize = buffer.getShort();
byte[] array = new byte[valueSize];
buffer.get(array);
value = new String(array, CHARSET);
/* Confirm the 0'ed byte at the end */
byte res = buffer.get();
if (res != 0) {
throw new IOException(errMsg);
}
break;
}
case TYPE_LONG:
/* Go read the matching entry in the Strings section of the block */
value = buffer.getLong();
break;
case TYPE_DOUBLE:
/* Go read the matching entry in the Strings section of the block */
value = buffer.getDouble();
break;
case TYPE_CUSTOM:
{
short valueSize = buffer.getShort();
ISafeByteBufferReader safeBuffer = SafeByteBufferFactory.wrapReader(buffer, valueSize);
value = CustomStateValue.readSerializedValue(safeBuffer);
break;
}
default:
/* Unknown data, better to not make anything up... */
throw new IOException(errMsg);
}
try {
return new HTInterval(intervalStart, intervalEnd, attribute, value, buffer.position() - posStart);
} catch (TimeRangeException e) {
throw new IOException(errMsg);
}
}
Aggregations