Search in sources :

Example 1 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class PerfSaveSessionHandler method saveData.

@Override
public IPath saveData(String filename) {
    // get paths
    IPath newDataLoc = getNewDataLocation(filename, DATA_EXT);
    IPath defaultDataLoc = PerfPlugin.getDefault().getPerfProfileData();
    URI newDataLocURI = null;
    URI defaultDataLocURI = null;
    // get files
    IRemoteFileProxy proxy = null;
    try {
        newDataLocURI = new URI(newDataLoc.toPortableString());
        defaultDataLocURI = new URI(defaultDataLoc.toPortableString());
        proxy = RemoteProxyManager.getInstance().getFileProxy(newDataLocURI);
    } catch (URISyntaxException e) {
        openErroDialog(Messages.MsgProxyError, Messages.MsgProxyError, newDataLoc.lastSegment());
    } catch (CoreException e) {
        openErroDialog(Messages.MsgProxyError, Messages.MsgProxyError, newDataLoc.lastSegment());
    }
    IFileStore newDataFileStore = proxy.getResource(newDataLocURI.getPath());
    IFileStore defaultDataFileStore = proxy.getResource(defaultDataLocURI.getPath());
    if (canSave(newDataLoc)) {
        // copy default data into new location
        try {
            defaultDataFileStore.copy(newDataFileStore, EFS.OVERWRITE, null);
            PerfPlugin.getDefault().setPerfProfileData(newDataLoc);
            try {
                PerfProfileView view = (PerfProfileView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PerfPlugin.VIEW_ID);
                view.setContentDescription(newDataLoc.toOSString());
            } catch (PartInitException e) {
            // fail silently
            }
            IFileInfo info = newDataFileStore.fetchInfo();
            info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
            newDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
            return newDataLoc;
        } catch (CoreException e) {
            openErroDialog(Messages.PerfSaveSession_failure_title, Messages.PerfSaveSession_failure_msg, newDataLoc.lastSegment());
        }
    }
    return null;
}
Also used : PerfProfileView(org.eclipse.linuxtools.internal.perf.ui.PerfProfileView) IFileInfo(org.eclipse.core.filesystem.IFileInfo) 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) PartInitException(org.eclipse.ui.PartInitException) URI(java.net.URI)

Example 2 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class PerfSaveStatsHandler method saveData.

@Override
public IPath saveData(String filename) {
    IPath newDataLoc = getNewDataLocation(filename, DATA_EXT);
    IPerfData statData = PerfPlugin.getDefault().getStatData();
    BufferedWriter writer = null;
    OutputStreamWriter osw = null;
    try {
        IRemoteFileProxy proxy = null;
        proxy = RemoteProxyManager.getInstance().getFileProxy(getWorkingDirURI());
        if (proxy == null) {
            openErroDialog(Messages.PerfSaveStat_error_title, Messages.PerfSaveStat_error_msg, newDataLoc.lastSegment());
            return null;
        }
        IFileStore newDataFileStore = proxy.getResource(newDataLoc.toOSString());
        osw = new OutputStreamWriter(newDataFileStore.openOutputStream(EFS.NONE, null));
        writer = new BufferedWriter(osw);
        writer.write(statData.getPerfData());
        closeResource(writer);
        IFileInfo info = newDataFileStore.fetchInfo();
        info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
        newDataFileStore.putInfo(info, EFS.SET_ATTRIBUTES, null);
        return newDataLoc;
    } catch (IOException | CoreException e) {
        openErroDialog(Messages.PerfSaveStat_error_title, Messages.PerfSaveStat_error_msg, newDataLoc.lastSegment());
    } finally {
        closeResource(writer);
    }
    return null;
}
Also used : IPerfData(org.eclipse.linuxtools.internal.perf.IPerfData) IFileInfo(org.eclipse.core.filesystem.IFileInfo) 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) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 3 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class LaunchOptions method isValid.

/**
 * Determines whether the global oprofile options represented by this
 * object are valid
 * @return whether the options are valid
 */
