Search in sources :

Example 1 with ProfileLaunchConfigurationTabGroup

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

the class ProviderFramework method getTabGroupProvider.

/**
 * Get a profiling tab that provides the specified type of profiling. This
 * looks through extensions of the extension point
 * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code> that have a
 * specific type attribute.
 *
 * @param type A profiling type (eg. memory, snapshot, timing, etc.)
 * @return a tab that implements <code>ProfileLaunchConfigurationTabGroup</code>
 * and provides the necessary profiling type, or <code>null</code> if none could be found.
 * @since 2.0
 */
public static ProfileLaunchConfigurationTabGroup getTabGroupProvider(String type) {
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentType = config.getAttribute("type");
            // $NON-NLS-1$
            String shortcut = config.getAttribute("tabgroup");
            if (currentType != null && shortcut != null && currentType.equals(type)) {
                try {
                    Object obj = config.createExecutableExtension(// $NON-NLS-1$
                    "tabgroup");
                    if (obj instanceof ProfileLaunchConfigurationTabGroup) {
                        return (ProfileLaunchConfigurationTabGroup) obj;
                    }
                } catch (CoreException e) {
                // continue, perhaps another configuration will succeed
                }
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 2 with ProfileLaunchConfigurationTabGroup

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

the class ProviderFramework method getTabGroupProviderFromId.

/**
 * Get a profiling tab that is associated with the specified id.
 * This looks through extensions of the extension point
 * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code> that have a
 * specific id.
 *
 * @param id A unique identifier
 * @return a tab that implements <code>ProfileLaunchConfigurationTabGroup</code>
 * and provides the necessary profiling type, or <code>null</code> if none could be found.
 * @since 2.0
 */
public static ProfileLaunchConfigurationTabGroup getTabGroupProviderFromId(String id) {
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentId = config.getAttribute("id");
            // $NON-NLS-1$
            String tabgroup = config.getAttribute("tabgroup");
            if (currentId != null && tabgroup != null && currentId.equals(id)) {
                try {
                    Object obj = config.createExecutableExtension(// $NON-NLS-1$
                    "tabgroup");
                    if (obj instanceof ProfileLaunchConfigurationTabGroup) {
                        return (ProfileLaunchConfigurationTabGroup) obj;
                    }
                } catch (CoreException e) {
                // continue, perhaps another configuration will succeed
                }
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with ProfileLaunchConfigurationTabGroup

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

the class AbstractProfilingOptionsTab method loadTabGroupItems.

private void loadTabGroupItems(CTabFolder tabgroup, String curProviderId) {
    // dispose of old tabs and their state
    for (CTabItem item : tabgroup.getItems()) {
        item.dispose();
    }
    setErrorMessage(null);
    initialized.clear();
    ProfileLaunchConfigurationTabGroup tabGroupConfig;
    if (curProviderId == null || curProviderId.isEmpty()) {
        curProviderId = getDefaultProviderId();
    }
    // starting initialization of this tab's controls
    initialized.put(curProviderId, false);
    tabGroupConfig = ProviderFramework.getTabGroupProviderFromId(curProviderId);
    if (tabGroupConfig == null) {
        String profilingToolName = null;
        try {
            profilingToolName = initial.getAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, (String) null);
        } catch (CoreException e) {
        // do nothing
        }
        if (profilingToolName == null) {
            setErrorMessage(NLS.bind(Messages.ProfilingTab_specified_providerid_not_installed, curProviderId));
        } else {
            setErrorMessage(NLS.bind(Messages.ProfilingTab_specified_profiler_not_installed, profilingToolName));
        }
        return;
    }
    tabs = tabGroupConfig.getProfileTabs();
    setProvider(curProviderId);
    // Show provider name in combo.
    int itemIndex = getComboItemIndexFromId(curProviderId);
    providerCombo.select(itemIndex);
    // Set name of configuration.
    setConfigurationName(providerCombo.getText());
    // create the tab item, and load the specified tab inside
    for (ILaunchConfigurationTab tab : tabs) {
        tab.setLaunchConfigurationDialog(getLaunchConfigurationDialog());
        CTabItem item = new CTabItem(tabgroup, SWT.NONE);
        item.setText(tab.getName());
        item.setImage(tab.getImage());
        tab.createControl(tabgroup);
        item.setControl(tab.getControl());
        tabgroup.setSelection(0);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) CTabItem(org.eclipse.swt.custom.CTabItem) ILaunchConfigurationTab(org.eclipse.debug.ui.ILaunchConfigurationTab)

Example 4 with ProfileLaunchConfigurationTabGroup

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

the class ProviderLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (config != null) {
        // get provider id from configuration.
        String providerId = config.getAttribute(ProviderProfileConstants.PROVIDER_CONFIG_ATT, // $NON-NLS-1$
        "");
        String providerToolName = config.getAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, // $NON-NLS-1$
        "");
        if (providerId == null || providerId.isEmpty()) {
            // $NON-NLS-1$
            String cProjectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
            if (cProjectName != null && !cProjectName.isEmpty()) {
                // We have a previously created C/C++ run/debug configuration and now Linux Tools
                // profiling framework has been added.  Find a suitable default provider id to use
                // and perform initialization prior to profiling.
                String defaultType = null;
                String[] categories = ProviderFramework.getProviderCategories();
                if (categories.length == 0) {
                    infoDialog(Messages.ProviderNoProfilers_title_0, Messages.ProviderNoProfilers_msg_0);
                    return;
                }
                for (String category : categories) {
                    // Give precedence to timing category if present
                    if (category.equals("timing")) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        defaultType = "timing";
                    }
                }
                // if default category still not set, take first one found
                if (defaultType == null)
                    defaultType = categories[0];
                providerId = ProviderFramework.getProviderIdToRun(null, defaultType);
                ProfileLaunchConfigurationTabGroup tabGroupConfig = ProviderFramework.getTabGroupProviderFromId(providerId);
                if (tabGroupConfig == null) {
                    infoDialog(Messages.ProviderNoProfilers_title_0, Messages.ProviderNoProfilers_msg_0);
                    return;
                }
                AbstractLaunchConfigurationTab[] tabs = tabGroupConfig.getProfileTabs();
                // Set up defaults according to profiling tabs.  We must use a working copy
                // to do this which we save at the end to the original copy.
                ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
                for (ILaunchConfigurationTab tab : tabs) {
                    tab.setDefaults(wc);
                }
                config = wc.doSave();
            }
        }
        // get delegate associated with provider id.
        AbstractCLaunchDelegate delegate = ProviderFramework.getConfigurationDelegateFromId(providerId);
        // launch delegate
        if (delegate != null) {
            try {
                delegate.launch(config, mode, launch, monitor);
            } catch (CoreException e) {
                errorDialog(Messages.ProviderLaunchError_msg_0, e.getMessage());
            }
        } else {
            String message = providerToolName.isEmpty() ? NLS.bind(Messages.ProviderProfilerMissing_msg_0, providerId) : NLS.bind(Messages.ProviderProfilerMissing_msg_1, providerToolName);
            infoDialog(Messages.ProviderProfilerMissing_title_0, message);
        }
    }
}
Also used : AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) CoreException(org.eclipse.core.runtime.CoreException) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) AbstractCLaunchDelegate(org.eclipse.cdt.launch.AbstractCLaunchDelegate) ILaunchConfigurationTab(org.eclipse.debug.ui.ILaunchConfigurationTab)

