use of org.eclipse.core.filesystem.IFileStore 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.core.filesystem.IFileStore in project linuxtools by eclipse.
the class STLink2SourceSupport method findFileInCommonSourceLookup.
private static IEditorInput findFileInCommonSourceLookup(IPath path) {
try {
AbstractSourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector();
ISourceContainer[] c = director.getSourceContainers();
for (ISourceContainer sourceContainer : c) {
Object[] o = sourceContainer.findSourceElements(path.toOSString());
for (Object object : o) {
if (object instanceof IFile) {
return new FileEditorInput((IFile) object);
} else if (object instanceof LocalFileStorage) {
LocalFileStorage storage = (LocalFileStorage) object;
IFileStore ifs = EFS.getStore(storage.getFile().toURI());
return new FileStoreEditorInput(ifs);
}
}
}
} catch (CoreException e) {
// do nothing
}
return null;
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class InfoAdapter method checkTimerSupport.
/**
* Set whether the cpu supports timer mode
*/
public static void checkTimerSupport() {
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(Oprofile.OprofileProject.getProject());
IFileStore fileStore = proxy.getResource(CPUTYPE);
if (fileStore.fetchInfo().exists()) {
try (InputStream is = fileStore.openInputStream(EFS.NONE, new NullProgressMonitor());
BufferedReader bi = new BufferedReader(new InputStreamReader(is))) {
String cpuType = bi.readLine();
if (cpuType.equals(TIMER)) {
hasTimerSupport = true;
} else {
hasTimerSupport = false;
}
}
}
} catch (FileNotFoundException e) {
hasTimerSupport = true;
} catch (IOException e) {
hasTimerSupport = true;
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class InfoAdapter method getCPUFrequency.
/**
* Get the system's cpu frequency
*
* @return the system's cpu frequency
*/
private int getCPUFrequency() {
int val = 0;
try {
proxy = RemoteProxyManager.getInstance().getFileProxy(Oprofile.OprofileProject.getProject());
IFileStore fileStore = proxy.getResource(CPUINFO);
if (fileStore.fetchInfo().exists()) {
InputStream is = fileStore.openInputStream(EFS.NONE, new NullProgressMonitor());
try (BufferedReader bi = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = bi.readLine()) != null) {
int index = line.indexOf(':');
if (index != -1) {
String substr;
// x86/ia64/x86_64
if (line.startsWith("cpu MHz")) {
// $NON-NLS-1$
substr = line.substring(index + 1).trim();
return (int) Double.parseDouble(substr);
// ppc/pc64
} else if (line.startsWith("clock")) {
// $NON-NLS-1$
// $NON-NLS-1$
int MHzLoc = line.indexOf("MHz");
substr = line.substring(index + 1, MHzLoc);
return (int) Double.parseDouble(substr);
// alpha
} else if (line.startsWith("cycle frequency [Hz]")) {
// $NON-NLS-1$
substr = line.substring(index + 1).trim();
return (int) (Double.parseDouble(substr) / 1E6);
// sparc64
} else if (line.startsWith("Cpu0ClkTck")) {
// $NON-NLS-1$
substr = line.substring(index + 1).trim();
return (int) (Double.parseDouble(substr) / 1E6);
}
}
}
} catch (IOException | NumberFormatException e) {
e.printStackTrace();
}
}
} catch (CoreException e) {
e.printStackTrace();
}
return val;
}
use of org.eclipse.core.filesystem.IFileStore 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();
}
}
Aggregations