Search in sources :

Example 1 with CachegrindLine

use of org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine in project linuxtools by eclipse.

the class CachegrindViewPart method getHeaderListener.

private SelectionListener getHeaderListener() {
    return SelectionListener.widgetSelectedAdapter(e -> {
        TreeColumn column = (TreeColumn) e.widget;
        Tree tree = viewer.getTree();
        if (column.equals(tree.getSortColumn())) {
            int direction = tree.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP;
            tree.setSortDirection(direction);
        } else {
            tree.setSortDirection(SWT.UP);
        }
        tree.setSortColumn(column);
        viewer.setComparator(new ViewerComparator() {

            @Override
            public int compare(Viewer viewer, Object e1, Object e2) {
                Tree tree = ((TreeViewer) viewer).getTree();
                int direction = tree.getSortDirection();
                ICachegrindElement o1 = (ICachegrindElement) e1;
                ICachegrindElement o2 = (ICachegrindElement) e2;
                long result = 0;
                int sortIndex = Arrays.asList(tree.getColumns()).indexOf(tree.getSortColumn());
                if (sortIndex == 0) {
                    // use compareTo
                    result = o1.compareTo(o2);
                } else {
                    long[] v1 = null;
                    long[] v2 = null;
                    if (o1 instanceof CachegrindFunction && o2 instanceof CachegrindFunction) {
                        v1 = ((CachegrindFunction) o1).getTotals();
                        v2 = ((CachegrindFunction) o2).getTotals();
                    } else if (o1 instanceof CachegrindLine && o2 instanceof CachegrindLine) {
                        v1 = ((CachegrindLine) o1).getValues();
                        v2 = ((CachegrindLine) o2).getValues();
                    } else if (o1 instanceof CachegrindOutput && o2 instanceof CachegrindOutput) {
                        v1 = ((CachegrindOutput) o1).getSummary();
                        v2 = ((CachegrindOutput) o2).getSummary();
                    }
                    if (v1 != null && v2 != null) {
                        result = v1[sortIndex - 1] - v2[sortIndex - 1];
                    }
                }
                // ascending or descending
                result = direction == SWT.UP ? result : -result;
                // overflow check
                if (result > Integer.MAX_VALUE) {
                    result = Integer.MAX_VALUE;
                } else if (result < Integer.MIN_VALUE) {
                    result = Integer.MIN_VALUE;
                }
                return (int) result;
            }
        });
    });
}
Also used : ICachegrindElement(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement) CachegrindOutput(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput) TreeColumn(org.eclipse.swt.widgets.TreeColumn) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) Tree(org.eclipse.swt.widgets.Tree) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine)

Example 2 with CachegrindLine

use of org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine in project linuxtools by eclipse.

the class DoubleClickTest method testDoubleClickLine.

@Test
public void testDoubleClickLine() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testDoubleClickFunction");
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    CachegrindOutput output = view.getOutputs()[0];
    // $NON-NLS-1$
    CachegrindFile file = getFileByName(output, "cpptest.cpp");
    // $NON-NLS-1$
    CachegrindFunction func = getFunctionByName(file, "main");
    CachegrindLine line = func.getLines()[0];
    TreePath path = new TreePath(new Object[] { output, file, func });
    doDoubleClick(path);
    // check file in editor
    IEditorPart editor = checkFile(file);
    // check line number
    ITextEditor textEditor = (ITextEditor) editor;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    TextSelection textSelection = (TextSelection) selection;
    // zero-indexed
    int actualLine = textSelection.getStartLine() + 1;
    assertEquals(line.getLine(), actualLine);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) TreePath(org.eclipse.jface.viewers.TreePath) CachegrindOutput(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine) IEditorPart(org.eclipse.ui.IEditorPart) Test(org.junit.Test)

Example 3 with CachegrindLine

use of org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine in project linuxtools by eclipse.

