use of org.eclipse.linuxtools.internal.perf.model.PMCommand in project linuxtools by eclipse.
the class ModelTest method testParseAnnotation.
@Test
public void testParseAnnotation() throws FileNotFoundException {
BufferedReader input = new BufferedReader(new FileReader("resources/perf-annotation-data"));
// Set up arguments for the annotation parser.
IPath workingDir = Path.fromOSString("/working/directory/");
PMCommand cmd = new PMCommand("testCommand");
PMDso dso = new PMDso("testDso", false);
PMFile tmpFile = new PMFile(PerfPlugin.STRINGS_UnfiledSymbols);
PMSymbol sym = new PMSymbol("testSym", 0, 0);
// Set children and respective parents.
cmd.addChild(dso);
dso.addChild(tmpFile);
tmpFile.addChild(sym);
dso.setParent(cmd);
tmpFile.setParent(dso);
sym.setParent(tmpFile);
PerfCore.parseAnnotation(null, input, workingDir, dso, sym);
// Expected results data.
String expectedDsoPath = "/working/directory/fibonacci";
String expectedFilePath = "/home/user/workspace/fibonacci/Debug/../src/fibonacci.cpp";
assertTrue(expectedDsoPath.equals(dso.getPath()));
assertEquals(dso.getChildren().length, 2);
for (TreeParent dsoChild : dso.getChildren()) {
String filePath = ((PMFile) dsoChild).getPath();
if (PerfPlugin.STRINGS_UnfiledSymbols.equals(filePath)) {
assertFalse(dsoChild.hasChildren());
} else {
assertTrue(expectedFilePath.equals(filePath));
assertTrue(dsoChild.hasChildren());
assertEquals(dsoChild.getChildren().length, 1);
TreeParent curSym = dsoChild.getChildren()[0];
assertTrue(curSym.hasChildren());
assertEquals(curSym.getChildren().length, 5);
float percentCount = 0;
for (TreeParent symChild : curSym.getChildren()) {
percentCount += symChild.getPercent();
}
assertEquals(Math.ceil(percentCount), 100.0, 0.0);
}
}
}
use of org.eclipse.linuxtools.internal.perf.model.PMCommand in project linuxtools by eclipse.
the class PerfCore method parseRemoteReport.
private static void parseRemoteReport(ILaunchConfiguration config, IPath workingDir, IProgressMonitor monitor, String perfDataLoc, PrintStream print, TreeParent invisibleRoot, boolean oldPerfVersion, BufferedReader input, BufferedReader error, IProject project) {
if (monitor != null && monitor.isCanceled()) {
return;
}
String line = null;
String[] items;
float percent;
Process p = null;
double samples;
String comm, dso, symbol;
boolean kernelFlag;
PMEvent currentEvent = null;
PMCommand currentCommand = null;
PMDso currentDso = null;
PMFile currentFile = null;
PMSymbol currentSym = null;
try {
while ((line = input.readLine()) != null) {
if (monitor != null && monitor.isCanceled()) {
return;
}
// line containing report information
if ((line.startsWith("#"))) {
// $NON-NLS-1$
if (line.contains("Events:") || line.contains("Samples:")) {
// ignore lost samples as the plugin has no logic for handling them
if (line.startsWith("# Total Lost Samples:")) {
// $NON-NLS-1$
continue;
}
// $NON-NLS-1$
String[] tmp = line.trim().split(" ");
String event = tmp[tmp.length - 1];
// In this case, the event name is single quoted
if (line.contains("Samples:")) {
// $NON-NLS-1$
event = event.substring(1, event.length() - 1);
}
currentEvent = new PMEvent(event);
invisibleRoot.addChild(currentEvent);
currentCommand = null;
currentDso = null;
} else if (line.contains("Samples:")) {
// $NON-NLS-1$
if (print != null) {
print.println("WARNING: You are running an older version of Perf, please update if you can. The plugin may produce unpredictable results.");
}
// $NON-NLS-1$
invisibleRoot.addChild(new PMEvent("WARNING: You are running an older version of Perf, the plugin may produce unpredictable results."));
}
// contains profiled information
} else {
// using custom field separator. for default whitespace use " +" //$NON-NLS-1$
items = line.trim().split("" + (char) 1);
if (items.length != 5) {
continue;
}
// $NON-NLS-1$ //$NON-NLS-2$
percent = Float.parseFloat(items[0].replace("%", ""));
// samples column
samples = Double.parseDouble(items[1].trim());
// command column
comm = items[2].trim();
// dso column
dso = items[3].trim();
// symbol column
symbol = items[4].trim();
// $NON-NLS-1$ //$NON-NLS-2$
kernelFlag = ("" + symbol.charAt(1)).equals("k");
// initialize current command if it doesn't exist
if ((currentCommand == null) || (!currentCommand.getName().equals(comm))) {
currentCommand = (PMCommand) currentEvent.getChild(comm);
if (currentCommand == null) {
currentCommand = new PMCommand(comm);
currentEvent.addChild(currentCommand);
}
}
// initialize current dso if it doesn't exist
if ((currentDso == null) || (!currentDso.getName().equals(dso))) {
currentDso = (PMDso) currentCommand.getChild(dso);
if (currentDso == null) {
currentDso = new PMDso(dso, kernelFlag);
currentCommand.addChild(currentDso);
}
}
/*
* Initialize the current file, and symbol
*
* We won't know the name of the file containing the symbol
* until we run 'perf annotate' to resolve it, so for now we
* attach all symbols as children of 'Unfiled Symbols'.
*/
currentFile = currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols);
currentSym = new PMSymbol(symbol, percent, samples);
currentFile.addChild(currentSym);
}
}
} catch (IOException e) {
logException(e);
}
// $NON-NLS-1$
spitStream(error, "Perf Report", print);
boolean SourceLineNumbers = PerfPlugin.ATTR_SourceLineNumbers_default;
boolean Kernel_SourceLineNumbers = PerfPlugin.ATTR_Kernel_SourceLineNumbers_default;
try {
// Check if resolving source file/line numbers is selected
SourceLineNumbers = config.getAttribute(PerfPlugin.ATTR_SourceLineNumbers, PerfPlugin.ATTR_SourceLineNumbers_default);
Kernel_SourceLineNumbers = config.getAttribute(PerfPlugin.ATTR_Kernel_SourceLineNumbers, PerfPlugin.ATTR_Kernel_SourceLineNumbers_default);
} catch (CoreException e2) {
SourceLineNumbers = false;
}
if (monitor != null && monitor.isCanceled()) {
return;
}
boolean hasProfileData = invisibleRoot.getChildren().length != 0;
if (SourceLineNumbers) {
for (TreeParent ev : invisibleRoot.getChildren()) {
if (!(ev instanceof PMEvent))
continue;
for (TreeParent cmd : ev.getChildren()) {
if (!(cmd instanceof PMCommand))
continue;
for (TreeParent d : cmd.getChildren()) {
if (!(d instanceof PMDso))
continue;
currentDso = (PMDso) d;
if ((!Kernel_SourceLineNumbers) && currentDso.isKernelDso())
continue;
for (TreeParent s : currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols).getChildren()) {
if (!(s instanceof PMSymbol))
continue;
if (monitor != null && monitor.isCanceled()) {
return;
}
currentSym = (PMSymbol) s;
String[] annotateCmd;
if (workingDir == null) {
annotateCmd = getAnnotateString(config, currentDso.getName(), currentSym.getName().substring(4), perfDataLoc, oldPerfVersion);
} else {
// $NON-NLS-1$
String perfDefaultDataLoc = workingDir + "/" + PerfPlugin.PERF_DEFAULT_DATA;
annotateCmd = getAnnotateString(config, currentDso.getName(), currentSym.getName().substring(4), perfDefaultDataLoc, oldPerfVersion);
}
try {
if (project == null) {
p = Runtime.getRuntime().exec(annotateCmd);
} else {
StringBuffer sb = new StringBuffer();
ArrayList<String> al = new ArrayList<>();
/*
* Wrap the whole Perf annotate line as a single argument of sh command
* so that any IO redirection will take effect. Change to working directory before run perf annotate.
* It results on a command string as 'sh', '-c', 'cd <workindir> && perf annotate <args> < /dev/null'
*/
// $NON-NLS-1$
al.add("sh");
// $NON-NLS-1$
al.add("-c");
if (workingDir != null) {
// $NON-NLS-1$ //$NON-NLS-2$
sb.append("cd " + workingDir.toOSString() + " && ");
}
for (int i = 0; i < annotateCmd.length; i++) {
sb.append(annotateCmd[i]);
// $NON-NLS-1$
sb.append(" ");
}
al.add(sb.toString());
p = RuntimeProcessFactory.getFactory().exec(al.toArray(new String[] {}), project);
}
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
} catch (IOException e) {
logException(e);
}
PerfCore.parseAnnotation(monitor, input, workingDir, currentDso, currentSym);
}
if (currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols).getChildren().length == 0) {
currentDso.removeChild(currentDso.getFile(PerfPlugin.STRINGS_UnfiledSymbols));
}
// $NON-NLS-1$
spitStream(error, "Perf Annotate", print);
}
}
}
}
if (print != null) {
if (hasProfileData) {
// $NON-NLS-1$
print.println("Profile data loaded into Perf Profile View.");
} else {
// $NON-NLS-1$
print.println("No profile data generated to be displayed.");
}
}
}
Aggregations