use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class RuntimeProcessFactory method whichCommand.
/**
* Used to get the full command path. It will look for the command in the
* system path and in the path selected in 'Linux Tools Path' preference page
* in the informed project.
*
* @param command The desired command
* @param project The current project. If null, only system path will be
* used to look for the command.
* @return The full command path if command was found or the command if
* command was not found.
* @throws IOException If problem executing the command occured.
*
* @since 1.1
*/
public String whichCommand(String command, IProject project) throws IOException {
String[] envp = updateEnvironment(null, project);
try {
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project);
URI whichUri;
// For Windows, we use the where command, otherwise, we use the Unix which command
if ((project != null && Platform.OS_WIN32.equals(RemoteProxyManager.getInstance().getOS(project))) || Platform.OS_WIN32.equals(Platform.getOS())) {
whichUri = URI.create(WHERE_CMD);
} else {
whichUri = URI.create(WHICH_CMD);
}
IPath whichPath = new Path(proxy.toPath(whichUri));
IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(project);
Process pProxy = launcher.execute(whichPath, new String[] { command }, envp, null, new NullProgressMonitor());
if (pProxy != null) {
ArrayList<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream()))) {
String readLine = reader.readLine();
while (readLine != null) {
lines.add(readLine);
readLine = reader.readLine();
}
}
if (!lines.isEmpty()) {
if (project != null && project.getLocationURI() != null) {
if (project.getLocationURI().toString().startsWith("rse:")) {
// RSE output
if (lines.size() > 1) {
command = lines.get(lines.size() - 2);
}
} else {
// Remotetools or o.e.Remote output
command = lines.get(0);
}
} else {
// Local output
command = lines.get(0);
}
}
}
} catch (CoreException e) {
throw new IOException(e);
}
// Command is not found
return command;
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy 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;
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class OprofiledLogDialog method run.
@Override
public void run() {
try {
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(Oprofile.OprofileProject.getProject());
IFileStore fileStore = proxy.getResource(Oprofile.getLogFile());
if (fileStore.fetchInfo().exists()) {
long modified = fileStore.fetchInfo().getLastModified();
// only reread it if it has been modified since the last run
if (modified != lastModified) {
lastModified = modified;
// $NON-NLS-1$
contents = "";
}
try (InputStream is = fileStore.openInputStream(EFS.NONE, new NullProgressMonitor());
BufferedReader bi = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = bi.readLine()) != null) {
// $NON-NLS-1$
contents += line + "\n";
}
bi.close();
}
}
} catch (FileNotFoundException e) {
// The file doesn't exist or was erased. Try again next time.
contents = OprofileUiMessages.getString(// $NON-NLS-1$
"oprofiled.logreader.error.fileNotFound");
} catch (IOException e) {
// Error reading log. Try again next time.
lastModified = 0;
contents = OprofileUiMessages.getString(// $NON-NLS-1$
"oprofiled.logreader.error.io");
} catch (CoreException e) {
e.printStackTrace();
}
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class ValgrindRemoteProxyLaunchDelegate method launch.
@Override
public void launch(final ILaunchConfiguration config, String mode, final ILaunch launch, IProgressMonitor m) throws CoreException {
if (m == null) {
m = new NullProgressMonitor();
}
// Clear process as we wait on it to be instantiated
process = null;
SubMonitor monitor = SubMonitor.convert(m, Messages.getString("ValgrindRemoteLaunchDelegate.task_name"), // $NON-NLS-1$
10);
// check for cancellation
if (monitor.isCanceled()) {
return;
}
this.config = config;
this.launch = launch;
try {
// remove any output from previous run
ValgrindUIPlugin.getDefault().resetView();
// reset stored launch data
getPlugin().setCurrentLaunchConfiguration(null);
getPlugin().setCurrentLaunch(null);
this.configUtils = new ConfigUtils(config);
IProject project = configUtils.getProject();
ValgrindUIPlugin.getDefault().setProfiledProject(project);
URI exeURI = new URI(configUtils.getExecutablePath());
RemoteConnection exeRC = new RemoteConnection(exeURI);
monitor.worked(1);
String valgrindPathString = RuntimeProcessFactory.getFactory().whichCommand(VALGRIND_CMD, project);
IPath valgrindFullPath = Path.fromOSString(valgrindPathString);
boolean copyExecutable = configUtils.getCopyExecutable();
if (copyExecutable) {
URI copyExeURI = new URI(configUtils.getCopyFromExecutablePath());
RemoteConnection copyExeRC = new RemoteConnection(copyExeURI);
IRemoteFileProxy copyExeRFP = copyExeRC.getRmtFileProxy();
IFileStore copyExeFS = copyExeRFP.getResource(copyExeURI.getPath());
IRemoteFileProxy exeRFP = exeRC.getRmtFileProxy();
IFileStore exeFS = exeRFP.getResource(exeURI.getPath());
IFileInfo exeFI = exeFS.fetchInfo();
if (exeFI.isDirectory()) {
// Assume the user wants to copy the file to the given directory, using
// the same filename as the "copy from" executable.
IPath copyExePath = Path.fromOSString(copyExeURI.getPath());
IPath newExePath = Path.fromOSString(exeURI.getPath()).append(copyExePath.lastSegment());
// update the exeURI with the new path.
exeURI = new URI(exeURI.getScheme(), exeURI.getAuthority(), newExePath.toString(), exeURI.getQuery(), exeURI.getFragment());
exeFS = exeRFP.getResource(exeURI.getPath());
}
copyExeFS.copy(exeFS, EFS.OVERWRITE | EFS.SHALLOW, SubMonitor.convert(monitor, 1));
// Note: assume that we don't need to create a new exeRC since the
// scheme and authority remain the same between the original exeURI and the new one.
}
valgrindVersion = getValgrindVersion(project);
IPath remoteBinFile = Path.fromOSString(exeURI.getPath());
String configWorkingDir = configUtils.getWorkingDirectory();
IFileStore workingDir;
if (configWorkingDir == null) {
// If no working directory was provided, use the directory containing the
// the executable as the working directory.
IPath workingDirPath = remoteBinFile.removeLastSegments(1);
IRemoteFileProxy workingDirRFP = exeRC.getRmtFileProxy();
workingDir = workingDirRFP.getResource(workingDirPath.toOSString());
} else {
URI workingDirURI = new URI(configUtils.getWorkingDirectory());
RemoteConnection workingDirRC = new RemoteConnection(workingDirURI);
IRemoteFileProxy workingDirRFP = workingDirRC.getRmtFileProxy();
workingDir = workingDirRFP.getResource(workingDirURI.getPath());
}
// $NON-NLS-1$
IPath remoteLogDir = Path.fromOSString("/tmp/");
// $NON-NLS-1$
outputPath = remoteLogDir.append("eclipse-valgrind-" + System.currentTimeMillis());
exeRC.createFolder(outputPath, SubMonitor.convert(monitor, 1));
// create/empty local output directory
IValgrindOutputDirectoryProvider provider = getPlugin().getOutputDirectoryProvider();
setOutputPath(config, provider.getOutputPath());
IPath localOutputDir = null;
try {
localOutputDir = provider.getOutputPath();
createDirectory(localOutputDir);
} catch (IOException e2) {
throw new CoreException(new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, IStatus.OK, "", // $NON-NLS-1$
e2));
}
// tool that was launched
toolID = getTool(config);
// ask tool extension for arguments
dynamicDelegate = getDynamicDelegate(toolID);
String[] valgrindArgs = getValgrindArgumentsArray(config);
String[] executableArgs = getProgramArgumentsArray(config);
String[] allArgs = new String[executableArgs.length + valgrindArgs.length + 2];
int idx = 0;
allArgs[idx++] = VALGRIND_CMD;
for (String valgrindArg : valgrindArgs) {
allArgs[idx++] = valgrindArg;
}
allArgs[idx++] = remoteBinFile.toOSString();
for (String executableArg : executableArgs) {
allArgs[idx++] = executableArg;
}
Process p = RuntimeProcessFactory.getFactory().exec(allArgs, new String[0], workingDir, project);
int state = p.waitFor();
if (state != IRemoteCommandLauncher.OK) {
abort(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("ValgrindLaunchConfigurationDelegate.Launch_exited_status") + " " + state + ". " + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
NLS.bind(Messages.getString("ValgrindRemoteProxyLaunchDelegate.see_reference"), "IRemoteCommandLauncher") + // $NON-NLS-1$
"\n", null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
if (p.exitValue() != 0) {
String line = null;
StringBuilder valgrindOutSB = new StringBuilder();
BufferedReader valgrindOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = valgrindOut.readLine()) != null) {
valgrindOutSB.append(line);
}
StringBuilder valgrindErrSB = new StringBuilder();
BufferedReader valgrindErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((line = valgrindErr.readLine()) != null) {
valgrindErrSB.append(line);
}
abort(// $NON-NLS-1$
NLS.bind("ValgrindRemoteProxyLaunchDelegate.Stdout", valgrindOutSB.toString()) + "\n" + // $NON-NLS-1$ //$NON-NLS-2$
NLS.bind("ValgrindRemoteProxyLaunchDelegate.Stderr", valgrindErrSB.toString()), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
// move remote log files to local directory
exeRC.download(outputPath, localOutputDir, SubMonitor.convert(monitor, 1));
// remove remote log dir and all files under it
exeRC.delete(outputPath, SubMonitor.convert(monitor, 1));
// store these for use by other classes
getPlugin().setCurrentLaunchConfiguration(config);
getPlugin().setCurrentLaunch(launch);
// parse Valgrind logs
IValgrindMessage[] messages = parseLogs(localOutputDir);
// create launch summary string to distinguish this launch
launchStr = createLaunchStr(valgrindFullPath);
// create view
ValgrindUIPlugin.getDefault().createView(launchStr, toolID);
// set log messages
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
view.setMessages(messages);
monitor.worked(1);
// pass off control to extender
dynamicDelegate.handleLaunch(config, launch, localOutputDir, monitor.newChild(2));
// initialize tool-specific part of view
dynamicDelegate.initializeView(view.getDynamicView(), launchStr, monitor.newChild(1));
// refresh view
ValgrindUIPlugin.getDefault().refreshView();
// show view
ValgrindUIPlugin.getDefault().showView();
monitor.worked(1);
} catch (URISyntaxException | IOException | RemoteConnectionException | InterruptedException e) {
abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
} finally {
monitor.done();
m.done();
}
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class MassifPlugin method openEditorForNode.
public void openEditorForNode(MassifHeapTreeNode element) {
IRemoteFileProxy proxy = null;
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(ValgrindUIPlugin.getDefault().getProfiledProject());
} catch (CoreException e1) {
e1.printStackTrace();
return;
}
IFileStore fs = proxy.getResource(element.getFilename());
// New versions of massif (e.g. 3.10) prints the full path
if (fs.fetchInfo().exists()) {
try {
ProfileUIUtils.openEditorAndSelect(element.getFilename(), element.getLine(), ValgrindUIPlugin.getDefault().getProfiledProject());
} catch (BadLocationException | CoreException e) {
// do nothing, the editor will not open.
e.printStackTrace();
}
} else {
// do source lookup
if (locator instanceof ISourceLookupDirector) {
Object obj = ((ISourceLookupDirector) locator).getSourceElement(element.getFilename());
try {
if (obj instanceof IFile) {
ProfileUIUtils.openEditorAndSelect(((IFile) obj), element.getLine());
}
} catch (PartInitException | BadLocationException e) {
e.printStackTrace();
}
}
}
}
Aggregations