Search in sources :

Example 1 with OprofileDaemonEvent

use of org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent 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 2 with OprofileDaemonEvent

use of org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent in project linuxtools by eclipse.

the class OprofileCounter method setEvents.

/**
 * Method setEvent.
 * @param event    the event for this counter
 */
public void setEvents(OpEvent[] events) {
    OprofileDaemonEvent[] newDaemonEvent = new OprofileDaemonEvent[events.length];
    for (int i = 0; i < events.length; i++) {
        if (i > daemonEvent.length - 1) {
            OprofileDaemonEvent de = new OprofileDaemonEvent();
            de.setEvent(events[i]);
            de.setResetCount(daemonEvent[0].getResetCount());
            newDaemonEvent[i] = de;
        } else {
            daemonEvent[i].setEvent(events[i]);
            newDaemonEvent[i] = daemonEvent[i];
        }
    }
    daemonEvent = newDaemonEvent;
}
Also used : OprofileDaemonEvent(org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent)

Example 3 with OprofileDaemonEvent

use of org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent in project linuxtools by eclipse.

the class OprofileCounter method loadConfiguration.

/**
 * Loads a counter configuration from the specified launch configuration.
 * @param config    the launch configuration
 */
public void loadConfiguration(ILaunchConfiguration config) {
    try {
        _enabled = config.getAttribute(OprofileLaunchPlugin.attrConterEnabled(number), false);
        int numEvents = config.getAttribute(OprofileLaunchPlugin.attrNumberOfEvents(number), 1);
        daemonEvent = new OprofileDaemonEvent[numEvents];
        for (int i = 0; i < numEvents; i++) {
            // $NON-NLS-1$
            String str = config.getAttribute(OprofileLaunchPlugin.attrConterEvent(number, i), "");
            int maskValue = config.getAttribute(OprofileLaunchPlugin.attrCounterUnitMask(number), OpUnitMask.SET_DEFAULT_MASK);
            daemonEvent[i] = new OprofileDaemonEvent();
            daemonEvent[i].setEvent(eventFromString(str));
            if (daemonEvent[i].getEvent() == null) {
                continue;
            }
            daemonEvent[i].getEvent().getUnitMask().setMaskValue(maskValue);
            daemonEvent[i].setProfileKernel(config.getAttribute(OprofileLaunchPlugin.attrCounterProfileKernel(number), false));
            daemonEvent[i].setProfileUser(config.getAttribute(OprofileLaunchPlugin.attrCounterProfileUser(number), false));
            daemonEvent[i].setResetCount(config.getAttribute(OprofileLaunchPlugin.attrCounterCount(number), OprofileDaemonEvent.COUNT_UNINITIALIZED));
        }
    } catch (CoreException ce) {
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OprofileDaemonEvent(org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent)

Aggregations

OprofileDaemonEvent (org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonEvent)3 CoreException (org.eclipse.core.runtime.CoreException)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 LaunchOptions (org.eclipse.linuxtools.internal.oprofile.launch.configuration.LaunchOptions)1 OprofileCounter (org.eclipse.linuxtools.internal.oprofile.launch.configuration.OprofileCounter)1 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)1