use of org.eclipse.linuxtools.internal.perf.model.TreeParent in project linuxtools by eclipse.
the class ModelTest method testParserDefaultEvent.
@Test
public void testParserDefaultEvent() {
TreeParent invisibleRoot = buildModel("resources/defaultevent-data/perf.data", "resources/defaultevent-data/perf.data.txt", "resources/defaultevent-data/perf.data.err.log");
// Assert specific properties extracted by the parser.
assertEquals(invisibleRoot.getChildren().length, 1);
TreeParent event = invisibleRoot.getChildren()[0];
assertEquals(event.getName(), "cycles");
assertTrue(event.hasChildren());
assertEquals(event.getChildren().length, 1);
TreeParent cmd = event.getChildren()[0];
assertTrue(cmd.hasChildren());
assertEquals(cmd.getChildren().length, 4);
String[] cmdLabels = { "hellotest", "[kernel.kallsyms]", "ld-2.14.90.so", "perf" };
checkCommadLabels(cmdLabels, cmd);
}
use of org.eclipse.linuxtools.internal.perf.model.TreeParent 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.TreeParent in project linuxtools by eclipse.
the class ModelTest method checkChildrenPercentages.
/**
* @param root some element that will serve as the root
* @param sum the expected sum of the percentages of this root's
* immediate children
*/
private void checkChildrenPercentages(TreeParent root, float sum) {
float actualSum = 0;
// If a root has no children we're done
if (root.getChildren().length != 0) {
for (TreeParent child : root.getChildren()) {
actualSum += child.getPercent();
checkChildrenPercentages(child, child.getPercent());
}
// eg. the invisible root, and PMCommand
if (actualSum != 100 && sum != -1) {
assertTrue(actualSum / sum <= 1.0 && actualSum / sum >= 0.99);
}
}
}
use of org.eclipse.linuxtools.internal.perf.model.TreeParent 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.");
}
}
}
use of org.eclipse.linuxtools.internal.perf.model.TreeParent in project linuxtools by eclipse.
the class PerfCore method report.
// Runs assuming perf.data has already been recorded, environ and workingDir can be set to null to use default
// perfDataLoc is optional - it is used to provide a pre-existing data file instead of something recorded from
// whatever project is being profiled. It is only used for junit tests atm.
public static void report(ILaunchConfiguration config, IPath workingDir, IProgressMonitor monitor, String perfDataLoc, PrintStream print) {
IProject project = getProject(config);
TreeParent invisibleRoot = PerfPlugin.getDefault().clearModelRoot();
PerfVersion perfVersion = getPerfVersion(config);
boolean oldPerfVersion = false;
if (perfVersion == null) {
if (print != null) {
// $NON-NLS-1$
print.println("ERROR: Unable to find Perf version, please verify it is installed and on the run path");
return;
}
} else if (!perfVersion.isNewer(new PerfVersion(0, 0, 2))) {
oldPerfVersion = true;
// $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.");
}
}
BufferedReader input = null;
BufferedReader error = null;
Process p = null;
if (monitor != null && monitor.isCanceled()) {
return;
}
try {
if (workingDir == null) {
p = RuntimeProcessFactory.getFactory().exec(getReportString(config, perfDataLoc), project);
PerfPlugin.getDefault().setPerfProfileData(new Path(perfDataLoc));
PerfPlugin.getDefault().setWorkingDir(project.getLocation());
} else {
String defaultPerfDataLoc = workingDir.toOSString() + PerfPlugin.PERF_DEFAULT_DATA;
p = RuntimeProcessFactory.getFactory().exec(getReportString(config, defaultPerfDataLoc), project);
PerfPlugin.getDefault().setPerfProfileData(new Path(defaultPerfDataLoc));
PerfPlugin.getDefault().setWorkingDir(workingDir);
}
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// spitting error stream moved to end of while loop, due to commenting of p.waitFor()
} catch (IOException e) {
logException(e);
}
PerfCore.parseRemoteReport(config, workingDir, monitor, perfDataLoc, print, invisibleRoot, oldPerfVersion, input, error, project);
}
Aggregations