Search in sources :

Example 1 with SystemTapUIErrorMessages

use of org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages in project linuxtools by eclipse.

the class SystemTapLaunchConfigurationDelegate method finishLaunch.

private void finishLaunch(ILaunch launch, ILaunchConfiguration config, IProgressMonitor monitor) {
    try {
        // Check for cancellation
        if (monitor.isCanceled() || launch == null) {
            return;
        }
        monitor.worked(1);
        // set the default source locator if required
        setDefaultSourceLocator(launch, config);
        /*
             * Fetch a parser
             */
        String parserClass = config.getAttribute(LaunchConfigurationConstants.PARSER_CLASS, LaunchConfigurationConstants.DEFAULT_PARSER_CLASS);
        IExtensionRegistry reg = Platform.getExtensionRegistry();
        IConfigurationElement[] extensions = reg.getConfigurationElementsFor(PluginConstants.PARSER_RESOURCE, PluginConstants.PARSER_NAME, parserClass);
        if (extensions == null || extensions.length < 1) {
            SystemTapUIErrorMessages mess = new // $NON-NLS-1$
            SystemTapUIErrorMessages(// $NON-NLS-1$
            Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser1"), // $NON-NLS-1$
            Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser1"), // $NON-NLS-1$
            Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser2") + Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser3") + // $NON-NLS-1$
            parserClass);
            mess.schedule();
            return;
        }
        IConfigurationElement element = extensions[0];
        SystemTapParser parser = (SystemTapParser) element.createExecutableExtension(PluginConstants.ATTR_CLASS);
        // Set parser options
        parser.setViewID(config.getAttribute(LaunchConfigurationConstants.VIEW_CLASS, LaunchConfigurationConstants.VIEW_CLASS));
        parser.setSourcePath(outputPath);
        parser.setMonitor(SubMonitor.convert(monitor));
        parser.setDone(false);
        parser.setSecondaryID(config.getAttribute(LaunchConfigurationConstants.SECONDARY_VIEW_ID, LaunchConfigurationConstants.DEFAULT_SECONDARY_VIEW_ID));
        parser.setKillButtonEnabled(true);
        monitor.worked(1);
        /*
             * Launch
             */
        File workDir = getWorkingDirectory(config);
        if (workDir == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            workDir = new File(System.getProperty("user.home", "."));
        }
        // Put command into a shell script
        String cmd = generateCommand();
        // $NON-NLS-1$ //$NON-NLS-2$
        File script = File.createTempFile("org.eclipse.linuxtools.profiling.launch" + System.currentTimeMillis(), ".sh");
        // $NON-NLS-1$
        String data = "#!/bin/sh\nexec " + cmd;
        try (FileOutputStream out = new FileOutputStream(script)) {
            out.write(data.getBytes());
        }
        // $NON-NLS-1$
        String[] commandArray = new String[] { "sh", script.getAbsolutePath() };
        Process subProcess = CdtSpawnerProcessFactory.getFactory().exec(commandArray, getEnvironment(config), workDir, true);
        IProcess process = DebugPlugin.newProcess(launch, subProcess, renderProcessLabel(commandArray[0]));
        // set the command line used
        process.setAttribute(IProcess.ATTR_CMDLINE, cmd);
        monitor.worked(1);
        StreamListener s = new StreamListener();
        process.getStreamsProxy().getErrorStreamMonitor().addListener(s);
        while (!process.isTerminated()) {
            Thread.sleep(100);
            if ((monitor != null && monitor.isCanceled()) || parser.isDone()) {
                parser.cancelJob();
                process.terminate();
                return;
            }
        }
        Thread.sleep(100);
        s.close();
        parser.setKillButtonEnabled(false);
        if (process.getExitValue() != 0) {
            parser.cancelJob();
            // exit code for command not found
            if (process.getExitValue() == 127) {
                SystemTapUIErrorMessages errorDialog = new SystemTapUIErrorMessages(// $NON-NLS-1$
                Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), // $NON-NLS-1$
                Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), // $NON-NLS-1$
                Messages.getString("SystemTapLaunchConfigurationDelegate.stapNotFound"));
                errorDialog.schedule();
            } else {
                SystemTapErrorHandler errorHandler = new SystemTapErrorHandler();
                // Prepare stap information
                // $NON-NLS-1$
                errorHandler.appendToLog(config.getName() + Messages.getString("SystemTapLaunchConfigurationDelegate.stap_command") + cmd + PluginConstants.NEW_LINE + PluginConstants.NEW_LINE);
                // Handle error from TEMP_ERROR_OUTPUT
                errorHandler.handle(monitor, new FileReader(TEMP_ERROR_OUTPUT));
                if ((monitor != null && monitor.isCanceled())) {
                    return;
                }
                errorHandler.finishHandling();
                if (errorHandler.isErrorRecognized()) {
                    SystemTapUIErrorMessages errorDialog = new SystemTapUIErrorMessages(// $NON-NLS-1$
                    Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), // $NON-NLS-1$
                    Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), errorHandler.getErrorMessage());
                    errorDialog.schedule();
                }
            }
            return;
        }
        if (element.getAttribute(PluginConstants.ATTR_REALTIME).equals(PluginConstants.VAL_TRUE)) {
            parser.setRealTime(true);
        }
        parser.schedule();
        monitor.worked(1);
        String message = generateErrorMessage(config.getName(), binaryArguments);
        DocWriter dw = new // $NON-NLS-1$
        DocWriter(// $NON-NLS-1$
        Messages.getString("SystemTapLaunchConfigurationDelegate.DocWriterName"), (Helper.getConsoleByName(config.getName())), message);
        dw.schedule();
    } catch (IOException | InterruptedException | CoreException e) {
        e.printStackTrace();
    } finally {
        monitor.done();
    }
}
Also used : SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DocWriter(org.eclipse.linuxtools.internal.callgraph.core.DocWriter) SystemTapErrorHandler(org.eclipse.linuxtools.internal.callgraph.core.SystemTapErrorHandler) SystemTapParser(org.eclipse.linuxtools.internal.callgraph.core.SystemTapParser) CoreException(org.eclipse.core.runtime.CoreException) FileOutputStream(java.io.FileOutputStream) FileReader(java.io.FileReader) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) IStreamListener(org.eclipse.debug.core.IStreamListener)

