Search in sources :

Example 6 with SystemTapUIErrorMessages

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

the class CallgraphView method createAnimateActions.

/**
 * Populates Animate menu.
 */
private void createAnimateActions() {
    // Set animation mode to slow
    animationSlow = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.getString("CallgraphView.AnimationSlow"), // $NON-NLS-1$
    IAction.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            g.setAnimationMode(StapGraph.CONSTANT_ANIMATION_SLOW);
            this.setChecked(true);
            animationSlow.setChecked(true);
            animationFast.setChecked(false);
        }
    };
    animationSlow.setChecked(true);
    // Set animation mode to fast
    animationFast = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.getString("CallgraphView.AnimationFast"), // $NON-NLS-1$
    IAction.AS_RADIO_BUTTON) {

        @Override
        public void run() {
            g.setAnimationMode(StapGraph.CONSTANT_ANIMATION_FASTEST);
            animationSlow.setChecked(false);
            animationFast.setChecked(true);
        }
    };
    // Toggle collapse mode
    modeCollapsedNodes = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.getString("CallgraphView.CollapsedMode"), // $NON-NLS-1$
    IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            if (g.isCollapseMode()) {
                g.setCollapseMode(false);
                g.draw(g.getRootVisibleNodeNumber());
            } else {
                g.setCollapseMode(true);
                g.draw(g.getRootVisibleNodeNumber());
            }
        }
    };
    // $NON-NLS-1$
    ImageDescriptor newImage = getImageDescriptor("icons/mode_collapsednodes.gif");
    modeCollapsedNodes.setImageDescriptor(newImage);
    limits = new // $NON-NLS-1$
    Action(// $NON-NLS-1$
    Messages.getString("CallgraphView.SetLimits"), // $NON-NLS-1$
    IAction.AS_PUSH_BUTTON) {

        private Spinner limit;

        private Spinner buffer;

        private Shell sh;

        @Override
        public void run() {
            sh = new Shell();
            sh.setLayout(new GridLayout());
            sh.setSize(150, 200);
            Label limitLabel = new Label(sh, SWT.NONE);
            limitLabel.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false));
            // $NON-NLS-1$
            limitLabel.setText(Messages.getString("CallgraphView.MaxNodes"));
            limit = new Spinner(sh, SWT.BORDER);
            limit.setMaximum(5000);
            limit.setSelection(g.getMaxNodes());
            limit.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false));
            Label bufferLabel = new Label(sh, SWT.NONE);
            bufferLabel.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false));
            // $NON-NLS-1$
            bufferLabel.setText(Messages.getString("CallgraphView.MaxDepth"));
            buffer = new Spinner(sh, SWT.BORDER);
            buffer.setMaximum(5000);
            buffer.setSelection(g.getLevelBuffer());
            buffer.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false));
            Button setLimit = new Button(sh, SWT.PUSH);
            // $NON-NLS-1$
            setLimit.setText(Messages.getString("CallgraphView.SetValues"));
            setLimit.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, false));
            setLimit.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
                boolean redraw = false;
                if (limit.getSelection() >= 0 && buffer.getSelection() >= 0) {
                    g.setMaxNodes(limit.getSelection());
                    g.setLevelBuffer(buffer.getSelection());
                    if (g.changeLevelLimits(g.getLevelOfNode(g.getRootVisibleNodeNumber()))) {
                        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferTooHigh"), // $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferTooHigh"), // $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferMessage1") + // $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferMessage2") + // $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferMessage3") + Messages.getString("CallgraphView.BufferMessage4") + // $NON-NLS-1$
                        g.getLevelBuffer() + Messages.getString("CallgraphView.BufferMessage5") + // $NON-NLS-1$
                        PluginConstants.NEW_LINE + PluginConstants.NEW_LINE + // $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferMessage6") + // $NON-NLS-1$
                        Messages.getString("CallgraphView.BufferMessage7"));
                        mess.schedule();
                    }
                    redraw = true;
                }
                sh.dispose();
                if (redraw) {
                    g.draw();
                }
            }));
            sh.open();
        }
    };
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 7 with SystemTapUIErrorMessages

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

the class StapGraphParser method parseDotFile.