the class CachegrindLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    ICachegrindElement element = ((ICachegrindElement) cell.getElement());
    int index = cell.getColumnIndex();
    if (index == 0) {
        if (element instanceof CachegrindFile) {
            // Try to use the CElementLabelProvider
            IAdaptable model = ((CachegrindFile) element).getModel();
            if (model != null) {
                cell.setText(cLabelProvider.getText(model));
                cell.setImage(cLabelProvider.getImage(model));
            } else {
                // Fall back
                String name = ((CachegrindFile) element).getName();
                cell.setText(name);
                cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE));
            }
        } else if (element instanceof CachegrindFunction) {
            // Try to use the CElementLabelProvider
            IAdaptable model = ((CachegrindFunction) element).getModel();
            if (model != null) {
                cell.setText(cLabelProvider.getText(model));
                cell.setImage(cLabelProvider.getImage(model));
            } else {
                // Fall back
                String name = ((CachegrindFunction) element).getName();
                cell.setText(name);
                cell.setImage(FUNC_IMG);
            }
        } else if (element instanceof CachegrindLine) {
            // $NON-NLS-1$
            cell.setText(NLS.bind(Messages.getString("CachegrindViewPart.line"), ((CachegrindLine) element).getLine()));
            cell.setImage(DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER_TOP));
        } else if (element instanceof CachegrindOutput) {
            // $NON-NLS-1$
            cell.setText(NLS.bind(Messages.getString("CachegrindViewPart.Total_PID"), ((CachegrindOutput) element).getPid()));
            cell.setImage(DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_REGISTER));
        }
    } else if (element instanceof CachegrindFunction) {
        cell.setText(df.format(((CachegrindFunction) element).getTotals()[index - 1]));
    } else if (element instanceof CachegrindLine) {
        cell.setText(df.format(((CachegrindLine) element).getValues()[index - 1]));
    } else if (element instanceof CachegrindOutput) {
        cell.setText(df.format(((CachegrindOutput) element).getSummary()[index - 1]));
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ICachegrindElement(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) CachegrindOutput(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine)

Example 4 with CachegrindLine

use of org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine in project linuxtools by eclipse.

the class CachegrindParser method parse.

public void parse(CachegrindOutput output, File cgOut) throws IOException {
    try (BufferedReader br = new BufferedReader(new FileReader(cgOut))) {
        output.setPid(ValgrindParserUtils.parsePID(cgOut.getName(), CachegrindLaunchDelegate.OUT_PREFIX));
        String line;
        CachegrindFile curFl = null;
        CachegrindFunction curFn = null;
        while ((line = br.readLine()) != null) {
            if (line.startsWith(EVENTS + COLON)) {
                output.setEvents(ValgrindParserUtils.parseStrValue(line, COLON + SPACE).split(SPACE));
            } else if (line.startsWith(CMD + COLON)) {
            // continue
            } else if (line.startsWith(DESC + COLON)) {
                CachegrindDescription description = parseDescription(line);
                output.addDescription(description);
            } else if (line.startsWith(FL + EQUALS)) {
                curFl = new CachegrindFile(output, ValgrindParserUtils.parseStrValue(line, EQUALS));
                output.addFile(curFl);
            } else if (line.startsWith(FN + EQUALS)) {
                if (curFl != null) {
                    curFn = new CachegrindFunction(curFl, ValgrindParserUtils.parseStrValue(line, EQUALS));
                    curFl.addFunction(curFn);
                } else {
                    ValgrindParserUtils.fail(line);
                }
            } else if (line.startsWith(SUMMARY + COLON)) {
                long[] summary = parseData(line, ValgrindParserUtils.parseStrValue(line, COLON + SPACE).split(SPACE));
                output.setSummary(summary);
            } else {
                // line data
                String[] tokens = line.split(SPACE, 2);
                if (ValgrindParserUtils.isNumber(tokens[0])) {
                    int lineNo = Integer.parseInt(tokens[0]);
                    long[] data = parseData(line, tokens[1].split(SPACE));
                    if (curFn != null) {
                        curFn.addLine(new CachegrindLine(curFn, lineNo, data));
                    } else {
                        ValgrindParserUtils.fail(line);
                    }
                } else {
                    ValgrindParserUtils.fail(line);
                }
            }
        }
    }
}
Also used : CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine) CachegrindDescription(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindDescription)

Example 5 with CachegrindLine

