diff options
12 files changed, 169 insertions, 28 deletions
diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF b/oprofile/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF index 17fa6d832c..93d5af1aa4 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Bundle-Version: 0.3.1.qualifier Bundle-Activator: org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin Bundle-Vendor: %bundleProvider Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.0", - org.eclipse.ui;bundle-version="3.4.0" + org.eclipse.ui;bundle-version="3.4.0", + org.eclipse.linuxtools.tools.launch.core;bundle-version="0.8.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ClassPath: oprofile-core.jar Bundle-ActivationPolicy: lazy @@ -21,3 +22,4 @@ Export-Package: org.eclipse.linuxtools.oprofile.core, org.eclipse.linuxtools.oprofile.core.opxml.sessions Bundle-Localization: plugin Eclipse-BundleShape: dir +Import-Package: org.eclipse.core.resources diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/op_error_key b/oprofile/org.eclipse.linuxtools.oprofile.core/op_error_key index b9946f6330..fe62b76465 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/op_error_key +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/op_error_key @@ -1,2 +1,3 @@ nmi_watchdog=opcontrolNmiWatchdog -distinct=opcontrolDistinct
\ No newline at end of file +distinct=opcontrolDistinct +sudo=opcontrolSudo diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java index 0feb64ae88..f87a368104 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/Oprofile.java @@ -16,12 +16,14 @@ import java.io.File; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import org.eclipse.core.resources.IProject; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.linuxtools.oprofile.core.daemon.OpEvent; import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; import org.eclipse.linuxtools.oprofile.core.model.OpModelEvent; import org.eclipse.linuxtools.oprofile.core.model.OpModelImage; import org.eclipse.linuxtools.oprofile.core.opxml.checkevent.CheckEventsProcessor; +import org.eclipse.linuxtools.tools.launch.core.properties.LinuxtoolsPathProperty; /** @@ -38,9 +40,14 @@ public class Oprofile // Oprofile information private static OpInfo _info; + // Project that will be profiled. + public static IProject _currentProject; + // Make sure that oprofile is ready to go static { - initializeOprofileModule(); + if(_currentProject != null){ + initializeOprofileModule(); + } } /** @@ -60,7 +67,7 @@ public class Oprofile if (!isKernelModuleLoaded()) { OprofileCorePlugin.showErrorDialog("oprofileInit", null); //$NON-NLS-1$ // throw new ExceptionInInitializerError(OprofileProperties.getString("fatal.kernelModuleNotLoaded")); //$NON-NLS-1$ - } else { + } else { _initializeOprofileCore(); } } @@ -88,13 +95,15 @@ public class Oprofile } } - - // Initializes static data for oprofile. + + // Initializes static data for oprofile. private static void _initializeOprofileCore () { - _info = OpInfo.getInfo(); - - if (_info == null) { - throw new ExceptionInInitializerError(OprofileProperties.getString("fatal.opinfoNotParsed")); //$NON-NLS-1$ + if (isKernelModuleLoaded()){ + _info = OpInfo.getInfo(); + + if (_info == null) { + throw new ExceptionInInitializerError(OprofileProperties.getString("fatal.opinfoNotParsed")); //$NON-NLS-1$ + } } } @@ -228,4 +237,32 @@ public class Oprofile return image; } + + // Reloads oprofile modules by calling 'opcontrol --deinit' and 'opcontrol --init' + public static void setCurrentProject(IProject project){ + + if(_currentProject == null){ + _currentProject = project; + initializeOprofileModule(); + } else { + + String currentPath = LinuxtoolsPathProperty.getLinuxtoolsPath(_currentProject); + String newPath = LinuxtoolsPathProperty.getLinuxtoolsPath(project); + + if(!currentPath.equals(newPath)){ + try { + OprofileCorePlugin.getDefault().getOpcontrolProvider().deinitModule(); + _currentProject = project; + OprofileCorePlugin.getDefault().getOpcontrolProvider().initModule(); + } catch (OpcontrolException e) { + OprofileCorePlugin.showErrorDialog("opcontrolProvider", e); //$NON-NLS-1$ + } + _currentProject = project; + } + } + } + + public static IProject getCurrentProject(){ + return _currentProject; + } } diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java index 573643ecfd..18d68a084d 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/daemon/OpInfo.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import org.eclipse.core.resources.IProject; import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; import org.eclipse.linuxtools.oprofile.core.OpxmlException; import org.eclipse.linuxtools.oprofile.core.linux.LinuxOpxmlProvider.OpInfoRunner; diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java index 2952127baf..0c725938bd 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/LinuxOpcontrolProvider.java @@ -18,6 +18,7 @@ import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; @@ -28,14 +29,19 @@ import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonOptions; import org.eclipse.linuxtools.oprofile.core.opxml.sessions.SessionManager; +import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory; +import org.eclipse.linuxtools.tools.launch.core.properties.LinuxtoolsPathProperty; /** * A class which encapsulates running opcontrol. */ public class LinuxOpcontrolProvider implements IOpcontrolProvider { + private static final String _OPCONTROL_EXECUTABLE = "opcontrol"; + // Location of opcontrol security wrapper - private static final String _OPCONTROL_REL_PATH = "natives/linux/scripts/opcontrol"; //$NON-NLS-1$ - private final String OPCONTROL_PROGRAM; + private static final String _OPCONTROL_REL_PATH = "natives/linux/scripts/" + _OPCONTROL_EXECUTABLE; //$NON-NLS-1$ + + private final String _OPCONTROL_PROGRAM; // Initialize the Oprofile kernel module and oprofilefs private static final String _OPD_INIT_MODULE = "--init"; //$NON-NLS-1$ @@ -104,9 +110,9 @@ public class LinuxOpcontrolProvider implements IOpcontrolProvider { public LinuxOpcontrolProvider() throws OpcontrolException { - OPCONTROL_PROGRAM = _findOpcontrol(); + _OPCONTROL_PROGRAM = _findOpcontrol(); } - + /** * Unload the kernel module and oprofilefs * @throws OpcontrolException @@ -242,8 +248,18 @@ public class LinuxOpcontrolProvider implements IOpcontrolProvider { * this appears to currently be the only way we can tell if user correctly * entered the password */ - private boolean _runOpcontrol(ArrayList<String> args) throws OpcontrolException { - args.add(0, OPCONTROL_PROGRAM); + private boolean _runOpcontrol(ArrayList<String> args) throws OpcontrolException { + IProject project = Oprofile.getCurrentProject(); + + + // If no linuxtools' toolchain is defined for this project, use the path for the + // link created by the installation script + if(project == null || LinuxtoolsPathProperty.getLinuxtoolsPath(project).equals("")){ + args.add(0, _OPCONTROL_PROGRAM); + } else{ + args.add(0, _OPCONTROL_EXECUTABLE); + } + // Verbosity hack. If --start or --start-daemon, add verbosity, if set String cmd = (String) args.get(1); if (_verbosity.length() > 0 && (cmd.equals (_OPD_START_COLLECTION) || cmd.equals(_OPD_START_DAEMON))) { @@ -260,7 +276,11 @@ public class LinuxOpcontrolProvider implements IOpcontrolProvider { Process p = null; try { - p = Runtime.getRuntime().exec(cmdArray); + if(project == null || LinuxtoolsPathProperty.getLinuxtoolsPath(project).equals("")){ + p = Runtime.getRuntime().exec(cmdArray); + } else{ + p = RuntimeProcessFactory.getFactory().sudoExec(cmdArray, project); + } } catch (IOException ioe) { throw new OpcontrolException(OprofileCorePlugin.createErrorStatus("opcontrolRun", ioe)); //$NON-NLS-1$ } @@ -319,18 +339,24 @@ public class LinuxOpcontrolProvider implements IOpcontrolProvider { } private static String _findOpcontrol() throws OpcontrolException { - URL url = FileLocator.find(Platform.getBundle(OprofileCorePlugin.getId()), new Path(_OPCONTROL_REL_PATH), null); + IProject project = Oprofile.getCurrentProject(); + URL url = FileLocator.find(Platform.getBundle(OprofileCorePlugin + .getId()), new Path(_OPCONTROL_REL_PATH), null); if (url != null) { try { return FileLocator.toFileURL(url).getPath(); - } catch (IOException ignore) { } - } else { - throw new OpcontrolException(OprofileCorePlugin.createErrorStatus("opcontrolProvider", null)); //$NON-NLS-1$ + } catch (IOException ignore) { + } + // If no linuxtools' toolchain is defined for this project and oprofile is not + // installed, throw exception + } else if(project == null || LinuxtoolsPathProperty.getLinuxtoolsPath(project).equals("")){ + throw new OpcontrolException(OprofileCorePlugin.createErrorStatus( + "opcontrolProvider", null)); //$NON-NLS-1$ } return null; - } + } // Convert the event into arguments for opcontrol private void _eventToArguments(ArrayList<String> args, OprofileDaemonEvent event) { diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java index b873d00a76..3f1848d48b 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/linux/OpxmlRunner.java @@ -29,6 +29,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.oprofile.core.Oprofile; import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; import org.eclipse.linuxtools.oprofile.core.OprofileProperties; import org.eclipse.linuxtools.oprofile.core.OpxmlException; @@ -39,6 +40,7 @@ import org.eclipse.linuxtools.oprofile.core.opxml.checkevent.CheckEventAdapter; import org.eclipse.linuxtools.oprofile.core.opxml.info.InfoAdapter; import org.eclipse.linuxtools.oprofile.core.opxml.modeldata.ModelDataAdapter; import org.eclipse.linuxtools.oprofile.core.opxml.sessions.SessionManager; +import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory; import org.eclipse.osgi.util.NLS; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -55,6 +57,7 @@ import org.xml.sax.XMLReader; */ public class OpxmlRunner { private OprofileSAXHandler _handler; + /** * Returns the current XMLProcessor handling parsing of opxml output. @@ -189,7 +192,7 @@ public class OpxmlRunner { cmd.add("event:" + args[1]); //$NON-NLS-1$ } String [] a = {}; - p = Runtime.getRuntime().exec(cmd.toArray(a)); + p = RuntimeProcessFactory.getFactory().exec(cmd.toArray(a), Oprofile.getCurrentProject()); StringBuilder output = new StringBuilder(); StringBuilder errorOutput = new StringBuilder(); @@ -273,8 +276,8 @@ public class OpxmlRunner { String [] ret = null; try { String cmd[] = {"opreport", "-X", "-d"}; - Process p = Runtime.getRuntime().exec(cmd); + Process p = RuntimeProcessFactory.getFactory().exec(cmd, Oprofile.getCurrentProject()); StringBuilder output = new StringBuilder(); StringBuilder errorOutput = new StringBuilder(); String s = null; diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/oprofile.properties b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/oprofile.properties index b306dc3df8..bb2ab7d749 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/oprofile.properties +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/oprofile.properties @@ -25,6 +25,7 @@ opcontrolNonZeroExitCodeExtraInfo.error.statusMessage=Exit code of opcontrol ind opcontrolNonZeroExitCode.error.statusMessage=Exit code of opcontrol indicates failure.\nIf this system does not have /usr/bin/consolehelper, make sure you have added\nthe following line to /etc/sudoers:\n<username> ALL=(ALL) NOPASSWD: <path to opcontrol, e.g. /usr/bin/opcontrol> opcontrolNmiWatchdog.error.statusMessage=Error: counter 0 not available\nnmi_watchdog using this resource?\nTry:\nopcontrol --deinit\necho 0 > /proc/sys/kernel/nmi_watchdog\nin a Terminal. Then try profiling your binary again. opcontrolDistinct.error.statusMessage= Error: All events must be distinct. +opcontrolSudo.error.statusMessage=Error: could not execute opcontrol using sudo without password.\nMake sure you have added the following line to /etc/sudoers:\n<username> ALL=(ALL) NOPASSWD: <path to opcontrol defined for current project, e.g. /usr/bin/opcontrol> opcontrolProvider.error.statusMessage=Could not find an OpcontrolProvider, or no opcontrol binary exists.\n\nPlease ensure you have run the install script as the root user. The install script will be in the org.eclipse.linuxtools.oprofile.core plugin, which may be located in one of a few places. You can locate it with the following command (type in a terminal):\n\nfind <~/.eclipse OR the location from which you're running eclipse> \ \n-name 'org.eclipse.linuxtools.oprofile.core_*'\n\nWhen you have found the location of the plugin, as root, run the install script contained therein:\n\ncd <path to org.eclipse.linuxtools.oprofile.core>/natives/linux/scripts\nsh install.sh\n\nYou may need to set the script as executable before running this command; do this with:\n\nchmod u+x install.sh diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/EventIdCache.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/EventIdCache.java index ed8b35f23a..cf9a832426 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/EventIdCache.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/EventIdCache.java @@ -11,7 +11,9 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.linuxtools.oprofile.core.Oprofile; import org.eclipse.linuxtools.oprofile.core.opxml.info.InfoAdapter; +import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -76,7 +78,7 @@ public class EventIdCache { */ private void readXML() { try { - Process p = Runtime.getRuntime().exec(OPHELP + " " + "-X"); + Process p = RuntimeProcessFactory.getFactory().exec(OPHELP + " " + "-X", Oprofile.getCurrentProject()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { diff --git a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/InfoAdapter.java b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/InfoAdapter.java index d66a34a759..de564d416f 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/InfoAdapter.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/oprofile/core/opxml/info/InfoAdapter.java @@ -12,8 +12,10 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.linuxtools.oprofile.core.Oprofile; import org.eclipse.linuxtools.oprofile.core.opxml.AbstractDataAdapter; import org.eclipse.linuxtools.oprofile.core.opxml.EventIdCache; +import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -82,7 +84,7 @@ public class InfoAdapter extends AbstractDataAdapter{ // In timer mode, we have no relevant XML generated by ophelp createDOM(null); }else{ - Process p = Runtime.getRuntime().exec("ophelp -X"); + Process p = RuntimeProcessFactory.getFactory().exec("ophelp -X", Oprofile.getCurrentProject()); InputStream is = p.getInputStream(); createDOM(is); } diff --git a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java index 27a19ee8dc..4011b839de 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/AbstractOprofileLaunchConfigurationDelegate.java @@ -19,7 +19,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -40,8 +42,11 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; public abstract class AbstractOprofileLaunchConfigurationDelegate extends ProfileLaunchConfigurationDelegate { + + protected ILaunchConfiguration config; + public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { - + this.config = config; LaunchOptions options = new LaunchOptions(); //default options created in the constructor options.loadConfiguration(config); IPath exePath = verifyProgramPath( config ); @@ -148,4 +153,14 @@ public abstract class AbstractOprofileLaunchConfigurationDelegate extends Profil protected boolean oprofileStatus() throws OpcontrolException { return OprofileCorePlugin.getDefault().getOpcontrolProvider().status(); } + + protected IProject getProject(){ + try{ + IProject project = CDebugUtils.verifyCProject(config).getProject(); + return project; + } catch (CoreException e) { + e.printStackTrace(); + } + return null; + } } diff --git a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/OprofileLaunchConfigurationDelegate.java b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/OprofileLaunchConfigurationDelegate.java index d68f4eba7c..4c1915eca0 100644 --- a/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/OprofileLaunchConfigurationDelegate.java +++ b/oprofile/org.eclipse.linuxtools.oprofile.launch/src/org/eclipse/linuxtools/oprofile/launch/launching/OprofileLaunchConfigurationDelegate.java @@ -16,7 +16,10 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchesListener2; import org.eclipse.linuxtools.oprofile.core.OpcontrolException; +import org.eclipse.linuxtools.oprofile.core.Oprofile; import org.eclipse.linuxtools.oprofile.core.OprofileCorePlugin; +import org.eclipse.linuxtools.oprofile.core.OprofileProperties; +import org.eclipse.linuxtools.oprofile.core.daemon.OpInfo; import org.eclipse.linuxtools.oprofile.core.daemon.OprofileDaemonEvent; import org.eclipse.linuxtools.oprofile.launch.configuration.LaunchOptions; import org.eclipse.swt.widgets.Display; @@ -27,6 +30,10 @@ public class OprofileLaunchConfigurationDelegate extends AbstractOprofileLaunchC protected boolean preExec(LaunchOptions options, OprofileDaemonEvent[] daemonEvents) { //set up and launch the oprofile daemon try { + // Set current project to allow using the oprofile path that + // was chosen for the project + Oprofile.setCurrentProject(getProject()); + if (!oprofileStatus()) return false; diff --git a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java index 9f28d71a0d..b45d26bbfa 100644 --- a/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java +++ b/profiling/org.eclipse.linuxtools.tools.launch.core/src/org/eclipse/linuxtools/tools/launch/core/factory/RuntimeProcessFactory.java @@ -13,8 +13,11 @@ package org.eclipse.linuxtools.tools.launch.core.factory; import java.io.BufferedReader; import java.io.File; -import java.io.InputStreamReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.StringTokenizer; import org.eclipse.core.resources.IProject; @@ -43,6 +46,11 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { cmdarray[0] = whichCommand(cmdarray[0], envp); return cmdarray; } + + private String[] fillPathSudoCommand(String[] cmdarray, String[] envp) throws IOException { + cmdarray[2] = whichCommand(cmdarray[2], envp); + return cmdarray; + } public String whichCommand(String command, IProject project) throws IOException { return whichCommand(command, updateEnvironment(null, project)); @@ -98,4 +106,40 @@ public class RuntimeProcessFactory extends LinuxtoolsProcessFactory { return Runtime.getRuntime().exec(cmdarray, envp, dir); } + + public Process sudoExec(String cmd, IProject project) throws IOException { + return sudoExec(cmd, null, null, project); + } + + public Process sudoExec(String cmd, String[] envp, IProject project) throws IOException { + return exec(cmd, envp, null, project); + } + + public Process sudoExec(String cmd, String[] envp, File dir, IProject project) + throws IOException { + return sudoExec(tokenizeCommand(cmd), envp, dir, project); + } + + public Process sudoExec(String[] cmdarray, IProject project) throws IOException { + return sudoExec(cmdarray, null, project); + } + + public Process sudoExec(String[] cmdarray, String[] envp, IProject project) throws IOException { + return sudoExec(cmdarray, envp, null, project); + } + + public Process sudoExec(String[] cmdarray, String[] envp, File dir, IProject project) throws IOException { + List<String> cmdList = Arrays.asList(cmdarray); + ArrayList<String> cmdArrayList = new ArrayList<String>(cmdList); + cmdArrayList.add(0, "sudo"); + cmdArrayList.add(1, "-n"); + + String[] cmdArraySudo = new String[cmdArrayList.size()]; + cmdArrayList.toArray(cmdArraySudo); + + envp = updateEnvironment(envp, project); + cmdArraySudo = fillPathSudoCommand(cmdArraySudo, envp); + + return Runtime.getRuntime().exec(cmdArraySudo, envp, dir); + } } |