aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-04-05 16:48:14 (EDT)
committerRoland Grunberg2013-04-30 14:33:33 (EDT)
commitd43ed1956e29c71c6d6572b3ad64f310cd84a5ec (patch)
tree6c5314afbbc64bcbcf0f60f24c91d902372d6679
parentb398d7d91d681599b30157c13f0423f353efa7fe (diff)
downloadorg.eclipse.linuxtools-d43ed1956e29c71c6d6572b3ad64f310cd84a5ec.zip
org.eclipse.linuxtools-d43ed1956e29c71c6d6572b3ad64f310cd84a5ec.tar.gz
org.eclipse.linuxtools-d43ed1956e29c71c6d6572b3ad64f310cd84a5ec.tar.bz2
Perf: Support text search for disassembly view.refs/changes/46/12346/3
Change-Id: Id5ef2b74ce591b4f2263866653feff1a0b663545 Reviewed-on: https://git.eclipse.org/r/12346 Tested-by: Hudson CI IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com> Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--perf/org.eclipse.linuxtools.perf/icons/search.gifbin0 -> 347 bytes
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java1
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/SourceDisassemblyView.java90
3 files changed, 89 insertions, 2 deletions
diff --git a/perf/org.eclipse.linuxtools.perf/icons/search.gif b/perf/org.eclipse.linuxtools.perf/icons/search.gif
new file mode 100644
index 0000000..d540a01
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/icons/search.gif
Binary files differ
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java
index 0dc03a9..2cf42fd 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java
@@ -100,6 +100,7 @@ public class PerfPlugin extends AbstractUIPlugin {
public static final String STRINGS_MultipleFilesForSymbol = "Symbols conflicting in multiple files";
public static final String STRINGS_ShowSourceDisassembly = "Show Source Disassembly View";
public static final String STRINGS_ShowStat = "Show Stat View";
+ public static final String STRINGS_SearchSourceDisassembly = "Search Source Disassembly";
public static final String PERF_COMMAND = "perf";
public static final String PERF_DEFAULT_DATA = "perf.data";
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 906cc3c..073fabc 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
@@ -17,34 +17,39 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.SourceDisassemblyData;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.texteditor.FindReplaceAction;
/**
* A ViewPart to display the output from perf's source disassembly.
*/
-public class SourceDisassemblyView extends ViewPart {
+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 StyledText text;
private static int SECONDARY_ID = 0;
-
public SourceDisassemblyView() {
}
@@ -59,6 +64,7 @@ public class SourceDisassemblyView extends ViewPart {
if (data != null) {
setStyledText(data.getPerfData());
setContentDescription(data.getTitle());
+ setupFindDialog();
}
}
@@ -79,6 +85,7 @@ public class SourceDisassemblyView extends ViewPart {
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) {
@@ -119,4 +126,83 @@ public class SourceDisassemblyView extends ViewPart {
});
}
+ /**
+ * Create find dialog and set is as a toolbar action.
+ */
+ public 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);
+ }
+
+ @Override
+ public boolean canPerformFind() {
+ return text != null && !"".equals(text.getText());
+ }
+
+ @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) {
+ }
+
}