Search in sources :

Example 1 with SystemTapParser

use of org.eclipse.linuxtools.internal.callgraph.core.SystemTapParser 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)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 IStreamListener (org.eclipse.debug.core.IStreamListener)1 IProcess (org.eclipse.debug.core.model.IProcess)1 DocWriter (org.eclipse.linuxtools.internal.callgraph.core.DocWriter)1 SystemTapErrorHandler (org.eclipse.linuxtools.internal.callgraph.core.SystemTapErrorHandler)1 SystemTapParser (org.eclipse.linuxtools.internal.callgraph.core.SystemTapParser)1 SystemTapUIErrorMessages (org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages)1