Search in sources :

Example 91 with IFileStore

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;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 92 with IFileStore

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;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PMStatEntry(org.eclipse.linuxtools.internal.perf.model.PMStatEntry) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 93 with IFileStore

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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) PerfSaveStatsHandler(org.eclipse.linuxtools.internal.perf.handlers.PerfSaveStatsHandler) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 94 with IFileStore

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 95 with IFileStore

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) URISyntaxException(java.net.URISyntaxException) PerfPlugin(org.eclipse.linuxtools.internal.perf.PerfPlugin) URI(java.net.URI)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)105 CoreException (org.eclipse.core.runtime.CoreException)49 IPath (org.eclipse.core.runtime.IPath)29 IOException (java.io.IOException)26 IFileInfo (org.eclipse.core.filesystem.IFileInfo)25 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 URI (java.net.URI)16 InputStream (java.io.InputStream)14 Path (org.eclipse.core.runtime.Path)14 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 InputStreamReader (java.io.InputStreamReader)11 PartInitException (org.eclipse.ui.PartInitException)11 BufferedReader (java.io.BufferedReader)10 URISyntaxException (java.net.URISyntaxException)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 Test (org.junit.Test)10 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)9 IStatus (org.eclipse.core.runtime.IStatus)9