Search in sources :

Example 11 with CachegrindFile

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

the class CModelLabelsTest method testFileLabelsH.

@Test
public void testFileLabelsH() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testFileLabelsH");
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    CachegrindOutput output = view.getOutputs()[0];
    // $NON-NLS-1$
    CachegrindFile file = getFileByName(output, "cpptest.h");
    assertTrue(file.getModel() instanceof ITranslationUnit);
    assertTrue(((ITranslationUnit) file.getModel()).isHeaderUnit());
    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)

Example 12 with CachegrindFile

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

Example 13 with CachegrindFile

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

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

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

Aggregations

CachegrindFile (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile)16 CachegrindOutput (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput)13 CachegrindViewPart (org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)12 Test (org.junit.Test)12 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)10 CachegrindFunction (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction)8 CachegrindLine (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindLine)4 TreePath (org.eclipse.jface.viewers.TreePath)3 IEditorPart (org.eclipse.ui.IEditorPart)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 ICachegrindElement (org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 CModelException (org.eclipse.cdt.core.model.CModelException)1