Skip to content

Commit

Permalink
Update UFTrace to handle new format
Browse files Browse the repository at this point in the history
Fix thread name being the process name.
Simplify Callstack provider.
Add extra entry support to Map and Symbol parsers.

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Change-Id: I325098d3e6b3d10a09d5004f38c2784a4e6498de
  • Loading branch information
MatthewKhouzam committed Feb 26, 2024
1 parent 9a73718 commit 93074b6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.tracecompass.incubator.callstack.core.instrumented.statesystem.CallStackStateProvider;
import org.eclipse.tracecompass.incubator.internal.uftrace.core.trace.DatEvent;
import org.eclipse.tracecompass.incubator.internal.uftrace.core.trace.UfEventType;
import org.eclipse.tracecompass.incubator.internal.uftrace.core.trace.Uftrace.ExecAspect;
import org.eclipse.tracecompass.incubator.internal.uftrace.core.trace.Uftrace.PidAspect;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
Expand All @@ -34,7 +33,6 @@
public class UfCallstackProvider extends CallStackStateProvider {


private final ITmfEventAspect<String> fExecAspect;
private final ITmfEventAspect<Integer> fTidAspect;
private final ITmfEventAspect<Integer> fPidAspect;

Expand All @@ -46,14 +44,13 @@ public class UfCallstackProvider extends CallStackStateProvider {
*/
public UfCallstackProvider(@NonNull ITmfTrace trace) {
super(trace);
fExecAspect = (ITmfEventAspect<String>) MultiAspect.<String>create(TmfTraceUtils.getEventAspects(trace, ExecAspect.class), ExecAspect.class);
fTidAspect = (ITmfEventAspect<Integer>) MultiAspect.<Integer>create(TmfTraceUtils.getEventAspects(trace, LinuxTidAspect.class), LinuxTidAspect.class);
fPidAspect = (ITmfEventAspect<Integer>) MultiAspect.<Integer>create(TmfTraceUtils.getEventAspects(trace, PidAspect.class), PidAspect.class);
}

@Override
public int getVersion() {
return 2;
return 3;
}

@Override
Expand Down Expand Up @@ -92,11 +89,6 @@ protected boolean considerEvent(@NonNull ITmfEvent event) {
return null;
}

@Override
protected @Nullable String getProcessName(@NonNull ITmfEvent event) {
return fExecAspect.resolve(event);
}

@Override
protected int getProcessId(@NonNull ITmfEvent event) {
Integer resolve = fPidAspect.resolve(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class MapEntry {

private final Perms fPerms;

private final String fExtra;

/**
* A map entry
*
Expand All @@ -53,10 +55,12 @@ public class MapEntry {
* inode location of the device
* @param pathName
* file path that backs this mapping (there may be pseudo-paths
* in brackes [])
* in brackets [])
* @param extra
* anything extra, e.g. build info
*/
public MapEntry(long addrLow, long addrHigh, Perms perms, long offset, char deviceMinor, char deviceMajor, long iNode,
String pathName) {
String pathName, String extra) {
fAddrLow = addrLow;
fAddrHigh = addrHigh;
fPerms = perms;
Expand All @@ -65,6 +69,7 @@ public MapEntry(long addrLow, long addrHigh, Perms perms, long offset, char devi
fDeviceMinor = deviceMinor;
fINode = iNode;
fPathName = pathName;
fExtra = extra;
}

/**
Expand Down Expand Up @@ -142,4 +147,11 @@ public Perms getPerms() {
return fPerms;
}

/**
* @return the extra
*/
public String getExtra() {
return fExtra;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MapParser {
private static final String SESSION_PATTERN_STRING = "sid\\-([a-fA-F0-9]+)\\.map"; //$NON-NLS-1$
private static final Pattern SESSION_PATTERN = Pattern.compile(SESSION_PATTERN_STRING);
private static final Pattern MAPFILE_PATTERN = Pattern.compile(
"^\\s*([a-fA-F0-9]+)\\-([a-fA-F0-9]+)\\s+([rxwps-]+)\\s+([a-fA-F0-9]+)\\s+([a-fA-F0-9]+)\\:([a-fA-F0-9]+)\\s+([a-fA-F0-9]+)\\s*(\\S+)?$"); //$NON-NLS-1$
"^\\s*([a-fA-F0-9]+)\\-([a-fA-F0-9]+)\\s+([rxwps-]+)\\s+([a-fA-F0-9]+)\\s+([a-fA-F0-9]+)\\:([a-fA-F0-9]+)\\s+([a-fA-F0-9]+)\\s*(\\S*)\\s*(\\S*)"); //$NON-NLS-1$
private final long fSessionId;
private final NavigableMap<Long, MapEntry> fData;

Expand All @@ -62,18 +62,19 @@ public static MapParser create(File file) throws IOException {
while (iter.hasNext()) {
String line = iter.next();
Matcher matcher = MAPFILE_PATTERN.matcher(line);
matcher.matches();
long addrLow = Long.parseUnsignedLong(matcher.group(1), 16);
long addrHigh = Long.parseUnsignedLong(matcher.group(2), 16);
Perms perms = Perms.create(matcher.group(3));
long offset = Long.parseLong(matcher.group(4), 16);
char deviceHigh = (char) Integer.parseInt(matcher.group(5), 16);
char deviceLow = (char) Integer.parseInt(matcher.group(6), 16);
long iNode = Long.parseLong(matcher.group(7), 16);
String pathName = matcher.group(8);

entries.put(addrLow,
new MapEntry(addrLow, addrHigh, perms, offset, deviceLow, deviceHigh, iNode, pathName));
if (matcher.matches()) {
long addrLow = Long.parseUnsignedLong(matcher.group(1), 16);
long addrHigh = Long.parseUnsignedLong(matcher.group(2), 16);
Perms perms = Perms.create(matcher.group(3));
long offset = Long.parseLong(matcher.group(4), 16);
char deviceHigh = (char) Integer.parseInt(matcher.group(5), 16);
char deviceLow = (char) Integer.parseInt(matcher.group(6), 16);
long iNode = Long.parseLong(matcher.group(7), 16);
String pathName = matcher.group(8);
String extra = matcher.group(9);
entries.put(addrLow,
new MapEntry(addrLow, addrHigh, perms, offset, deviceLow, deviceHigh, iNode, pathName, extra));
}
}
return new MapParser(sessionId, entries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
*/
public class SymParser {
private static final Pattern REGEX = Pattern.compile("^([a-fA-F\\d]+)\\s+([ABbCcDdGgiNPpRrSsTtUuVvWw\\-\\?])\\s*(.*)$"); //$NON-NLS-1$
private static final Pattern REGEX = Pattern.compile("^([a-fA-F\\d]+)\\s+([a-fA-F\\d]*)\\s*([ABbCcDdGgiNPpRrSsTtUuVvWw\\-\\?])\\s*(.*)$"); //$NON-NLS-1$

/**
* Symbol for
Expand Down Expand Up @@ -79,24 +79,26 @@ public String getName() {
* the file is not able to be read.
*/
public static SymParser parse(File file) throws IOException {
LineIterator iter = FileUtils.lineIterator(file);
SymParser sp = new SymParser();
while (iter.hasNext()) {
String line = iter.next();
if (line.startsWith("#")) {
continue;
}
Matcher match = REGEX.matcher(line);
if (!match.matches()) {
throw new IllegalArgumentException("invalid " + line); //$NON-NLS-1$

try (LineIterator iter = FileUtils.lineIterator(file)) {
SymParser sp = new SymParser();
while (iter.hasNext()) {
String line = iter.next();
if (line.startsWith("#")) { //$NON-NLS-1$
continue;
}
Matcher match = REGEX.matcher(line);
if (!match.matches()) {
throw new IllegalArgumentException("Symbol Parser: invalid line: " + line); //$NON-NLS-1$
}
long range = Long.parseUnsignedLong(match.group(1), 16);
char c = match.group(3).charAt(0);
String name = (match.groupCount() < 4) ? "Anonymous" : match.group(4); //$NON-NLS-1$
Symbol sym = new Symbol(c, name);
sp.fMap.put(range, sym);
}
long range = Long.parseUnsignedLong(match.group(1), 16);
char c = match.group(2).charAt(0);
String name = (match.groupCount() < 3) ? "Anonymous" : match.group(3); //$NON-NLS-1$
Symbol sym = new Symbol(c, name);
sp.fMap.put(range, sym);
return sp;
}
return sp;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxPidAspect;
import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
import org.eclipse.tracecompass.incubator.analysis.core.aspects.ThreadNameAspect;
import org.eclipse.tracecompass.incubator.analysis.core.aspects.ProcessNameAspect;
import org.eclipse.tracecompass.incubator.internal.uftrace.core.Activator;
import org.eclipse.tracecompass.incubator.internal.uftrace.core.trace.SymParser.Symbol;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
Expand Down Expand Up @@ -376,7 +376,7 @@ public final class PidAspect extends LinuxPidAspect {
*
* @author Matthew Khouzam
*/
public final class ExecAspect extends ThreadNameAspect {
public final class ExecAspect extends ProcessNameAspect {

@Override
public @Nullable String resolve(@NonNull ITmfEvent event) {
Expand Down

0 comments on commit 93074b6

Please sign in to comment.