use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class PerfPlugin method getWorkingDirURI.
/**
* Get the working directory.
* @return the URI of the working directory or null.
*/
public URI getWorkingDirURI() {
try {
IRemoteFileProxy fileProxy = RemoteProxyManager.getInstance().getFileProxy(getProfiledProject());
IPath wd = getWorkingDir();
if (wd == null || fileProxy == null) {
return null;
}
IFileStore fs = fileProxy.getResource(wd.toOSString());
return fs.toURI();
} catch (CoreException e) {
return null;
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class StatComparisonData method collectStats.
/**
* Collect statistics entries from the specified stat data file.
*
* @param file file to collect from
* @return List containing statistics entries from the given file.
*/
private static ArrayList<PMStatEntry> collectStats(IPath file) {
ArrayList<PMStatEntry> result = new ArrayList<>();
BufferedReader statReader = null;
URI fileURI = null;
try {
fileURI = new URI(file.toPortableString());
IRemoteFileProxy proxy = null;
proxy = RemoteProxyManager.getInstance().getFileProxy(fileURI);
IFileStore newDataFileStore = proxy.getResource(fileURI.getPath());
statReader = new BufferedReader(new InputStreamReader(newDataFileStore.openInputStream(EFS.NONE, null)));
// pattern for a valid perf stat entry
Pattern entryPattern = Pattern.compile(PMStatEntry.getString(Type.ENTRY_PATTERN));
// pattern for last stat entry (seconds elapsed):
Pattern totalTimePattern = Pattern.compile(PMStatEntry.getString(Type.TIME_PATTERN));
String line;
while ((line = statReader.readLine()) != null) {
line = line.trim();
Matcher match = entryPattern.matcher(line);
String samples, event, usage, units, delta, scale;
PMStatEntry statEntry;
if (match.find()) {
// extract information from groups
samples = match.group(1);
event = match.group(2);
usage = match.group(7);
units = match.group(8);
delta = match.group(10);
scale = match.group(14);
// create stat entry
statEntry = new PMStatEntry(toFloat(samples), event, toFloat(usage), units, toFloat(delta), toFloat(scale));
// add stat entry to results list
result.add(statEntry);
} else if (line.contains(PMStatEntry.TIME)) {
// match seconds elapsed pattern
match = totalTimePattern.matcher(line);
if (match.find()) {
samples = match.group(1);
event = match.group(2);
delta = match.group(4);
// create stat entry
statEntry = new PMStatEntry(toFloat(samples), event, 0, null, toFloat(delta), 0);
result.add(statEntry);
}
}
}
return result;
} catch (IOException | CoreException | URISyntaxException e) {
PerfPlugin.getDefault().openError(e, Messages.MsgError);
} finally {
try {
if (statReader != null) {
statReader.close();
}
} catch (IOException e) {
PerfPlugin.getDefault().openError(e, Messages.PerfResourceLeak_title);
}
}
return result;
}
use of org.eclipse.core.filesystem.IFileStore 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.core.filesystem.IFileStore 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.core.filesystem.IFileStore 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;
}
Aggregations