Example 2 with SystemTapUIErrorMessages

use of org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages in project linuxtools by eclipse.

the class LaunchStapGraph method launch.

public void launch(IBinary bin, String mode, ILaunchConfigurationWorkingCopy wc) {
    super.initialize();
    this.bin = bin;
    // $NON-NLS-1$
    name = "SystemTapGraph";
    binName = getName(bin);
    partialScriptPath = PluginConstants.getPluginLocation() + // $NON-NLS-1$
    "parse_function_partial.stp";
    // $NON-NLS-1$
    viewID = "org.eclipse.linuxtools.callgraph.callgraphview";
    projectName = bin.getCProject().getElementName();
    try {
        if (wc == null) {
            wc = createConfiguration(bin, name);
        }
        binaryPath = bin.getResource().getLocation().toString();
        arguments = binaryPath;
        outputPath = PluginConstants.getDefaultIOPath();
        if (writeFunctionListToScript(resourceToSearchFor) == null) {
            return;
        }
        if (funcs == null || funcs.length() < 0) {
            return;
        }
        needToGenerate = true;
        finishLaunch(name, mode, wc);
    } catch (IOException e) {
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
        "LaunchShortcutScriptGen", // $NON-NLS-1$
        Messages.getString("LaunchStapGraph.ScriptGenErr"), // $NON-NLS-1$
        Messages.getString("LaunchStapGraph.ScriptGenErrMsg"));
        mess.schedule();
        e.printStackTrace();
    } finally {
        // $NON-NLS-1$
        resourceToSearchFor = "";
        searchForResource = false;
    }
}
Also used : SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) IOException(java.io.IOException)

Example 3 with SystemTapUIErrorMessages

use of org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages in project linuxtools by eclipse.

