use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class StatData method updateStatData.
/**
* Save latest perf stat result under $workingDirectory/perf.stat. If file
* already exists rename it to perf.old.stat, in order to keep a reference
* to the previous session and be consistent with the way perf handles perf
* report data files.
*/
public void updateStatData() {
// build file name format
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(PerfPlugin.PERF_COMMAND);
// $NON-NLS-1$
stringBuilder.append("%s.");
stringBuilder.append(PerfSaveStatsHandler.DATA_EXT);
String statNameFormat = stringBuilder.toString();
// get current stat file
IPath workingDir = getWorkDir();
// $NON-NLS-1$
String curStatName = String.format(statNameFormat, "");
IPath curStatPath = workingDir.append(curStatName);
IRemoteFileProxy proxy = null;
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(project);
IFileStore curFileStore = proxy.getResource(curStatPath.toOSString());
if (curFileStore.fetchInfo().exists()) {
// get previous stat file
// $NON-NLS-1$
String oldStatName = String.format(statNameFormat, ".old");
IPath oldStatPath = workingDir.append(oldStatName);
IFileStore oldFileStore = proxy.getResource(oldStatPath.toOSString());
if (oldFileStore.fetchInfo().exists()) {
oldFileStore.delete(EFS.NONE, null);
}
curFileStore.copy(oldFileStore, EFS.NONE, null);
curFileStore.delete(EFS.NONE, null);
}
PerfSaveStatsHandler saveStats = new PerfSaveStatsHandler();
saveStats.saveData(PerfPlugin.PERF_COMMAND);
} catch (CoreException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError);
}
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class AbstractSaveDataHandler method canSave.
/**
* Verify that we can save the specified file.
*
* @param file <code>File</code> to save
* @return true if we can go ahead and save the file, false otherwise
*/
public boolean canSave(IPath file) {
IRemoteFileProxy proxy = null;
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(getWorkingDirURI());
} catch (CoreException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError);
}
IFileStore fileStore = proxy.getResource(file.toPortableString());
if (fileStore.fetchInfo().exists()) {
String msg = MessageFormat.format(Messages.PerfSaveSession_file_exists_msg, fileStore.getName());
return MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.PerfSaveSession_file_exists_title, msg);
}
return true;
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class PerfStatsQuickDiffHandler method isEnabled.
@Override
public boolean isEnabled() {
PerfPlugin plugin = PerfPlugin.getDefault();
IPath workingDir = plugin.getWorkingDir();
URI curStatDataURI = null;
URI prevStatDataURI = null;
if (workingDir != null) {
IPath curStatData = plugin.getPerfFile(PerfPlugin.PERF_DEFAULT_STAT);
IPath prevStatData = plugin.getPerfFile(PerfPlugin.PERF_DEAFULT_OLD_STAT);
IRemoteFileProxy proxy = null;
try {
curStatDataURI = new URI(curStatData.toPortableString());
prevStatDataURI = new URI(prevStatData.toPortableString());
proxy = RemoteProxyManager.getInstance().getFileProxy(curStatDataURI);
} catch (URISyntaxException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError);
} catch (CoreException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError);
}
IFileStore curFileStore = proxy.getResource(curStatDataURI.getPath());
IFileStore prevFileStore = proxy.getResource(prevStatDataURI.getPath());
return (curFileStore.fetchInfo().exists() && prevFileStore.fetchInfo().exists());
}
return false;
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class PerfLaunchConfigDelegate method launch.
@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
try {
ConfigUtils configUtils = new ConfigUtils(config);
project = configUtils.getProject();
// Set the current project that will be profiled
PerfPlugin.getDefault().setProfiledProject(project);
// check if Perf exists in $PATH
if (!PerfCore.checkPerfInPath(project)) {
// $NON-NLS-1$
IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, "Error: Perf was not found on PATH");
throw new CoreException(status);
}
URI workingDirURI = new URI(config.getAttribute(RemoteProxyCMainTab.ATTR_REMOTE_WORKING_DIRECTORY_NAME, EMPTY_STRING));
// Local project
if (workingDirURI.toString().equals(EMPTY_STRING)) {
workingDirURI = getWorkingDirectory(config).toURI();
workingDirPath = Path.fromPortableString(workingDirURI.getPath());
binPath = CDebugUtils.verifyProgramPath(config);
} else {
workingDirPath = Path.fromPortableString(workingDirURI.getPath() + IPath.SEPARATOR);
URI binURI = new URI(configUtils.getExecutablePath());
binPath = Path.fromPortableString(binURI.getPath().toString());
}
PerfPlugin.getDefault().setWorkingDir(workingDirPath);
if (config.getAttribute(PerfPlugin.ATTR_ShowStat, PerfPlugin.ATTR_ShowStat_default)) {
showStat(config, launch);
} else {
String perfPathString = RuntimeProcessFactory.getFactory().whichCommand(PerfPlugin.PERF_COMMAND, project);
IFileStore workingDir;
RemoteConnection workingDirRC = new RemoteConnection(workingDirURI);
IRemoteFileProxy workingDirRFP = workingDirRC.getRmtFileProxy();
workingDir = workingDirRFP.getResource(workingDirURI.getPath());
// Build the commandline string to run perf recording the given project
// Program args from launch config.
String[] arguments = getProgramArgumentsArray(config);
ArrayList<String> command = new ArrayList<>(4 + arguments.length);
// Get the base commandline string (with flags/options based on config)
command.addAll(Arrays.asList(PerfCore.getRecordString(config)));
// Add the path to the executable
command.add(binPath.toPortableString());
command.set(0, perfPathString);
command.add(2, OUTPUT_STR + PerfPlugin.PERF_DEFAULT_DATA);
// Compile string
command.addAll(Arrays.asList(arguments));
// Spawn the process
String[] commandArray = command.toArray(new String[command.size()]);
Process pProxy = RuntimeProcessFactory.getFactory().exec(commandArray, getEnvironment(config), workingDir, project);
// $NON-NLS-1$
MessageConsole console = new MessageConsole("Perf Console", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
MessageConsoleStream stream = console.newMessageStream();
if (pProxy != null) {
try (BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream()))) {
String err = error.readLine();
while (err != null) {
stream.println(err);
err = error.readLine();
}
}
}
/* This commented part is the basic method to run perf record without integrating into eclipse.
String binCall = exePath.toOSString();
for(String arg : arguments) {
binCall.concat(" " + arg);
}
PerfCore.Run(binCall);*/
pProxy.destroy();
PrintStream print = null;
if (config.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true)) {
// Get the console to output to.
// This may not be the best way to accomplish this but it shall do for now.
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
IOConsole binaryOutCons = null;
// Find the console
for (IConsole x : existing) {
if (x.getName().contains(renderProcessLabel(commandArray[0]))) {
binaryOutCons = (IOConsole) x;
}
}
if ((binaryOutCons == null) && (existing.length != 0)) {
// if can't be found get the most recent opened, this should probably never happen.
if (existing[existing.length - 1] instanceof IOConsole)
binaryOutCons = (IOConsole) existing[existing.length - 1];
}
// Get the printstream via the outputstream.
// Get ouput stream
OutputStream outputTo;
if (binaryOutCons != null) {
outputTo = binaryOutCons.newOutputStream();
// Get the printstream for that console
print = new PrintStream(outputTo);
}
for (int i = 0; i < command.size(); i++) {
// $NON-NLS-1$
print.print(command.get(i) + " ");
}
// Print Message
print.println();
// $NON-NLS-1$
print.println("Analysing recorded perf.data, please wait...");
// Possibly should pass this (the console reference) on to PerfCore.Report if theres anything we ever want to spit out to user.
}
PerfCore.report(config, workingDirPath, monitor, null, print);
URI perfDataURI = null;
IRemoteFileProxy proxy = null;
perfDataURI = new URI(workingDirURI.toString() + IPath.SEPARATOR + PerfPlugin.PERF_DEFAULT_DATA);
proxy = RemoteProxyManager.getInstance().getFileProxy(perfDataURI);
IFileStore perfDataFileStore = proxy.getResource(perfDataURI.getPath());
IFileInfo info = perfDataFileStore.fetchInfo();
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
perfDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
PerfCore.refreshView(renderProcessLabel(binPath.toPortableString()));
if (config.getAttribute(PerfPlugin.ATTR_ShowSourceDisassembly, PerfPlugin.ATTR_ShowSourceDisassembly_default)) {
showSourceDisassembly(Path.fromPortableString(workingDirURI.toString() + IPath.SEPARATOR));
}
}
} catch (IOException e) {
e.printStackTrace();
abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
} catch (RemoteConnectionException e) {
e.printStackTrace();
abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
} catch (URISyntaxException e) {
e.printStackTrace();
abort(e.getLocalizedMessage(), null, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
}
}
use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.
the class RuntimeProcessFactory method sudoExec.
/**
* Execute one command, as root, using the path selected in 'Linux Tools Path'
* preference page in the informed project.
* @param cmdarray An array with the command to be executed and its params.
* @param envp An array with extra enviroment variables to be used when running
* the command
* @param dir The directory used as current directory to run the command.
* @param project The current project. If null, only system path will be
* used to look for the command.
* @return The process started by sudoExec
*
* @since 1.1
*/
private Process sudoExec(String[] cmdarray, String[] envp, IFileStore dir, IProject project) throws IOException {
// $NON-NLS-1$
URI uri = URI.create("sudo");
List<String> cmdList = Arrays.asList(cmdarray);
ArrayList<String> cmdArrayList = new ArrayList<>(cmdList);
// $NON-NLS-1$
cmdArrayList.add(0, "-n");
String[] cmdArraySudo = new String[cmdArrayList.size()];
cmdArrayList.toArray(cmdArraySudo);
Process p = null;
try {
cmdArraySudo = fillPathSudoCommand(cmdArraySudo, project);
IRemoteCommandLauncher launcher;
IPath changeToDir = null, path;
if (project != null) {
IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(project);
path = new Path(proxy.toPath(uri));
launcher = RemoteProxyManager.getInstance().getLauncher(project);
envp = updateEnvironment(envp, project);
if (dir != null) {
changeToDir = new Path(proxy.toPath(dir.toURI()));
}
} else {
launcher = RemoteProxyManager.getInstance().getLauncher(uri);
path = new Path(uri.getPath());
if (dir != null) {
changeToDir = new Path(dir.toURI().getPath());
}
}
List<String> cmdlist = new ArrayList<>(Arrays.asList(cmdArraySudo));
cmdlist.remove(0);
cmdlist.toArray(cmdArraySudo);
cmdArraySudo = cmdlist.toArray(new String[0]);
p = launcher.execute(path, cmdArraySudo, envp, changeToDir, new NullProgressMonitor());
} catch (CoreException e) {
e.printStackTrace();
}
return p;
}
Aggregations