public boolean isValid() {
    IRemoteFileProxy proxy = null;
    try {
        proxy = RemoteProxyManager.getInstance().getFileProxy(getOprofileProject());
    } catch (CoreException e) {
        e.printStackTrace();
    }
    // The only point of contention is whether the specified vmlinux *file* exists.
    String fn = options.getKernelImageFile();
    if (fn != null && fn.length() > 0) {
        IFileStore fileStore = proxy.getResource(options.getKernelImageFile());
        return (fileStore.fetchInfo().exists() && !fileStore.fetchInfo().isDirectory());
    }
    return true;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 4 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class AbstractOprofileLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    this.config = config;
    Oprofile.OprofileProject.setProject(getProject());
    // default options created in the constructor
    LaunchOptions options = new LaunchOptions();
    options.loadConfiguration(config);
    IPath exePath = getExePath(config);
    options.setBinaryImage(exePath.toOSString());
    Oprofile.OprofileProject.setProfilingBinary(options.getOprofileComboText());
    /*
         * Parameters needed for the application under profiling
         */
    String[] appArgs = getProgramArgumentsArray(config);
    String[] appEnv = getEnvironment(config);
    // if daemonEvents null or zero size, the default event will be used
    OprofileDaemonEvent[] daemonEvents = null;
    ArrayList<OprofileDaemonEvent> events = new ArrayList<>();
    if (!config.getAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, false)) {
        // get the events to profile from the counters
        OprofileCounter[] counters = oprofileCounters(config);
        for (int i = 0; i < counters.length; ++i) {
            if (counters[i].getEnabled()) {
                OprofileDaemonEvent[] counterEvents = counters[i].getDaemonEvents();
                events.addAll(Arrays.asList(counterEvents));
            }
        }
        daemonEvents = new OprofileDaemonEvent[events.size()];
        events.toArray(daemonEvents);
    }
    if (!preExec(options, daemonEvents, launch)) {
        return;
    }
    Process process = null;
    // outputing the profiling data to the project dir/OPROFILE_DATA
    if (OprofileProject.getProfilingBinary().equals(OprofileProject.OPERF_BINARY)) {
        String eventsString = null;
        // Event spec: "EVENT:count:mask:profileKernel:profileUser"
        StringBuilder spec = new StringBuilder();
        spec.append(EVENTS);
        boolean isCommaAllowed = false;
        for (int i = 0; i < events.size(); i++) {
            OprofileDaemonEvent event = events.get(i);
            if (isCommaAllowed) {
                spec.append(',');
            }
            spec.append(event.getEvent().getText());
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append(event.getResetCount());
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append(event.getEvent().getUnitMask().getMaskValue());
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append((event.getProfileKernel() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append((event.getProfileUser() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
            isCommaAllowed = true;
        }
        eventsString = spec.toString();
        ArrayList<String> argArray = new ArrayList<>(Arrays.asList(appArgs));
        // Use remote file proxy to determine data folder since the project may be either local or remote
        IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(OprofileProject.getProject());
        IFileStore dataFolder = proxy.getResource(oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OPROFILE_DATA);
        if (!dataFolder.fetchInfo().exists()) {
            dataFolder.mkdir(EFS.SHALLOW, null);
        }
        argArray.add(0, exePath.toOSString());
        if (events.size() > 0) {
            argArray.add(0, eventsString);
        }
        argArray.add(0, SESSION_DIR + oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OPROFILE_DATA);
        argArray.add(0, OprofileProject.OPERF_BINARY);
        boolean appended = false;
        for (int i = 0; i < options.getExecutionsNumber(); i++) {
            /*
                 * If profiling multiple times,
                 * append oprofile results from 2nd execution on.
                 */
            if (!appended && i != 0) {
                argArray.add(1, APPEND);
                appended = true;
            }
            String[] arguments = new String[argArray.size()];
            arguments = argArray.toArray(arguments);
            try {
                process = RuntimeProcessFactory.getFactory().exec(arguments, appEnv, OprofileProject.getProject());
            } catch (IOException e1) {
                if (process != null)
                    process.destroy();
                // $NON-NLS-1$
                Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
                throw new CoreException(status);
            }
            DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()));
            try {
                process.waitFor();
            } catch (InterruptedException e) {
                if (process != null)
                    process.destroy();
                // $NON-NLS-1$
                Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
                throw new CoreException(status);
            }
        }
    }
    // outputing the profiling data to the project dir/OPROFILE_DATA
    if (OprofileProject.getProfilingBinary().equals(OprofileProject.OCOUNT_BINARY)) {
        String eventsString = null;
        // Event spec: "EVENT:count:mask:profileKernel:profileUser"
        StringBuilder spec = new StringBuilder();
        spec.append(EVENTS);
        boolean isCommaAllowed = false;
        for (int i = 0; i < events.size(); i++) {
            OprofileDaemonEvent event = events.get(i);
            if (isCommaAllowed) {
                spec.append(',');
            }
            spec.append(event.getEvent().getText());
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append(event.getResetCount());
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append(event.getEvent().getUnitMask().getMaskValue());
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append((event.getProfileKernel() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
            spec.append(OPD_SETUP_EVENT_SEPARATOR);
            spec.append((event.getProfileUser() ? OPD_SETUP_EVENT_TRUE : OPD_SETUP_EVENT_FALSE));
            isCommaAllowed = true;
        }
        eventsString = spec.toString();
        ArrayList<String> argArray = new ArrayList<>(Arrays.asList(appArgs));
        argArray.add(0, exePath.toOSString());
        if (events.size() > 0) {
            argArray.add(0, eventsString);
        }
        argArray.add(0, OUTPUT_FILE + oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OCOUNT_DATA);
        argArray.add(0, OprofileProject.OCOUNT_BINARY);
        String[] arguments = new String[argArray.size()];
        arguments = argArray.toArray(arguments);
        try {
            process = RuntimeProcessFactory.getFactory().exec(arguments, OprofileProject.getProject());
        } catch (IOException e1) {
            process.destroy();
            // $NON-NLS-1$
            Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
            throw new CoreException(status);
        }
        DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()));
        try {
            process.waitFor();
            // Put the OCount data in a separate view
            StringBuffer buffer = new StringBuffer();
            // Use remote file proxy to operate resources since the project may be either local or remote
            IRemoteFileProxy proxy = RemoteProxyManager.getInstance().getFileProxy(OprofileProject.getProject());
            IFileStore ocountDataStore = proxy.getResource(oprofileWorkingDirURI(config).getPath() + IPath.SEPARATOR + OCOUNT_DATA);
            try (InputStream is = ocountDataStore.openInputStream(EFS.NONE, monitor);
                BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
                String s = reader.readLine();
                // $NON-NLS-1$
                String sep_char = "";
                while (s != null) {
                    buffer.append(s);
                    buffer.append(sep_char);
                    // $NON-NLS-1$
                    sep_char = "\n";
                    s = reader.readLine();
                }
                // Open the OCount View and display output from ocount
                final String text = buffer.toString();
                Display.getDefault().syncExec(() -> refreshOcountView(text));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (InterruptedException e) {
            process.destroy();
            // $NON-NLS-1$
            Status status = new Status(IStatus.ERROR, OprofileLaunchPlugin.PLUGIN_ID, OprofileLaunchMessages.getString("oprofilelaunch.error.interrupted_error.status_message"));
            throw new CoreException(status);
        }
        return;
    }
    postExec(options, daemonEvents, process);
}
Also used : OprofileCounter(org.eclipse.linuxtools.internal.oprofile.launch.configuration.OprofileCounter) ArrayList(java.util.ArrayList) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) OprofileDaemonEvent(org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) LaunchOptions(org.eclipse.linuxtools.internal.oprofile.launch.configuration.LaunchOptions) CoreException(org.eclipse.core.runtime.CoreException) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 5 with IRemoteFileProxy

use of org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy in project linuxtools by eclipse.

the class EventIdCache method getUnitMaskType.

/**
 * Get the unit mask type. Schema Version 1.1 and newer of ophelp XML
 * will list the unit mask type as an attribute. Older version will not
 * so we default to file lookups.
 *
 * @param name the name of the event
 * @return the type of unit mask. This can be either mandatory, exclusive,
 * bitmask, or null if none could be found.
 */
public String getUnitMaskType(String name) {
    IProject project = Oprofile.OprofileProject.getProject();
    EventIdCache eventIdCache;
    if (project != null) {
        eventIdCache = cacheMap.get(project.getLocationURI().getHost());
    } else {
        eventIdCache = cacheMap.get(LOCAL);
    }
    if (eventIdCache.eventRoot == null) {
        readXML(eventIdCache);
        buildCache(eventIdCache);
    }
    Element header = (Element) eventIdCache.eventRoot.getElementsByTagName(HEADER).item(0);
    double schemaVersion = 0;
    if (!eventIdCache.eventRoot.getAttribute(SCHEMA).isEmpty()) {
        schemaVersion = Double.parseDouble(eventIdCache.eventRoot.getAttribute(SCHEMA));
    } else {
        schemaVersion = Double.parseDouble(header.getAttribute(SCHEMA));
    }
    String unitMaskType = null;
    IRemoteFileProxy proxy = null;
    try {
        proxy = RemoteProxyManager.getInstance().getFileProxy(Oprofile.OprofileProject.getProject());
    } catch (CoreException e) {
        e.printStackTrace();
    }
    // Schema Version > 1.0 has the unit mask type within the XML
    if (schemaVersion > 1.0) {
        Element event = getElementWithName(name);
        Element unitMaskTag = (Element) event.getElementsByTagName(InfoAdapter.UNIT_MASKS).item(0);
        return unitMaskTag.getAttribute(CATEGORY);
    } else {
        IFileStore fileStore = proxy.getResource(InfoAdapter.CPUTYPE);
        try (InputStream fileInputStream = fileStore.openInputStream(EFS.NONE, new NullProgressMonitor());
            BufferedReader bi = new BufferedReader(new InputStreamReader(fileInputStream))) {
            String cpuType = bi.readLine();
            // $NON-NLS-1$
            IFileStore opArchEvents = proxy.getResource(InfoAdapter.OP_SHARE + cpuType + "/" + InfoAdapter.EVENTS);
            // $NON-NLS-1$
            IFileStore opArchUnitMasks = proxy.getResource(InfoAdapter.OP_SHARE + cpuType + "/" + InfoAdapter.UNIT_MASKS);
            try (InputStream inputStreamEvents = opArchEvents.openInputStream(EFS.NONE, new NullProgressMonitor());
                BufferedReader eventReader = new BufferedReader(new InputStreamReader(inputStreamEvents))) {
                String line;
                while ((line = eventReader.readLine()) != null) {
                    // find the line with the event name
                    if (line.contains("name:" + name + ' ')) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        int start = line.indexOf("um:") + 3;
                        int end = line.indexOf(' ', start);
                        // grab the string that references the unit mask type
                        String um = line.substring(start, end);
                        try (InputStream inputStreamMasks = opArchUnitMasks.openInputStream(EFS.NONE, new NullProgressMonitor());
                            BufferedReader unitMaskReader = new BufferedReader(new InputStreamReader(inputStreamMasks))) {
                            while ((line = unitMaskReader.readLine()) != null) {
                                if (line.contains("name:" + um + ' ')) {
                                    // $NON-NLS-1$
                                    // $NON-NLS-1$
                                    start = line.indexOf("type:") + 5;
                                    end = line.indexOf(' ', start);
                                    unitMaskType = line.substring(start, end);
                                    return unitMaskType;
                                }
                            }
                        }
                    }
                }
            }
        } catch (IOException | CoreException e) {
        }
    }
    return unitMaskType;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore)

Aggregations

IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)25 CoreException (org.eclipse.core.runtime.CoreException)24 IFileStore (org.eclipse.core.filesystem.IFileStore)18 URI (java.net.URI)12 IOException (java.io.IOException)10 IPath (org.eclipse.core.runtime.IPath)10 BufferedReader (java.io.BufferedReader)9 InputStreamReader (java.io.InputStreamReader)9 URISyntaxException (java.net.URISyntaxException)7 ArrayList (java.util.ArrayList)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 IFileInfo (org.eclipse.core.filesystem.IFileInfo)6 InputStream (java.io.InputStream)3 IStatus (org.eclipse.core.runtime.IStatus)3 Path (org.eclipse.core.runtime.Path)3 Status (org.eclipse.core.runtime.Status)3 IRemoteCommandLauncher (org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher)3 RemoteConnectionException (org.eclipse.linuxtools.profiling.launch.RemoteConnectionException)3 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)3 Test (org.junit.Test)3