the class SystemTapLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor m) throws CoreException {
    if (m == null) {
        m = new NullProgressMonitor();
    }
    SubMonitor monitor = SubMonitor.convert(m, "SystemTap runtime monitor", // $NON-NLS-1$
    5);
    initialize();
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    /*
         * Set variables
         */
    if (!config.getAttribute(LaunchConfigurationConstants.ARGUMENTS, LaunchConfigurationConstants.DEFAULT_ARGUMENTS).equals(LaunchConfigurationConstants.DEFAULT_ARGUMENTS)) {
        arguments = config.getAttribute(LaunchConfigurationConstants.ARGUMENTS, LaunchConfigurationConstants.DEFAULT_ARGUMENTS);
        needsArguments = true;
    }
    if (!config.getAttribute(LaunchConfigurationConstants.BINARY_PATH, LaunchConfigurationConstants.DEFAULT_BINARY_PATH).equals(LaunchConfigurationConstants.DEFAULT_BINARY_PATH)) {
        binaryPath = config.getAttribute(LaunchConfigurationConstants.BINARY_PATH, LaunchConfigurationConstants.DEFAULT_BINARY_PATH);
        needsBinary = true;
    }
    if (!config.getAttribute(LaunchConfigurationConstants.BINARY_ARGUMENTS, LaunchConfigurationConstants.DEFAULT_BINARY_ARGUMENTS).equals(LaunchConfigurationConstants.DEFAULT_BINARY_ARGUMENTS)) {
        binaryArguments = config.getAttribute(LaunchConfigurationConstants.BINARY_ARGUMENTS, LaunchConfigurationConstants.DEFAULT_BINARY_ARGUMENTS);
    }
    if (!config.getAttribute(LaunchConfigurationConstants.SCRIPT_PATH, LaunchConfigurationConstants.DEFAULT_SCRIPT_PATH).equals(LaunchConfigurationConstants.DEFAULT_SCRIPT_PATH)) {
        scriptPath = config.getAttribute(LaunchConfigurationConstants.SCRIPT_PATH, LaunchConfigurationConstants.DEFAULT_SCRIPT_PATH);
    }
    // Generate script if needed
    if (config.getAttribute(LaunchConfigurationConstants.NEED_TO_GENERATE, LaunchConfigurationConstants.DEFAULT_NEED_TO_GENERATE)) {
        temporaryScript = new File(scriptPath);
        temporaryScript.delete();
        try {
            temporaryScript.createNewFile();
            try (FileWriter fstream = new FileWriter(temporaryScript);
                BufferedWriter out = new BufferedWriter(fstream)) {
                out.write(config.getAttribute(LaunchConfigurationConstants.GENERATED_SCRIPT, LaunchConfigurationConstants.DEFAULT_GENERATED_SCRIPT));
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    stap = config.getAttribute(LaunchConfigurationConstants.COMMAND, PluginConstants.STAP_PATH);
    /**
     * Generate partial command
     */
    partialCommand = ConfigurationOptionsSetter.setOptions(config);
    outputPath = config.getAttribute(LaunchConfigurationConstants.OUTPUT_PATH, PluginConstants.getDefaultOutput());
    boolean fileExists = true;
    try {
        // Make sure the output file exists
        File tempFile = new File(outputPath);
        tempFile.delete();
        fileExists = tempFile.createNewFile();
    } catch (IOException e1) {
        fileExists = false;
    }
    // check for cancellation
    if (!fileExists || monitor.isCanceled()) {
        SystemTapUIErrorMessages mess = new // $NON-NLS-1$
        SystemTapUIErrorMessages(// $NON-NLS-1$
        Messages.getString("SystemTapLaunchConfigurationDelegate.0"), Messages.getString("SystemTapLaunchConfigurationDelegate.1"), // $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("SystemTapLaunchConfigurationDelegate.2") + outputPath + // $NON-NLS-1$
        Messages.getString("SystemTapLaunchConfigurationDelegate.3"));
        mess.schedule();
        return;
    }
    finishLaunch(launch, config, m);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) FileWriter(java.io.FileWriter) SubMonitor(org.eclipse.core.runtime.SubMonitor) SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 4 with SystemTapUIErrorMessages

use of org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages in project linuxtools by eclipse.

the class SystemTapLaunchShortcut method finishLaunchHelper.

/**
 * Helper function for methods common to both types of finishLaunch.
 * @throws IOException
 */
private boolean finishLaunchHelper() throws IOException {
    if (invalid(scriptPath)) {
        scriptPath = setScriptPath();
    }
    if (invalid(scriptPath)) {
        // Setting the variable didn't work, do not launch.
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(Messages.getString(// $NON-NLS-1$
        "SystemTapLaunchShortcut.ErrorMessageName"), Messages.getString("SystemTapLaunchShortcut.ErrorMessageTitle"), // $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("SystemTapLaunchShortcut.ErrorMessage") + name);
        mess.schedule();
        return false;
    }
    if (invalid(parserID)) {
        parserID = setParserID();
    }
    if (invalid(parserID)) {
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
        Messages.getString("SystemTapLaunchShortcut.InvalidParser1"), Messages.getString("SystemTapLaunchShortcut.InvalidParser2"), // $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("SystemTapLaunchShortcut.InvalidParser3"));
        mess.schedule();
        return false;
    }
    if (invalid(viewID)) {
        viewID = setViewID();
    }
    if (invalid(viewID)) {
        // Setting the variable didn't work, do not launch.
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
        Messages.getString("SystemTapLaunchShortcut.InvalidView1"), Messages.getString("SystemTapLaunchShortcut.InvalidView2"), // $NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("SystemTapLaunchShortcut.InvalidView3"));
        mess.schedule();
        return false;
    }
    if (needToGenerate) {
        if (invalid(generatedScript)) {
            generatedScript = generateScript();
        }
        if (invalid(generatedScript)) {
            // Setting the variable didn't work, do not launch.
            SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(Messages.getString(// $NON-NLS-1$
            "SystemTapLaunchShortcut.InvalidGeneration1"), Messages.getString("SystemTapLaunchShortcut.InvalidGeneration2"), // $NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("SystemTapLaunchShortcut.InvalidGeneration3"));
            mess.schedule();
            return false;
        }
    }
    return true;
}
Also used : SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages)

Example 5 with SystemTapUIErrorMessages

use of org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages in project linuxtools by eclipse.

the class SystemTapLaunchShortcut method launch.

/**
 * Default implementation of launch. It will run stap with the selected binary
 * as an argument and set the output path to <code>PluginConstants.getDefaultIOPath()</code>.
 * <br>
 * The name of the created launch will be 'DefaultSystemTapLaunch'
 */
@Override
public void launch(IBinary bin, String mode) {
    initialize();
    this.bin = bin;
    binName = getName(bin);
    // $NON-NLS-1$
    name = "DefaultSystemTapLaunch";
    try {
        ILaunchConfigurationWorkingCopy wc = createConfiguration(bin, name);
        binaryPath = bin.getResource().getLocation().toString();
        arguments = binaryPath;
        outputPath = PluginConstants.getDefaultIOPath();
        finishLaunch(name, mode, wc);
    } catch (IOException e) {
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
        "LaunchShortcutScriptGen", // $NON-NLS-1$
        Messages.getString("LaunchStapGraph.ScriptGenErr"), // $NON-NLS-1$
        Messages.getString("LaunchStapGraph.ScriptGenErrMsg"));
        mess.schedule();
        e.printStackTrace();
    } finally {
        // $NON-NLS-1$
        resourceToSearchFor = "";
        searchForResource = false;
    }
}
Also used : SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IOException(java.io.IOException)

Aggregations

SystemTapUIErrorMessages (org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages)8 IOException (java.io.IOException)5 File (java.io.File)2 ArrayList (java.util.ArrayList)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)1 IStreamListener (org.eclipse.debug.core.IStreamListener)1 IProcess (org.eclipse.debug.core.model.IProcess)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 DocWriter (org.eclipse.linuxtools.internal.callgraph.core.DocWriter)1