Search in sources :

Example 6 with CachegrindOutput

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

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

the class BasicCachegrindTest method testFileNames.

@Test
public void testFileNames() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testFileNames");
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    CachegrindOutput output = view.getOutputs()[0];
    // $NON-NLS-1$
    CachegrindFile file = getFileByName(output, "cpptest.cpp");
    assertNotNull(file);
    // $NON-NLS-1$
    file = getFileByName(output, "cpptest.h");
    assertNotNull(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) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) Test(org.junit.Test)

Example 8 with CachegrindOutput

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

the class BasicCachegrindTest method testNumFunctions.

@Test
public void testNumFunctions() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testNumFunctions");
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    CachegrindOutput output = view.getOutputs()[0];
    // $NON-NLS-1$
    CachegrindFile file = getFileByName(output, "cpptest.cpp");
    assertNotNull(file);
    assertEquals(8, file.getFunctions().length);
}
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) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) Test(org.junit.Test)

Example 9 with CachegrindOutput

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

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

the class CModelLabelsTest method testFileLabelsCPP.

@Test
public void testFileLabelsCPP() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testFileLabelsCPP");
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    CachegrindOutput output = view.getOutputs()[0];
    // $NON-NLS-1$
    CachegrindFile file = getFileByName(output, "cpptest.cpp");
    assertTrue(file.getModel() instanceof ITranslationUnit);
    checkLabelProvider(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) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart) ITranslationUnit(org.eclipse.cdt.core.model.ITranslationUnit) Test(org.junit.Test)

Aggregations

CachegrindOutput (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput)17 Test (org.junit.Test)14 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)13 CachegrindFile (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile)13 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)11 CachegrindFunction (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction)7 TreePath (org.eclipse.jface.viewers.TreePath)5 CachegrindLine (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine)3 IMethod (org.eclipse.cdt.core.model.IMethod)2 ITranslationUnit (org.eclipse.cdt.core.model.ITranslationUnit)2 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)2 TextSelection (org.eclipse.jface.text.TextSelection)2 ISelection (org.eclipse.jface.viewers.ISelection)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 ICachegrindElement (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 IFunction (org.eclipse.cdt.core.model.IFunction)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1