use of org.eclipse.linuxtools.profiling.launch.RemoteProxyManager in project linuxtools by eclipse.
the class OpxmlRunner method runOpReport.
/**
* Run opreport with specified arguments <code>args</code> and return
* InputStream to output of report for parsing.
*
* @param args
* arguments to run with opreport
* @return InputStream to output of report
*/
private InputStream runOpReport(String[] args) {
ArrayList<String> cmd = new ArrayList<>();
// $NON-NLS-1$
cmd.add("opreport");
if (OprofileProject.getProfilingBinary().equals(OprofileProject.OPERF_BINARY)) {
/*
* The session-dir parameter is relative to project's working dir,
* which might be local or remote. So it should use the proxy
* manager to determine working dir.
*/
// $NON-NLS-1$
String workingDir = "";
RemoteProxyManager proxy = RemoteProxyManager.getInstance();
try {
IRemoteFileProxy rfile = proxy.getFileProxy(Oprofile.OprofileProject.getProject());
workingDir = rfile.getWorkingDir().getPath();
} catch (CoreException e) {
e.printStackTrace();
return null;
}
// $NON-NLS-1$ //$NON-NLS-2$
cmd.add(1, "--session-dir=" + workingDir + IPath.SEPARATOR + "oprofile_data");
}
Collections.addAll(cmd, args);
Process p = null;
try {
p = RuntimeProcessFactory.getFactory().exec(cmd.toArray(new String[0]), Oprofile.OprofileProject.getProject());
StringBuilder output = new StringBuilder();
StringBuilder errorOutput = new StringBuilder();
String s = null;
try (BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
// stream buffer fills up.
while ((s = stdInput.readLine()) != null) {
// $NON-NLS-1$
output.append(s + System.getProperty("line.separator"));
}
while ((s = stdError.readLine()) != null) {
// $NON-NLS-1$
errorOutput.append(s + System.getProperty("line.separator"));
}
if (!errorOutput.toString().trim().equals("")) {
// $NON-NLS-1$
OprofileCorePlugin.log(IStatus.ERROR, // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
OprofileProperties.getString("process.log.stderr"), "opreport", // $NON-NLS-1$
errorOutput.toString().trim()));
}
} catch (IOException e) {
e.printStackTrace();
}
if (p.waitFor() == 0) {
// convert the string to inputstream to pass to builder.parse
return new ByteArrayInputStream(output.toString().getBytes(StandardCharsets.UTF_8));
}
} catch (IOException e1) {
e1.printStackTrace();
// $NON-NLS-1$
OprofileCorePlugin.showErrorDialog("opxmlParse", null);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
Aggregations