Search in sources :

Example 1 with CachegrindFunction

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

the class CModelLabelsTest method testNestedMethodLabel.

@Test
public void testNestedMethodLabel() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testNestedMethodLabel");
    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, "A::B::e()");
    assertTrue(func.getModel() instanceof IMethod);
    checkLabelProvider(func, file);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) 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) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) IMethod(org.eclipse.cdt.core.model.IMethod) Test(org.junit.Test)

Example 2 with CachegrindFunction

use of org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction 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 3 with CachegrindFunction

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

the class CModelLabelsTest method testMethodLabel.

@Test
public void testMethodLabel() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testMethodLabel");
    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, "A::A()");
    assertTrue(func.getModel() instanceof IMethod);
    checkLabelProvider(func, file);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) 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) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) IMethod(org.eclipse.cdt.core.model.IMethod) Test(org.junit.Test)

Example 4 with CachegrindFunction

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

the class CModelLabelsTest method testFunctionLabel.

@Test
public void testFunctionLabel() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testFunctionLabel");
    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");
    assertTrue(func.getModel() instanceof IFunction);
    checkLabelProvider(func, file);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) 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) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) IFunction(org.eclipse.cdt.core.model.IFunction) Test(org.junit.Test)

Example 5 with CachegrindFunction

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

the class DoubleClickTest method testDoubleClickFunction.

@Test
public void testDoubleClickFunction() 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");
    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 line = textSelection.getStartLine() + 1;
    int expectedLine = ((IFunction) func.getModel()).getSourceRange().getStartLine();
    assertEquals(expectedLine, line);
}
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) IEditorPart(org.eclipse.ui.IEditorPart) Test(org.junit.Test)

Aggregations

CachegrindFunction (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction)9 CachegrindFile (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile)8 CachegrindOutput (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput)7 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)5 CachegrindLine (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine)5 Test (org.junit.Test)5 ICachegrindElement (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement)3 IMethod (org.eclipse.cdt.core.model.IMethod)2 TextSelection (org.eclipse.jface.text.TextSelection)2 ISelection (org.eclipse.jface.viewers.ISelection)2 TreePath (org.eclipse.jface.viewers.TreePath)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 Tree (org.eclipse.swt.widgets.Tree)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 CModelException (org.eclipse.cdt.core.model.CModelException)1 IFunction (org.eclipse.cdt.core.model.IFunction)1