use of org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine in project linuxtools by eclipse.

the class CachegrindViewPart method createPartControl.

@Override
public void createPartControl(Composite parent) {
    Composite top = new Composite(parent, SWT.NONE);
    GridLayout topLayout = new GridLayout();
    topLayout.marginHeight = topLayout.marginWidth = 0;
    top.setLayout(topLayout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer = new TreeViewer(top, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    labelProvider = new CachegrindLabelProvider();
    ColumnViewerToolTipSupport.enableFor(viewer);
    Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
    // $NON-NLS-1$
    column.getColumn().setText(Messages.getString("CachegrindViewPart.Location"));
    column.getColumn().setWidth(COLUMN_SIZE * 4);
    column.getColumn().setResizable(true);
    column.getColumn().addSelectionListener(getHeaderListener());
    column.setLabelProvider(labelProvider);
    contentProvider = new CachegrindTreeContentProvider();
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(labelProvider);
    viewer.setAutoExpandLevel(2);
    doubleClickListener = event -> {
        Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
        String path = null;
        int line = 0;
        if (selection instanceof CachegrindFile) {
            path = ((CachegrindFile) selection).getPath();
        } else if (selection instanceof CachegrindLine) {
            CachegrindLine element = (CachegrindLine) selection;
            CachegrindFile file = (CachegrindFile) element.getParent().getParent();
            path = file.getPath();
            line = element.getLine();
        } else if (selection instanceof CachegrindFunction) {
            CachegrindFunction function = (CachegrindFunction) selection;
            path = ((CachegrindFile) function.getParent()).getPath();
            if (function.getModel() instanceof ISourceReference) {
                ISourceReference model = (ISourceReference) function.getModel();
                try {
                    ISourceRange sr = model.getSourceRange();
                    if (sr != null) {
                        line = sr.getStartLine();
                    }
                } catch (CModelException e1) {
                    e1.printStackTrace();
                }
            }
        }
        if (path != null) {
            try {
                ProfileUIUtils.openEditorAndSelect(path, line, ValgrindUIPlugin.getDefault().getProfiledProject());
            } catch (BadLocationException | CoreException e2) {
                e2.printStackTrace();
            }
        }
    };
    viewer.addDoubleClickListener(doubleClickListener);
    expandAction = new ExpandAction(viewer);
    collapseAction = new CollapseAction(viewer);
    MenuManager manager = new MenuManager();
    manager.addMenuListener(manager1 -> {
        ITreeSelection selection = (ITreeSelection) viewer.getSelection();
        ICachegrindElement element = (ICachegrindElement) selection.getFirstElement();
        if (contentProvider.hasChildren(element)) {
            manager1.add(expandAction);
            manager1.add(collapseAction);
        }
    });
    manager.setRemoveAllWhenShown(true);
    Menu contextMenu = manager.createContextMenu(viewer.getTree());
    viewer.getControl().setMenu(contextMenu);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) CachegrindFunction(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction) CModelException(org.eclipse.cdt.core.model.CModelException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) Tree(org.eclipse.swt.widgets.Tree) CachegrindLine(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine) Menu(org.eclipse.swt.widgets.Menu) ISourceRange(org.eclipse.cdt.core.model.ISourceRange) ICachegrindElement(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement) Composite(org.eclipse.swt.widgets.Composite) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) CoreException(org.eclipse.core.runtime.CoreException) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) ExpandAction(org.eclipse.linuxtools.valgrind.ui.ExpandAction) ISourceReference(org.eclipse.cdt.core.model.ISourceReference) CollapseAction(org.eclipse.linuxtools.valgrind.ui.CollapseAction) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

CachegrindFunction (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction)5 CachegrindLine (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine)5 CachegrindFile (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile)4 CachegrindOutput (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput)3 ICachegrindElement (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Tree (org.eclipse.swt.widgets.Tree)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 CModelException (org.eclipse.cdt.core.model.CModelException)1 ISourceRange (org.eclipse.cdt.core.model.ISourceRange)1 ISourceReference (org.eclipse.cdt.core.model.ISourceReference)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 MenuManager (org.eclipse.jface.action.MenuManager)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1