private IStatus parseDotFile() {
    BufferedReader buff = internalData;
    HashMap<Integer, ArrayList<Integer>> outNeighbours = new HashMap<>();
    ArrayList<String> nameList = new ArrayList<>();
    ArrayList<Integer> idList = new ArrayList<>();
    endingTimeInNS = 0l;
    totalTime = 10000l;
    try {
        String line;
        while ((line = buff.readLine()) != null) {
            if (line.equals("}")) {
                // $NON-NLS-1$
                break;
            }
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            if (line.length() < 1) {
                continue;
            }
            // $NON-NLS-1$
            String[] args = line.split(" ", 2);
            if (args[0].contains("->")) {
                // $NON-NLS-1$
                // connection
                int[] ids = new int[2];
                int called = 1;
                try {
                    // $NON-NLS-1$
                    ids[0] = Integer.parseInt(args[0].split("->")[0]);
                    // $NON-NLS-1$
                    ids[1] = Integer.parseInt(args[0].split("->")[1]);
                    // $NON-NLS-1$
                    int index1 = args[1].indexOf("=\"");
                    // $NON-NLS-1$
                    int index2 = args[1].indexOf("\"]");
                    called = Integer.parseInt(args[1].substring(index1 + 2, index2));
                } catch (NumberFormatException e) {
                    SystemTapUIErrorMessages m = new SystemTapUIErrorMessages(// $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("StapGraphParser.idOrLabel"), // $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("StapGraphParser.idOrLabel"), // $NON-NLS-1$
                    Messages.getString("StapGraphParser.nonNumericLabel"));
                    m.schedule();
                    return Status.CANCEL_STATUS;
                }
                // Set neighbour
                ArrayList<Integer> tmpList = outNeighbours.get(ids[0]);
                if (tmpList == null) {
                    tmpList = new ArrayList<>();
                }
                for (int i = 0; i < called; i++) {
                    tmpList.add(ids[1]);
                }
                outNeighbours.put(ids[0], tmpList);
            } else {
                // node
                try {
                    int id = Integer.parseInt(args[0]);
                    if (firstNode == -1) {
                        firstNode = id;
                    }
                    // $NON-NLS-1$
                    int index = args[1].indexOf("=\"");
                    String name = args[1].substring(index + 2, args[1].indexOf(' ', index));
                    double dtime = 0.0;
                    dtime = Double.parseDouble(args[1].substring(args[1].indexOf(' ') + 1, args[1].indexOf('%')));
                    long time = (long) (dtime * 100);
                    nameList.add(name);
                    idList.add(id);
                    timeMap.put(id, time);
                    serialMap.put(id, name);
                    if (countMap.get(name) == null) {
                        countMap.put(name, 0);
                    }
                    countMap.put(name, countMap.get(name) + 1);
                    long cumulativeTime = (aggregateTimeMap.get(name) != null ? aggregateTimeMap.get(name) : 0) + time;
                    aggregateTimeMap.put(name, cumulativeTime);
                } catch (NumberFormatException e) {
                    SystemTapUIErrorMessages m = new SystemTapUIErrorMessages(// $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("StapGraphParser.idOrTime"), // $NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("StapGraphParser.idOrTime"), // $NON-NLS-1$
                    Messages.getString("StapGraphParser.nonNumericTime"));
                    m.schedule();
                    return Status.CANCEL_STATUS;
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            buff.close();
        } catch (IOException e) {
        // Do nothing
        }
    }
    neighbourMaps.put(0, outNeighbours);
    nameMaps.put(0, nameList);
    idMaps.put(0, idList);
    try {
        view.update();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return Status.OK_STATUS;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Example 8 with SystemTapUIErrorMessages

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

the class StapGraphParser method parse.

private IStatus parse(String s) {
    try {
        if (s.length() < 1) {
            return Status.OK_STATUS;
        }
        switch(s.charAt(0)) {
            case '<':
                /*
                 *
                 * Open tag -- function call
                 *
                 *
                 */
                String[] args = s.substring(1, s.length()).split(DELIM);
                // args[0] = name
                // args[1] = id
                // arsg[2] = time of event
                int id = Integer.parseInt(args[1]);
                long time = Long.parseLong(args[2]);
                int tid = Integer.parseInt(args[3]);
                String name = args[0];
                // and the name contains "__", then this is probably a C directive
                if (!encounteredMain && !isFunctionNameClean(name) && name.contains("__")) {
                    // $NON-NLS-1$
                    skippedDirectives = true;
                    break;
                }
                List<String> nameList = nameMaps.get(tid);
                if (nameList == null) {
                    nameList = new ArrayList<>();
                }
                List<Integer> idList = idMaps.get(tid);
                if (idList == null) {
                    idList = new ArrayList<>();
                }
                HashMap<Integer, ArrayList<Integer>> outNeighbours = neighbourMaps.get(tid);
                if (outNeighbours == null) {
                    outNeighbours = new HashMap<>();
                }
                if (startTime < 1) {
                    startTime = time;
                }
                endingTimeInNS = time;
                name = cleanFunctionName(name);
                if (name.equals("main")) {
                    // $NON-NLS-1$
                    encounteredMain = true;
                }
                if (firstNode == -1) {
                    firstNode = id;
                }
                serialMap.put(id, name);
                timeMap.put(id, time);
                if (aggregateTimeMap.get(name) == null) {
                    aggregateTimeMap.put(name, (long) 0);
                }
                if (nameList.indexOf(name) == -1) {
                    long cumulativeTime = aggregateTimeMap.get(name) - time;
                    aggregateTimeMap.put(name, cumulativeTime);
                    shouldGetEndingTimeForID.add(id);
                }
                if (countMap.get(name) == null) {
                    countMap.put(name, 0);
                }
                countMap.put(name, countMap.get(name) + 1);
                nameList.add(name);
                idList.add(id);
                if (outNeighbours.get(id) == null) {
                    outNeighbours.put(id, new ArrayList<Integer>());
                }
                if (idList.size() > 1) {
                    int parentID = idList.get(idList.size() - 2);
                    outNeighbours.get(parentID).add(id);
                }
                callOrderList.add(id);
                lastFunctionMap.put(tid, id);
                neighbourMaps.put(tid, outNeighbours);
                nameMaps.put(tid, nameList);
                idMaps.put(tid, idList);
                break;
            case '>':
                /*
                 *
                 * Close tag -- Function return
                 *
                 */
                args = s.substring(1, s.length()).split(DELIM);
                // args[0] = name
                // args[1] = time of event
                name = args[0];
                tid = Integer.parseInt(args[2]);
                nameList = nameMaps.get(tid);
                if (nameList == null) {
                    nameList = new ArrayList<>();
                }
                idList = idMaps.get(tid);
                if (idList == null) {
                    idList = new ArrayList<>();
                }
                // and the name contains "__", then this is probably a C directive
                if (!encounteredMain && !isFunctionNameClean(name) && name.contains("__")) {
                    // $NON-NLS-1$
                    skippedDirectives = true;
                    break;
                }
                name = cleanFunctionName(name);
                int lastOccurance = nameList.lastIndexOf(name);
                if (lastOccurance < 0) {
                    // $NON-NLS-1$
                    parsingError(Messages.getString("StapGraphParser.RetMismatch") + name);
                    return Status.CANCEL_STATUS;
                }
                nameList.remove(lastOccurance);
                id = idList.remove(lastOccurance);
                if (timeMap.get(id) == null) {
                    // $NON-NLS-1$
                    parsingError(Messages.getString("StapGraphParser.NoStartTime") + name);
                    return Status.CANCEL_STATUS;
                }
                endingTimeInNS = Long.parseLong(args[1]);
                time = endingTimeInNS - timeMap.get(id);
                timeMap.put(id, time);
                if (id == firstNode) {
                    showTime(id, time);
                }
                // TO BE ADDED TO THE CUMULATIVE TIME FOR FUNCTIONS OF THIS NAME
                if (shouldGetEndingTimeForID.contains(id)) {
                    long cumulativeTime = aggregateTimeMap.get(name) + Long.parseLong(args[1]);
                    aggregateTimeMap.put(name, cumulativeTime);
                }
                nameMaps.put(tid, nameList);
                idMaps.put(tid, idList);
                break;
            default:
                // Messages.getString("StapGraphParser.15") ); //$NON-NLS-1$
                return Status.CANCEL_STATUS;
        }
    } catch (NumberFormatException e) {
        SystemTapUIErrorMessages mess = new SystemTapUIErrorMessages(// $NON-NLS-1$
        Messages.getString("StapGraphParser.BadSymbol"), // $NON-NLS-1$
        Messages.getString("StapGraphParser.BadSymbol"), // $NON-NLS-1$
        Messages.getString("StapGraphParser.BadSymbolMsg1") + // $NON-NLS-1$
        Messages.getString("StapGraphParser.BadSymbolMsg2"));
        mess.schedule();
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : ArrayList(java.util.ArrayList) SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages)

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