diff options
Diffstat (limited to 'perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui')
10 files changed, 849 insertions, 849 deletions
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDoubleClickAction.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDoubleClickAction.java index 8e23a80fb6..8d8d5a4fb3 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDoubleClickAction.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDoubleClickAction.java @@ -31,49 +31,49 @@ import org.eclipse.linuxtools.profiling.ui.ProfileUIUtils; */ public class PerfDoubleClickAction extends Action { - private TreeViewer viewer; + private TreeViewer viewer; - public PerfDoubleClickAction(TreeViewer v) { - viewer = v; - } - @Override - public void run() { - ISelection selection = viewer.getSelection(); - Object obj = ((IStructuredSelection)selection).getFirstElement(); + public PerfDoubleClickAction(TreeViewer v) { + viewer = v; + } + @Override + public void run() { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection)selection).getFirstElement(); - try { - if (obj instanceof PMLineRef) { - // Open in editor - PMLineRef line = (PMLineRef) obj; - PMFile file = (PMFile) ((PMSymbol) line.getParent()).getParent(); - ProfileUIUtils.openEditorAndSelect(file.getPath(),Integer.parseInt(line.getName())); - } else if (obj instanceof PMFile) { - PMFile file = (PMFile) obj; - ProfileUIUtils.openEditorAndSelect(file.getName(), 1); - } else if (obj instanceof PMSymbol) { - PMSymbol sym = (PMSymbol) obj; - PMFile file = (PMFile) sym.getParent(); - PMDso dso = (PMDso) file.getParent(); + try { + if (obj instanceof PMLineRef) { + // Open in editor + PMLineRef line = (PMLineRef) obj; + PMFile file = (PMFile) ((PMSymbol) line.getParent()).getParent(); + ProfileUIUtils.openEditorAndSelect(file.getPath(),Integer.parseInt(line.getName())); + } else if (obj instanceof PMFile) { + PMFile file = (PMFile) obj; + ProfileUIUtils.openEditorAndSelect(file.getName(), 1); + } else if (obj instanceof PMSymbol) { + PMSymbol sym = (PMSymbol) obj; + PMFile file = (PMFile) sym.getParent(); + PMDso dso = (PMDso) file.getParent(); - if (file.getName().equals(PerfPlugin.STRINGS_UnfiledSymbols)) - return; // Don't try to do anything if we don't know where or what the symbol is. + if (file.getName().equals(PerfPlugin.STRINGS_UnfiledSymbols)) + return; // Don't try to do anything if we don't know where or what the symbol is. - String binaryPath = dso.getPath(); - ICProject project; - project = ProfileUIUtils.findCProjectWithAbsolutePath(binaryPath); - Map<String, int[]> map = ProfileUIUtils.findFunctionsInProject(project, sym.getFunctionName(), -1, file.getPath(), true); - boolean bFound = false; - for (Map.Entry<String, int[]> entry : map.entrySet()) { - ProfileUIUtils.openEditorAndSelect(entry.getKey(), entry.getValue()[0], entry.getValue()[1]); - bFound = true; - } - if (!bFound) { - ProfileUIUtils.openEditorAndSelect(file.getPath(), 1); - } - } - // if we encounter an exception, act as though no corresponding source exists - } catch (NumberFormatException|BadLocationException|CoreException e) { - } - } + String binaryPath = dso.getPath(); + ICProject project; + project = ProfileUIUtils.findCProjectWithAbsolutePath(binaryPath); + Map<String, int[]> map = ProfileUIUtils.findFunctionsInProject(project, sym.getFunctionName(), -1, file.getPath(), true); + boolean bFound = false; + for (Map.Entry<String, int[]> entry : map.entrySet()) { + ProfileUIUtils.openEditorAndSelect(entry.getKey(), entry.getValue()[0], entry.getValue()[1]); + bFound = true; + } + if (!bFound) { + ProfileUIUtils.openEditorAndSelect(file.getPath(), 1); + } + } + // if we encounter an exception, act as though no corresponding source exists + } catch (NumberFormatException|BadLocationException|CoreException e) { + } + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfProfileView.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfProfileView.java index 4b3fd0a43c..22f789928a 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfProfileView.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfProfileView.java @@ -35,105 +35,105 @@ import org.eclipse.ui.part.ViewPart; public class PerfProfileView extends ViewPart { - /** - * The ID of the view as specified by the extension. - */ - public static final String ID = "org.eclipse.linuxtools.internal.perf.views.ProfileView"; //$NON-NLS-1$ - - private TreeViewer viewer; - private DrillDownAdapter drillDownAdapter; - private Action doubleClickAction; - - static class NameSorter extends ViewerSorter { - @Override - public int compare(Viewer viewer, Object e1, Object e2) { - return (((TreeParent) e1).getPercent() - <= ((TreeParent) e2).getPercent()) ? 1 : -1; - } - } - - /** - * This is a callback that will allow us - * to create the viewer and initialize it. - */ - @Override - public void createPartControl(Composite parent) { - viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - drillDownAdapter = new DrillDownAdapter(viewer); - viewer.setContentProvider(new PerfViewContentProvider()); - - viewer.setLabelProvider(new PerfViewLabelProvider()); - viewer.setSorter(new NameSorter()); - - // Create the help context id for the viewer's control - PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.eclipse.linuxtools.internal.perf.viewer"); //$NON-NLS-1$ - hookContextMenu(); - hookDoubleClickAction(); - contributeToActionBars(); - } - - public void refreshModel() { - viewer.setInput(PerfPlugin.getDefault().getModelRoot()); - viewer.refresh(); - } - - private void hookContextMenu() { - MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - @Override - public void menuAboutToShow(IMenuManager manager) { - PerfProfileView.this.fillContextMenu(manager); - } - }); - Menu menu = menuMgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, viewer); - } - - private void contributeToActionBars() { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } - - private void fillLocalPullDown(IMenuManager manager) { - } - - private void fillContextMenu(IMenuManager manager) { - drillDownAdapter.addNavigationActions(manager); - // Other plug-ins can contribute there actions here - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - private void fillLocalToolBar(IToolBarManager manager) { - drillDownAdapter.addNavigationActions(manager); - } - - private void hookDoubleClickAction() { - doubleClickAction = new PerfDoubleClickAction(viewer); - viewer.addDoubleClickListener(new IDoubleClickListener() { - @Override - public void doubleClick(DoubleClickEvent event) { - doubleClickAction.run(); - } - }); - } - - public TreeViewer getTreeViewer () { - return viewer; - } - - /** - * Passing the focus request to the viewer's control. - */ - @Override - public void setFocus() { - viewer.getControl().setFocus(); - } - - @Override - public void setContentDescription (String name) { - super.setContentDescription(name); - } + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "org.eclipse.linuxtools.internal.perf.views.ProfileView"; //$NON-NLS-1$ + + private TreeViewer viewer; + private DrillDownAdapter drillDownAdapter; + private Action doubleClickAction; + + static class NameSorter extends ViewerSorter { + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + return (((TreeParent) e1).getPercent() + <= ((TreeParent) e2).getPercent()) ? 1 : -1; + } + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + @Override + public void createPartControl(Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + drillDownAdapter = new DrillDownAdapter(viewer); + viewer.setContentProvider(new PerfViewContentProvider()); + + viewer.setLabelProvider(new PerfViewLabelProvider()); + viewer.setSorter(new NameSorter()); + + // Create the help context id for the viewer's control + PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.eclipse.linuxtools.internal.perf.viewer"); //$NON-NLS-1$ + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + } + + public void refreshModel() { + viewer.setInput(PerfPlugin.getDefault().getModelRoot()); + viewer.refresh(); + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + @Override + public void menuAboutToShow(IMenuManager manager) { + PerfProfileView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { + } + + private void fillContextMenu(IMenuManager manager) { + drillDownAdapter.addNavigationActions(manager); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void fillLocalToolBar(IToolBarManager manager) { + drillDownAdapter.addNavigationActions(manager); + } + + private void hookDoubleClickAction() { + doubleClickAction = new PerfDoubleClickAction(viewer); + viewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent event) { + doubleClickAction.run(); + } + }); + } + + public TreeViewer getTreeViewer () { + return viewer; + } + + /** + * Passing the focus request to the viewer's control. + */ + @Override + public void setFocus() { + viewer.getControl().setFocus(); + } + + @Override + public void setContentDescription (String name) { + super.setContentDescription(name); + } }
\ No newline at end of file diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewContentProvider.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewContentProvider.java index 97016c0efc..6d86fac214 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewContentProvider.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewContentProvider.java @@ -15,40 +15,40 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.linuxtools.internal.perf.model.TreeParent; public class PerfViewContentProvider implements ITreeContentProvider { - - @Override - public void inputChanged(Viewer v, Object oldInput, Object newInput) { - } - - @Override - public void dispose() { - } - - @Override - public Object[] getElements(Object parent) { - return getChildren(parent); - } - - @Override - public Object getParent(Object child) { - if (child instanceof TreeParent) { - return ((TreeParent) child).getParent(); - } - return null; - } - - @Override - public Object[] getChildren(Object parent) { - if (parent instanceof TreeParent) { - return ((TreeParent) parent).getChildren(); - } - return new Object[0]; - } - - @Override - public boolean hasChildren(Object parent) { - if (parent instanceof TreeParent) - return ((TreeParent) parent).hasChildren(); - return false; - } + + @Override + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + @Override + public void dispose() { + } + + @Override + public Object[] getElements(Object parent) { + return getChildren(parent); + } + + @Override + public Object getParent(Object child) { + if (child instanceof TreeParent) { + return ((TreeParent) child).getParent(); + } + return null; + } + + @Override + public Object[] getChildren(Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent) parent).getChildren(); + } + return new Object[0]; + } + + @Override + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent) + return ((TreeParent) parent).hasChildren(); + return false; + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewLabelProvider.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewLabelProvider.java index fc1aaac166..0ad73a11ab 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewLabelProvider.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfViewLabelProvider.java @@ -24,36 +24,36 @@ import org.eclipse.ui.PlatformUI; public class PerfViewLabelProvider extends LabelProvider { - @Override - public String getText(Object obj) { - return obj.toString(); - } - @Override - public Image getImage(Object obj) { - String imageKey; + @Override + public String getText(Object obj) { + return obj.toString(); + } + @Override + public Image getImage(Object obj) { + String imageKey; - if (obj instanceof PMDso) { - imageKey = "icons/dso.gif"; //$NON-NLS-1$ - } else if (obj instanceof PMSymbol) { - imageKey = "icons/symbol.gif"; //$NON-NLS-1$ - if (((PMSymbol)obj).conflicted()) - return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); - } else if (obj instanceof PMLineRef) { - imageKey = "icons/line.gif"; //$NON-NLS-1$ - } else if (obj instanceof PMEvent) { - imageKey = "icons/event.gif"; //$NON-NLS-1$ - } else if (obj instanceof PMFile) { - imageKey = "icons/file.gif"; //$NON-NLS-1$ - if (((PMFile)obj).getName().equals(PerfPlugin.STRINGS_MultipleFilesForSymbol)) { - return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); - } - } else if (obj instanceof TreeParent) { - imageKey = ISharedImages.IMG_OBJ_FOLDER; - return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); - } else { - imageKey = ISharedImages.IMG_OBJ_ELEMENT; - return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); - } - return PerfPlugin.getImageDescriptor(imageKey).createImage(); - } + if (obj instanceof PMDso) { + imageKey = "icons/dso.gif"; //$NON-NLS-1$ + } else if (obj instanceof PMSymbol) { + imageKey = "icons/symbol.gif"; //$NON-NLS-1$ + if (((PMSymbol)obj).conflicted()) + return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); + } else if (obj instanceof PMLineRef) { + imageKey = "icons/line.gif"; //$NON-NLS-1$ + } else if (obj instanceof PMEvent) { + imageKey = "icons/event.gif"; //$NON-NLS-1$ + } else if (obj instanceof PMFile) { + imageKey = "icons/file.gif"; //$NON-NLS-1$ + if (((PMFile)obj).getName().equals(PerfPlugin.STRINGS_MultipleFilesForSymbol)) { + return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); + } + } else if (obj instanceof TreeParent) { + imageKey = ISharedImages.IMG_OBJ_FOLDER; + return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); + } else { + imageKey = ISharedImages.IMG_OBJ_ELEMENT; + return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); + } + return PerfPlugin.getImageDescriptor(imageKey).createImage(); + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonView.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonView.java index 8c3e2b37eb..f6b46db492 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonView.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonView.java @@ -55,200 +55,200 @@ import org.eclipse.ui.PlatformUI; */ public class ReportComparisonView extends Viewer { - // Color values constants - private static final Color BLACK = new Color(Display.getDefault(), 0, 0, 0); - private static final Color RED = new Color(Display.getDefault(), 150, 0, 0); - private static final Color GREEN = new Color(Display.getDefault(), 0, 50, 0); - private static final Color LIGHT_GREEN = new Color(Display.getDefault(), 0, 105, 0); - private static final Color ORANGE = new Color(Display.getDefault(), 150, 100, 0); - - // Regex for a generic entry in a perf comparison report. - private static final String DIFF_ENTRY = "\\s+(\\d+(\\.\\d+)?)\\%\\s+([\\+\\-]?\\d+(\\.\\d+)?)\\%.*"; //$NON-NLS-1$ - - private Composite fComposite; - private ICompareInput fInput; - - // Comparison result. - private StyledText result; - private Label reverseLabel; - private boolean reverse; - - public ReportComparisonView (Composite parent, CompareConfiguration config) { - fComposite = new Composite (parent, SWT.NONE); - fComposite.setLayout(new GridLayout(2, false)); - fComposite.setData(CompareUI.COMPARE_VIEWER_TITLE, Messages.ReportComparisonView_label); - - reverseLabel = new Label(fComposite, SWT.NONE); - reverseLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); - reverseLabel.setText(Messages.StatComparisonView_reversedLabel); - reverseLabel.setVisible(false); - - final Button reverse = new Button(fComposite, SWT.TOGGLE); - reverse.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED)); - reverse.setToolTipText(Messages.StatComparisonView_reverseToolTip); - reverse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - reverse.addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - toggleReverse(); - setInput(fInput); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - result = new StyledText(fComposite, SWT.V_SCROLL | SWT.H_SCROLL); - result.setAlwaysShowScrollBars(false); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gd.horizontalSpan = 2; - result.setLayoutData(gd); - result.setEditable(false); - } - - /** - * Set properties for StlyedText widget. - * @param input String StyledText content. - */ - private void setStyledText(String input) { - result.setText(input); - result.setJustify(true); - result.setAlignment(SWT.LEFT); - - result.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); - - List<StyleRange> styles = new ArrayList<>(); - int ptr = 0; - String[] lines = input.split("\n"); //$NON-NLS-1$ - - for(String line : lines){ - if (Pattern.matches(DIFF_ENTRY, line)) { - Matcher m = Pattern.compile(DIFF_ENTRY).matcher(line); - if (m.matches() && m.group(1) != null && m.group(3) != null) { - try { - float baseline = Float.parseFloat(m.group(1).trim()); - float delta = Float.parseFloat(m.group(3).trim()); - if (baseline > 1 && Math.abs(delta) > 1) { - StyleRange curStyleRange = new StyleRange(ptr, line.length(), BLACK, null); - if (delta < 0 ) { - curStyleRange = delta < -5 ? new StyleRange(ptr, line.length(), LIGHT_GREEN, null) : - new StyleRange(ptr, line.length(), GREEN, null); - } else { - curStyleRange = delta < 5 ? new StyleRange(ptr, line .length(), ORANGE, null) : - new StyleRange(ptr, line.length(), RED, null); - } - styles.add(curStyleRange); - } - } catch (NumberFormatException e) { - // set no StyleRange - } - } - } - // + 1 to skip over the '\n' at EOL that the tokenizer eats - ptr += line.length() + 1; - } - - result.setStyleRanges(styles.toArray(new StyleRange[0])); - } - - @Override - public Control getControl() { - return fComposite; - } - - @Override - public Object getInput() { - return fInput; - } - - @Override - public ISelection getSelection() { - return null; - } - - @Override - public void refresh() { - } - - @Override - public void setInput(Object input) { - if (input instanceof ICompareInput) { - fInput = (ICompareInput) input; - - if (fInput.getAncestor() != null || - (fInput.getKind() & Differencer.DIRECTION_MASK) != 0) { - setStyledText(Messages.CompUnsupported); - } else { - // get corresponding files - IPath oldDatum; - IPath newDatum; - IProject proj = null; - - if (fInput.getLeft() instanceof ResourceNode) { - ResourceNode left = (ResourceNode) fInput.getLeft(); - IResource oldData = left.getResource(); - oldDatum = oldData.getLocation(); - proj = oldData.getProject(); - } else { - IEncodedStreamContentAccessor lStream = (IEncodedStreamContentAccessor) fInput.getLeft(); - oldDatum = generateTempFile(lStream); - } - - if (fInput.getRight() instanceof ResourceNode) { - ResourceNode right = (ResourceNode) fInput.getRight(); - IResource newData = right.getResource(); - newDatum = newData.getLocation(); - proj = newData.getProject(); - } else { - IEncodedStreamContentAccessor rStream = (IEncodedStreamContentAccessor) fInput.getRight(); - newDatum = generateTempFile(rStream); - } - - String title = MessageFormat.format(Messages.ContentDescription_0, - new Object[] { oldDatum.toFile().getName(), newDatum.toFile().getName() }); - - // create comparison data and run comparison. - ReportComparisonData diffData; - if (reverse) { - diffData = new ReportComparisonData(title, oldDatum, newDatum, proj); - } else { - diffData = new ReportComparisonData(title, newDatum, oldDatum, proj); - } - diffData.parse(); - - setStyledText(diffData.getPerfData()); - } - } - - fComposite.layout(); - } - - @Override - public void setSelection(ISelection selection, boolean reveal) { - } - - private IPath generateTempFile(IEncodedStreamContentAccessor stream) { - try { - Path tmpFile = Files.createTempFile("perf-report-", ".data"); //$NON-NLS-1$ //$NON-NLS-2$ - tmpFile.toFile().delete(); - Files.copy(stream.getContents(), tmpFile); - return new org.eclipse.core.runtime.Path(tmpFile.toString()); - } catch (IOException e) { - return null; - } catch (CoreException e) { - return null; - } - } - - private void toggleReverse () { - if (reverse) { - reverse = false; - reverseLabel.setVisible(false); - } else { - reverse = true; - reverseLabel.setVisible(true); - } - } + // Color values constants + private static final Color BLACK = new Color(Display.getDefault(), 0, 0, 0); + private static final Color RED = new Color(Display.getDefault(), 150, 0, 0); + private static final Color GREEN = new Color(Display.getDefault(), 0, 50, 0); + private static final Color LIGHT_GREEN = new Color(Display.getDefault(), 0, 105, 0); + private static final Color ORANGE = new Color(Display.getDefault(), 150, 100, 0); + + // Regex for a generic entry in a perf comparison report. + private static final String DIFF_ENTRY = "\\s+(\\d+(\\.\\d+)?)\\%\\s+([\\+\\-]?\\d+(\\.\\d+)?)\\%.*"; //$NON-NLS-1$ + + private Composite fComposite; + private ICompareInput fInput; + + // Comparison result. + private StyledText result; + private Label reverseLabel; + private boolean reverse; + + public ReportComparisonView (Composite parent, CompareConfiguration config) { + fComposite = new Composite (parent, SWT.NONE); + fComposite.setLayout(new GridLayout(2, false)); + fComposite.setData(CompareUI.COMPARE_VIEWER_TITLE, Messages.ReportComparisonView_label); + + reverseLabel = new Label(fComposite, SWT.NONE); + reverseLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); + reverseLabel.setText(Messages.StatComparisonView_reversedLabel); + reverseLabel.setVisible(false); + + final Button reverse = new Button(fComposite, SWT.TOGGLE); + reverse.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED)); + reverse.setToolTipText(Messages.StatComparisonView_reverseToolTip); + reverse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + reverse.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + toggleReverse(); + setInput(fInput); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + result = new StyledText(fComposite, SWT.V_SCROLL | SWT.H_SCROLL); + result.setAlwaysShowScrollBars(false); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.horizontalSpan = 2; + result.setLayoutData(gd); + result.setEditable(false); + } + + /** + * Set properties for StlyedText widget. + * @param input String StyledText content. + */ + private void setStyledText(String input) { + result.setText(input); + result.setJustify(true); + result.setAlignment(SWT.LEFT); + + result.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); + + List<StyleRange> styles = new ArrayList<>(); + int ptr = 0; + String[] lines = input.split("\n"); //$NON-NLS-1$ + + for(String line : lines){ + if (Pattern.matches(DIFF_ENTRY, line)) { + Matcher m = Pattern.compile(DIFF_ENTRY).matcher(line); + if (m.matches() && m.group(1) != null && m.group(3) != null) { + try { + float baseline = Float.parseFloat(m.group(1).trim()); + float delta = Float.parseFloat(m.group(3).trim()); + if (baseline > 1 && Math.abs(delta) > 1) { + StyleRange curStyleRange = new StyleRange(ptr, line.length(), BLACK, null); + if (delta < 0 ) { + curStyleRange = delta < -5 ? new StyleRange(ptr, line.length(), LIGHT_GREEN, null) : + new StyleRange(ptr, line.length(), GREEN, null); + } else { + curStyleRange = delta < 5 ? new StyleRange(ptr, line .length(), ORANGE, null) : + new StyleRange(ptr, line.length(), RED, null); + } + styles.add(curStyleRange); + } + } catch (NumberFormatException e) { + // set no StyleRange + } + } + } + // + 1 to skip over the '\n' at EOL that the tokenizer eats + ptr += line.length() + 1; + } + + result.setStyleRanges(styles.toArray(new StyleRange[0])); + } + + @Override + public Control getControl() { + return fComposite; + } + + @Override + public Object getInput() { + return fInput; + } + + @Override + public ISelection getSelection() { + return null; + } + + @Override + public void refresh() { + } + + @Override + public void setInput(Object input) { + if (input instanceof ICompareInput) { + fInput = (ICompareInput) input; + + if (fInput.getAncestor() != null || + (fInput.getKind() & Differencer.DIRECTION_MASK) != 0) { + setStyledText(Messages.CompUnsupported); + } else { + // get corresponding files + IPath oldDatum; + IPath newDatum; + IProject proj = null; + + if (fInput.getLeft() instanceof ResourceNode) { + ResourceNode left = (ResourceNode) fInput.getLeft(); + IResource oldData = left.getResource(); + oldDatum = oldData.getLocation(); + proj = oldData.getProject(); + } else { + IEncodedStreamContentAccessor lStream = (IEncodedStreamContentAccessor) fInput.getLeft(); + oldDatum = generateTempFile(lStream); + } + + if (fInput.getRight() instanceof ResourceNode) { + ResourceNode right = (ResourceNode) fInput.getRight(); + IResource newData = right.getResource(); + newDatum = newData.getLocation(); + proj = newData.getProject(); + } else { + IEncodedStreamContentAccessor rStream = (IEncodedStreamContentAccessor) fInput.getRight(); + newDatum = generateTempFile(rStream); + } + + String title = MessageFormat.format(Messages.ContentDescription_0, + new Object[] { oldDatum.toFile().getName(), newDatum.toFile().getName() }); + + // create comparison data and run comparison. + ReportComparisonData diffData; + if (reverse) { + diffData = new ReportComparisonData(title, oldDatum, newDatum, proj); + } else { + diffData = new ReportComparisonData(title, newDatum, oldDatum, proj); + } + diffData.parse(); + + setStyledText(diffData.getPerfData()); + } + } + + fComposite.layout(); + } + + @Override + public void setSelection(ISelection selection, boolean reveal) { + } + + private IPath generateTempFile(IEncodedStreamContentAccessor stream) { + try { + Path tmpFile = Files.createTempFile("perf-report-", ".data"); //$NON-NLS-1$ //$NON-NLS-2$ + tmpFile.toFile().delete(); + Files.copy(stream.getContents(), tmpFile); + return new org.eclipse.core.runtime.Path(tmpFile.toString()); + } catch (IOException e) { + return null; + } catch (CoreException e) { + return null; + } + } + + private void toggleReverse () { + if (reverse) { + reverse = false; + reverseLabel.setVisible(false); + } else { + reverse = true; + reverseLabel.setVisible(true); + } + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonViewCreator.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonViewCreator.java index 905f3383ea..a6f7a19bef 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonViewCreator.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/ReportComparisonViewCreator.java @@ -17,9 +17,9 @@ import org.eclipse.swt.widgets.Composite; public class ReportComparisonViewCreator implements IViewerCreator { - @Override - public Viewer createViewer(Composite parent, CompareConfiguration config) { - return new ReportComparisonView(parent, config); - } + @Override + public Viewer createViewer(Composite parent, CompareConfiguration config) { + return new ReportComparisonView(parent, config); + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java index 37e8104386..641ef5384b 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java @@ -43,193 +43,193 @@ import org.eclipse.ui.texteditor.FindReplaceAction; */ public class SourceDisassemblyView extends ViewPart implements IFindReplaceTarget{ - private static final Color RED = new Color(Display.getDefault(), 150, 0, 0); - private static final Color ORANGE = new Color(Display.getDefault(), 150, 100, 0); - private static final Color GREEN = new Color(Display.getDefault(), 0, 100, 0); - private static String ASM = "\\s+([0-9]+\\.[0-9]+ )?:\\s+[0-9a-f]+:\\s+[0-9a-z]+\\s+.*"; //$NON-NLS-1$ - private static String CODE = "\\s+:\\s+.*"; //$NON-NLS-1$ - private static String WORD_BOUNDARY = "\\b"; //$NON-NLS-1$' - private static int SECONDARY_ID = 0; - private StyledText text; - public SourceDisassemblyView() { - } - - @Override - public void createPartControl(Composite parent) { - parent.setLayoutData(new GridLayout(1, true)); - - text = new StyledText(parent, SWT.WRAP | SWT.V_SCROLL); - text.setEditable(false); - - IPerfData data = PerfPlugin.getDefault().getSourceDisassemblyData(); - if (data != null) { - setStyledText(data.getPerfData()); - setContentDescription(data.getTitle()); - setupFindDialog(); - } - } - - @Override - public void setFocus() { - return; - } - - /** - * Set styled text field (only used for testing). - * - * @param txt StyledText to set. - */ - protected void setStyledText(StyledText txt) { - text = txt; - } - - /** - * Get the text content of this view. - * - * @return String content of this view - */ - public String getContent() { - return (text == null) ? "" : text.getText(); //$NON-NLS-1$ - } - - /** - * Set styled text field based on the specified string, which is parsed in - * order to set appropriate styles to be used for rendering the widget - * content. - * - * @param input text content of widget. - */ - private void setStyledText (String input) { - List<StyleRange> styles = new ArrayList<> (); - int ptr = 0; - - text.setText(input); - - StringTokenizer tok = new StringTokenizer(input, "\n"); //$NON-NLS-1$ - while (tok.hasMoreTokens()) { - String line = tok.nextToken(); - if (Pattern.matches(ASM, line)) { - Matcher m = Pattern.compile(ASM).matcher(line); - if (m.matches() && m.group(1) != null) { - - try { - float percent = Float.parseFloat(m.group(1).trim()); - if (percent >= 20) { - styles.add(new StyleRange(ptr, line.length(), RED, null)); - } else if (percent >= 5) { - styles.add(new StyleRange(ptr, line.length(), ORANGE, null)); - } - } catch (NumberFormatException e) { - // set no StyleRange - } - } - } else if (Pattern.matches(CODE, line)) { - styles.add(new StyleRange(ptr, line.length(), GREEN, null)); - } - - // + 1 to skip over the '\n' at EOL that the tokenizer eats - ptr += line.length() + 1; - } - text.setStyleRanges(styles.toArray(new StyleRange [0])); - } - - public static void refreshView () { - Display.getDefault().syncExec(new Runnable() { - - @Override - public void run() { - try { - // A new view is created every time - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .showView(PerfPlugin.SOURCE_DISASSEMBLY_VIEW_ID, - Integer.toString(SECONDARY_ID++), - IWorkbenchPage.VIEW_CREATE); - } catch (PartInitException e) { - IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, e.getMessage(), e); - PerfPlugin.getDefault().getLog().log(status); - } - } - }); - } - - /** - * Create find dialog and set is as a toolbar action. - */ - private void setupFindDialog() { - FindReplaceAction findAction = new FindReplaceAction( - Platform.getResourceBundle(PerfPlugin.getDefault().getBundle()), - null, text.getShell(), this); - findAction.setImageDescriptor(PerfPlugin - .getImageDescriptor("icons/search.gif"));//$NON-NLS-1$ - findAction.setToolTipText(PerfPlugin.STRINGS_SearchSourceDisassembly); - IActionBars bars = getViewSite().getActionBars(); - bars.getToolBarManager().add(findAction); - bars.setGlobalActionHandler(ActionFactory.FIND.getId(), findAction); - } - - @Override - public boolean canPerformFind() { - return text != null && !text.getText().isEmpty(); - } - - @Override - public int findAndSelect(int widgetOffset, String findString, - boolean searchForward, boolean caseSensitive, boolean wholeWord) { - int matchIndex = -1; - String searchString = text.getText(); - String findRegex = findString; - - // offset is -1 when text boundaries are reached during a wrapped search - if (widgetOffset < 0) { - widgetOffset = searchForward ? 0 : searchString.length(); - } - - if (wholeWord) { - findRegex = WORD_BOUNDARY + findRegex + WORD_BOUNDARY; - } - - int caseFlag = caseSensitive ? 0 : Pattern.CASE_INSENSITIVE; - Pattern pattern = Pattern.compile(findRegex, caseFlag); - Matcher matcher = pattern.matcher(searchString); - - if (searchForward) { - matchIndex = matcher.find(widgetOffset) ? matcher.start() : -1; - } else { - // backward search from 0 to offset (exclusive) - matcher.region(0, widgetOffset); - - // get start index of last match - while (matcher.find()) { - matchIndex = matcher.start(); - } - } - - // only select when a match has been found - if (matchIndex != -1) { - text.setSelection(matchIndex, matchIndex + findString.length()); - } - return matchIndex; - } - - @Override - public Point getSelection() { - Point selection = text.getSelection(); - // selection point consists of starting point x and lenght y - x. - return new Point(selection.x, selection.y - selection.x); - } - - @Override - public String getSelectionText() { - return text.getSelectionText(); - } - - @Override - public boolean isEditable() { - return false; - } - - @Override - public void replaceSelection(String text) { - } + private static final Color RED = new Color(Display.getDefault(), 150, 0, 0); + private static final Color ORANGE = new Color(Display.getDefault(), 150, 100, 0); + private static final Color GREEN = new Color(Display.getDefault(), 0, 100, 0); + private static String ASM = "\\s+([0-9]+\\.[0-9]+ )?:\\s+[0-9a-f]+:\\s+[0-9a-z]+\\s+.*"; //$NON-NLS-1$ + private static String CODE = "\\s+:\\s+.*"; //$NON-NLS-1$ + private static String WORD_BOUNDARY = "\\b"; //$NON-NLS-1$' + private static int SECONDARY_ID = 0; + private StyledText text; + public SourceDisassemblyView() { + } + + @Override + public void createPartControl(Composite parent) { + parent.setLayoutData(new GridLayout(1, true)); + + text = new StyledText(parent, SWT.WRAP | SWT.V_SCROLL); + text.setEditable(false); + + IPerfData data = PerfPlugin.getDefault().getSourceDisassemblyData(); + if (data != null) { + setStyledText(data.getPerfData()); + setContentDescription(data.getTitle()); + setupFindDialog(); + } + } + + @Override + public void setFocus() { + return; + } + + /** + * Set styled text field (only used for testing). + * + * @param txt StyledText to set. + */ + protected void setStyledText(StyledText txt) { + text = txt; + } + + /** + * Get the text content of this view. + * + * @return String content of this view + */ + public String getContent() { + return (text == null) ? "" : text.getText(); //$NON-NLS-1$ + } + + /** + * Set styled text field based on the specified string, which is parsed in + * order to set appropriate styles to be used for rendering the widget + * content. + * + * @param input text content of widget. + */ + private void setStyledText (String input) { + List<StyleRange> styles = new ArrayList<> (); + int ptr = 0; + + text.setText(input); + + StringTokenizer tok = new StringTokenizer(input, "\n"); //$NON-NLS-1$ + while (tok.hasMoreTokens()) { + String line = tok.nextToken(); + if (Pattern.matches(ASM, line)) { + Matcher m = Pattern.compile(ASM).matcher(line); + if (m.matches() && m.group(1) != null) { + + try { + float percent = Float.parseFloat(m.group(1).trim()); + if (percent >= 20) { + styles.add(new StyleRange(ptr, line.length(), RED, null)); + } else if (percent >= 5) { + styles.add(new StyleRange(ptr, line.length(), ORANGE, null)); + } + } catch (NumberFormatException e) { + // set no StyleRange + } + } + } else if (Pattern.matches(CODE, line)) { + styles.add(new StyleRange(ptr, line.length(), GREEN, null)); + } + + // + 1 to skip over the '\n' at EOL that the tokenizer eats + ptr += line.length() + 1; + } + text.setStyleRanges(styles.toArray(new StyleRange [0])); + } + + public static void refreshView () { + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + try { + // A new view is created every time + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + .showView(PerfPlugin.SOURCE_DISASSEMBLY_VIEW_ID, + Integer.toString(SECONDARY_ID++), + IWorkbenchPage.VIEW_CREATE); + } catch (PartInitException e) { + IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, e.getMessage(), e); + PerfPlugin.getDefault().getLog().log(status); + } + } + }); + } + + /** + * Create find dialog and set is as a toolbar action. + */ + private void setupFindDialog() { + FindReplaceAction findAction = new FindReplaceAction( + Platform.getResourceBundle(PerfPlugin.getDefault().getBundle()), + null, text.getShell(), this); + findAction.setImageDescriptor(PerfPlugin + .getImageDescriptor("icons/search.gif"));//$NON-NLS-1$ + findAction.setToolTipText(PerfPlugin.STRINGS_SearchSourceDisassembly); + IActionBars bars = getViewSite().getActionBars(); + bars.getToolBarManager().add(findAction); + bars.setGlobalActionHandler(ActionFactory.FIND.getId(), findAction); + } + + @Override + public boolean canPerformFind() { + return text != null && !text.getText().isEmpty(); + } + + @Override + public int findAndSelect(int widgetOffset, String findString, + boolean searchForward, boolean caseSensitive, boolean wholeWord) { + int matchIndex = -1; + String searchString = text.getText(); + String findRegex = findString; + + // offset is -1 when text boundaries are reached during a wrapped search + if (widgetOffset < 0) { + widgetOffset = searchForward ? 0 : searchString.length(); + } + + if (wholeWord) { + findRegex = WORD_BOUNDARY + findRegex + WORD_BOUNDARY; + } + + int caseFlag = caseSensitive ? 0 : Pattern.CASE_INSENSITIVE; + Pattern pattern = Pattern.compile(findRegex, caseFlag); + Matcher matcher = pattern.matcher(searchString); + + if (searchForward) { + matchIndex = matcher.find(widgetOffset) ? matcher.start() : -1; + } else { + // backward search from 0 to offset (exclusive) + matcher.region(0, widgetOffset); + + // get start index of last match + while (matcher.find()) { + matchIndex = matcher.start(); + } + } + + // only select when a match has been found + if (matchIndex != -1) { + text.setSelection(matchIndex, matchIndex + findString.length()); + } + return matchIndex; + } + + @Override + public Point getSelection() { + Point selection = text.getSelection(); + // selection point consists of starting point x and lenght y - x. + return new Point(selection.x, selection.y - selection.x); + } + + @Override + public String getSelectionText() { + return text.getSelectionText(); + } + + @Override + public boolean isEditable() { + return false; + } + + @Override + public void replaceSelection(String text) { + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonView.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonView.java index 0d0ec1591c..6b1bb089ab 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonView.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonView.java @@ -55,202 +55,202 @@ import org.eclipse.ui.PlatformUI; */ public class StatComparisonView extends Viewer { - // color values constasts - private static final Color RED = new Color(Display.getDefault(), 150, 0, 0); - private static final Color GREEN = new Color(Display.getDefault(), 0, 100, 0); - - // event occurrence reg-ex - private static String OCCURRENCE = "\\s*(\\-?+" //$NON-NLS-1$ - + PMStatEntry.DECIMAL + ").*"; //$NON-NLS-1$ - - private Composite fComposite; - private ICompareInput fInput; - private StyledText text; - private Label reverseLabel; - private boolean reverse; - - public StatComparisonView(Composite parent, CompareConfiguration config) { - fComposite = new Composite(parent, SWT.NONE); - fComposite.setLayout(new GridLayout(2, false)); - fComposite.setData(CompareUI.COMPARE_VIEWER_TITLE, Messages.StatComparisonView_label); - - reverseLabel = new Label(fComposite, SWT.NONE); - reverseLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); - reverseLabel.setText(Messages.StatComparisonView_reversedLabel); - reverseLabel.setVisible(false); - - final Button reverse = new Button(fComposite, SWT.TOGGLE); - reverse.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED)); - reverse.setToolTipText(Messages.StatComparisonView_reverseToolTip); - reverse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - reverse.addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - toggleReverse(); - setInput(fInput); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - text = new StyledText(fComposite, SWT.V_SCROLL | SWT.H_SCROLL); - text.setAlwaysShowScrollBars(false); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gd.horizontalSpan = 2; - text.setLayoutData(gd); - text.setEditable(false); - - } - - /** - * Set String input in text display. Adapted from - * org.eclipse.linuxtools.internal.perf.ui.SourceDisassemblyView. - * - * @param input text to display - */ - private void setStyledText(String input) { - text.setText(input); - text.setAlignment(SWT.LEFT); - // set default TextConsole font (monospaced). - text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); - - List<StyleRange> styles = new ArrayList<>(); - int ptr = 0; - - String[] lines = input.split("\n"); //$NON-NLS-1$ - - for (String line : lines) { - if (Pattern.matches(OCCURRENCE, line)) { - Matcher m = Pattern.compile(OCCURRENCE).matcher(line); - if (m.matches() && m.group(1) != null) { - try { - float occurrence = StatComparisonData.toFloat(m - .group(1).trim()); - if (occurrence > 0) { - styles.add(new StyleRange(ptr, line.length(), RED, - null)); - } else if (occurrence < 0) { - styles.add(new StyleRange(ptr, line.length(), - GREEN, null)); - } - } catch (NumberFormatException e) { - // set no StyleRange - } - } - } - // + 1 to skip over the '\n' at EOL that the tokenizer eats - ptr += line.length() + 1; - } - - text.setStyleRanges(styles.toArray(new StyleRange[0])); - } - - /** - * Update contents of current view, replacing the containing data and text styling. - * - * @param data IPerfData data replacement. - */ - private void updateData(IPerfData data) { - if (data != null) { - setStyledText(data.getPerfData()); - } - } - - @Override - public Control getControl() { - return fComposite; - } - - @Override - public Object getInput() { - return fInput; - } - - @Override - public ISelection getSelection() { - return null; - } - - @Override - public void refresh() { - } - - @Override - public void setInput(Object input) { - if (input instanceof ICompareInput) { - fInput = (ICompareInput) input; - - if (fInput.getAncestor() != null || - (fInput.getKind() & Differencer.DIRECTION_MASK) != 0) { - setStyledText(Messages.CompUnsupported); - } else { - // get corresponding files - IPath oldDatum; - IPath newDatum; - - if (fInput.getLeft() instanceof ResourceNode) { - ResourceNode left = (ResourceNode) fInput.getLeft(); - oldDatum = left.getResource().getLocation(); - } else { - IEncodedStreamContentAccessor lStream = (IEncodedStreamContentAccessor) fInput.getLeft(); - oldDatum = generateTempFile(lStream); - } - - if (fInput.getRight() instanceof ResourceNode) { - ResourceNode right = (ResourceNode) fInput.getRight(); - newDatum = right.getResource().getLocation(); - } else { - IEncodedStreamContentAccessor rStream = (IEncodedStreamContentAccessor) fInput.getRight(); - newDatum = generateTempFile(rStream); - } - - String title = MessageFormat.format(Messages.ContentDescription_0, - new Object[] { oldDatum.toFile().getName(), newDatum.toFile().getName() }); - - // create comparison data and run comparison. - StatComparisonData diffData; - if (reverse) { - diffData = new StatComparisonData(title, newDatum, oldDatum); - } else { - diffData = new StatComparisonData(title, oldDatum, newDatum); - } - diffData.runComparison(); - updateData(diffData); - } - - } - - fComposite.layout(); - } - - private IPath generateTempFile(IEncodedStreamContentAccessor stream) { - try { - Path tmpFile = Files.createTempFile("perf-stat-", ".stat"); //$NON-NLS-1$ //$NON-NLS-2$ - tmpFile.toFile().delete(); - Files.copy(stream.getContents(), tmpFile); - return new org.eclipse.core.runtime.Path(tmpFile.toString()); - } catch (IOException e) { - return null; - } catch (CoreException e) { - return null; - } - } - - @Override - public void setSelection(ISelection selection, boolean reveal) { - } - - private void toggleReverse () { - if (reverse) { - reverse = false; - reverseLabel.setVisible(false); - } else { - reverse = true; - reverseLabel.setVisible(true); - } - } + // color values constasts + private static final Color RED = new Color(Display.getDefault(), 150, 0, 0); + private static final Color GREEN = new Color(Display.getDefault(), 0, 100, 0); + + // event occurrence reg-ex + private static String OCCURRENCE = "\\s*(\\-?+" //$NON-NLS-1$ + + PMStatEntry.DECIMAL + ").*"; //$NON-NLS-1$ + + private Composite fComposite; + private ICompareInput fInput; + private StyledText text; + private Label reverseLabel; + private boolean reverse; + + public StatComparisonView(Composite parent, CompareConfiguration config) { + fComposite = new Composite(parent, SWT.NONE); + fComposite.setLayout(new GridLayout(2, false)); + fComposite.setData(CompareUI.COMPARE_VIEWER_TITLE, Messages.StatComparisonView_label); + + reverseLabel = new Label(fComposite, SWT.NONE); + reverseLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); + reverseLabel.setText(Messages.StatComparisonView_reversedLabel); + reverseLabel.setVisible(false); + + final Button reverse = new Button(fComposite, SWT.TOGGLE); + reverse.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_SYNCED)); + reverse.setToolTipText(Messages.StatComparisonView_reverseToolTip); + reverse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + reverse.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + toggleReverse(); + setInput(fInput); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + text = new StyledText(fComposite, SWT.V_SCROLL | SWT.H_SCROLL); + text.setAlwaysShowScrollBars(false); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.horizontalSpan = 2; + text.setLayoutData(gd); + text.setEditable(false); + + } + + /** + * Set String input in text display. Adapted from + * org.eclipse.linuxtools.internal.perf.ui.SourceDisassemblyView. + * + * @param input text to display + */ + private void setStyledText(String input) { + text.setText(input); + text.setAlignment(SWT.LEFT); + // set default TextConsole font (monospaced). + text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); + + List<StyleRange> styles = new ArrayList<>(); + int ptr = 0; + + String[] lines = input.split("\n"); //$NON-NLS-1$ + + for (String line : lines) { + if (Pattern.matches(OCCURRENCE, line)) { + Matcher m = Pattern.compile(OCCURRENCE).matcher(line); + if (m.matches() && m.group(1) != null) { + try { + float occurrence = StatComparisonData.toFloat(m + .group(1).trim()); + if (occurrence > 0) { + styles.add(new StyleRange(ptr, line.length(), RED, + null)); + } else if (occurrence < 0) { + styles.add(new StyleRange(ptr, line.length(), + GREEN, null)); + } + } catch (NumberFormatException e) { + // set no StyleRange + } + } + } + // + 1 to skip over the '\n' at EOL that the tokenizer eats + ptr += line.length() + 1; + } + + text.setStyleRanges(styles.toArray(new StyleRange[0])); + } + + /** + * Update contents of current view, replacing the containing data and text styling. + * + * @param data IPerfData data replacement. + */ + private void updateData(IPerfData data) { + if (data != null) { + setStyledText(data.getPerfData()); + } + } + + @Override + public Control getControl() { + return fComposite; + } + + @Override + public Object getInput() { + return fInput; + } + + @Override + public ISelection getSelection() { + return null; + } + + @Override + public void refresh() { + } + + @Override + public void setInput(Object input) { + if (input instanceof ICompareInput) { + fInput = (ICompareInput) input; + + if (fInput.getAncestor() != null || + (fInput.getKind() & Differencer.DIRECTION_MASK) != 0) { + setStyledText(Messages.CompUnsupported); + } else { + // get corresponding files + IPath oldDatum; + IPath newDatum; + + if (fInput.getLeft() instanceof ResourceNode) { + ResourceNode left = (ResourceNode) fInput.getLeft(); + oldDatum = left.getResource().getLocation(); + } else { + IEncodedStreamContentAccessor lStream = (IEncodedStreamContentAccessor) fInput.getLeft(); + oldDatum = generateTempFile(lStream); + } + + if (fInput.getRight() instanceof ResourceNode) { + ResourceNode right = (ResourceNode) fInput.getRight(); + newDatum = right.getResource().getLocation(); + } else { + IEncodedStreamContentAccessor rStream = (IEncodedStreamContentAccessor) fInput.getRight(); + newDatum = generateTempFile(rStream); + } + + String title = MessageFormat.format(Messages.ContentDescription_0, + new Object[] { oldDatum.toFile().getName(), newDatum.toFile().getName() }); + + // create comparison data and run comparison. + StatComparisonData diffData; + if (reverse) { + diffData = new StatComparisonData(title, newDatum, oldDatum); + } else { + diffData = new StatComparisonData(title, oldDatum, newDatum); + } + diffData.runComparison(); + updateData(diffData); + } + + } + + fComposite.layout(); + } + + private IPath generateTempFile(IEncodedStreamContentAccessor stream) { + try { + Path tmpFile = Files.createTempFile("perf-stat-", ".stat"); //$NON-NLS-1$ //$NON-NLS-2$ + tmpFile.toFile().delete(); + Files.copy(stream.getContents(), tmpFile); + return new org.eclipse.core.runtime.Path(tmpFile.toString()); + } catch (IOException e) { + return null; + } catch (CoreException e) { + return null; + } + } + + @Override + public void setSelection(ISelection selection, boolean reveal) { + } + + private void toggleReverse () { + if (reverse) { + reverse = false; + reverseLabel.setVisible(false); + } else { + reverse = true; + reverseLabel.setVisible(true); + } + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonViewCreator.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonViewCreator.java index 7170f4e77d..db2efdb36b 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonViewCreator.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonViewCreator.java @@ -17,8 +17,8 @@ import org.eclipse.swt.widgets.Composite; public class StatComparisonViewCreator implements IViewerCreator { - @Override - public Viewer createViewer(Composite parent, CompareConfiguration config) { - return new StatComparisonView(parent, config); - } + @Override + public Viewer createViewer(Composite parent, CompareConfiguration config) { + return new StatComparisonView(parent, config); + } } diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatView.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatView.java index 7275622cff..c28e142693 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatView.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatView.java @@ -29,66 +29,66 @@ import org.eclipse.ui.part.ViewPart; */ public class StatView extends ViewPart { - private StyledText text; + private StyledText text; - public StatView() { - } + public StatView() { + } - @Override - public void createPartControl(Composite parent) { - parent.setLayoutData(new GridLayout(1, true)); + @Override + public void createPartControl(Composite parent) { + parent.setLayoutData(new GridLayout(1, true)); - text = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL); - text.setEditable(false); + text = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL); + text.setEditable(false); - IPerfData data = PerfPlugin.getDefault().getStatData(); - if (data != null) { - setStyledText(data.getPerfData()); - setContentDescription(data.getTitle()); - } - } + IPerfData data = PerfPlugin.getDefault().getStatData(); + if (data != null) { + setStyledText(data.getPerfData()); + setContentDescription(data.getTitle()); + } + } - @Override - public void setFocus() { - return; - } + @Override + public void setFocus() { + return; + } - private void setStyledText (String input) { - text.setText(input); + private void setStyledText (String input) { + text.setText(input); - // the default TextConsole font (we want monospaced) - text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); - } - /** - * Update to most recent statistics data. - */ - private void updateData(){ - IPerfData data = PerfPlugin.getDefault().getStatData(); - if (data != null) { - setStyledText(data.getPerfData()); - setContentDescription(data.getTitle()); - } - } + // the default TextConsole font (we want monospaced) + text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); + } + /** + * Update to most recent statistics data. + */ + private void updateData(){ + IPerfData data = PerfPlugin.getDefault().getStatData(); + if (data != null) { + setStyledText(data.getPerfData()); + setContentDescription(data.getTitle()); + } + } - /** - * Refresh perf statistics view. - */ - public static void refreshView () { - Display.getDefault().syncExec(new Runnable() { + /** + * Refresh perf statistics view. + */ + public static void refreshView () { + Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - try { - // A new view is created every time - StatView view = (StatView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .showView(PerfPlugin.STAT_VIEW_ID); - view.updateData(); - } catch (PartInitException e) { - IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, e.getMessage(), e); - PerfPlugin.getDefault().getLog().log(status); - } - } - }); - } + @Override + public void run() { + try { + // A new view is created every time + StatView view = (StatView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + .showView(PerfPlugin.STAT_VIEW_ID); + view.updateData(); + } catch (PartInitException e) { + IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, e.getMessage(), e); + PerfPlugin.getDefault().getLog().log(status); + } + } + }); + } } |