Example 5 with ProfileLaunchConfigurationTabGroup

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

the class ProviderLaunchShortcut method setDefaultProfileAttributes.

@Override
protected void setDefaultProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
    // acquire a provider id to run.
    final String providerId = ProviderFramework.getProviderIdToRun(wc, getProfilingType());
    // get tool name from id.
    final String providerToolName = ProviderFramework.getProviderToolNameFromId(providerId);
    // get tab group associated with provider id.
    final ProfileLaunchConfigurationTabGroup tabgroup = ProviderFramework.getTabGroupProviderFromId(providerId);
    /**
     * Certain tabs' setDefaults(ILaunchConfigurationWorkingCopy) may
     * require a launch configuration dialog. Eg. CMainTab generates
     * a name for the configuration based on generateName in setDefaults()
     * so we can create a temporary launch configuration dialog here. With
     * the exception of generateName(String), the other methods do not
     * get called.
     */
    ILaunchConfigurationDialog dialog = new ILaunchConfigurationDialog() {

        @Override
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void updateMessage() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void updateButtons() {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setName(String name) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setActiveTab(int index) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setActiveTab(ILaunchConfigurationTab tab) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ILaunchConfigurationTab[] getTabs() {
            return null;
        }

        @Override
        public String getMode() {
            return null;
        }

        @Override
        public ILaunchConfigurationTab getActiveTab() {
            return null;
        }

        @Override
        public String generateName(String name) {
            if (name == null) {
                // $NON-NLS-1$
                name = "";
            }
            String providerConfigutationName = generateProviderConfigurationName(name, providerToolName);
            return getLaunchManager().generateLaunchConfigurationName(providerConfigutationName);
        }
    };
    // $NON-NLS-1$
    tabgroup.createTabs(dialog, "profile");
    // set configuration to match default attributes for all tabs.
    for (ILaunchConfigurationTab tab : tabgroup.getTabs()) {
        tab.setLaunchConfigurationDialog(dialog);
        tab.setDefaults(wc);
    }
    // get configuration shortcut associated with provider id.
    ProfileLaunchShortcut shortcut = ProviderFramework.getLaunchShortcutProviderFromId(providerId);
    // set attributes related to the specific profiling shortcut configuration.
    shortcut.setDefaultProfileLaunchShortcutAttributes(wc);
    wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_ATT, providerId);
    // set tool name in configuration.
    wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, providerToolName);
    /**
     * To avoid renaming an already renamed launch configuration, we can
     * check the expected format of the name using regular expressions and
     * skip on matches.
     */
    String curConfigName = wc.getName();
    // $NON-NLS-1$
    Pattern configNamePattern = Pattern.compile(".+\\s\\[.+\\](\\s\\(\\d+\\))?$");
    Matcher match = configNamePattern.matcher(curConfigName);
    if (!match.find()) {
        wc.rename(dialog.generateName(curConfigName));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ILaunchConfigurationDialog(org.eclipse.debug.ui.ILaunchConfigurationDialog) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) ProfileLaunchShortcut(org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ILaunchConfigurationTab(org.eclipse.debug.ui.ILaunchConfigurationTab)

Aggregations

ProfileLaunchConfigurationTabGroup (org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup)6 CoreException (org.eclipse.core.runtime.CoreException)4 ILaunchConfigurationTab (org.eclipse.debug.ui.ILaunchConfigurationTab)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 AbstractCLaunchDelegate (org.eclipse.cdt.launch.AbstractCLaunchDelegate)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 AbstractLaunchConfigurationTab (org.eclipse.debug.ui.AbstractLaunchConfigurationTab)1 ILaunchConfigurationDialog (org.eclipse.debug.ui.ILaunchConfigurationDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ProfileLaunchShortcut (org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut)1 StubbyLaunchConfigurationTabGroup (org.eclipse.linuxtools.profiling.provider.tests.stubby.StubbyLaunchConfigurationTabGroup)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Test (org.junit.Test)1