aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-06-04 18:23:49 (EDT)
committerRoland Grunberg2013-06-06 14:33:51 (EDT)
commit04b4d62990bfda9b07542a3ee247fef8ec71b774 (patch)
tree1973427a3fd94a09922f7f1e053a5e93596d8a7e
parentd9ea851aec593e1c39ff456e00407b6ca11ab325 (diff)
downloadorg.eclipse.linuxtools-04b4d62990bfda9b07542a3ee247fef8ec71b774.zip
org.eclipse.linuxtools-04b4d62990bfda9b07542a3ee247fef8ec71b774.tar.gz
org.eclipse.linuxtools-04b4d62990bfda9b07542a3ee247fef8ec71b774.tar.bz2
Perf: Open stat data files in stat viewrefs/changes/95/13595/3
Add editor launch handler for perf stat data files. Change-Id: Id567fed6753b26b3138448a3197db96d6053c4fb Reviewed-on: https://git.eclipse.org/r/13595 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--perf/org.eclipse.linuxtools.perf/plugin.xml7
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/Messages.java5
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDataOpenHandler.java88
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/messages.properties6
4 files changed, 105 insertions, 1 deletions
diff --git a/perf/org.eclipse.linuxtools.perf/plugin.xml b/perf/org.eclipse.linuxtools.perf/plugin.xml
index 6808f0b..8c19d9f 100644
--- a/perf/org.eclipse.linuxtools.perf/plugin.xml
+++ b/perf/org.eclipse.linuxtools.perf/plugin.xml
@@ -164,6 +164,13 @@
launcher="org.eclipse.linuxtools.internal.perf.launch.PerfOpenData"
name="Perf Viewer">
</editor>
+ <editor
+ default="true"
+ filenames="*.stat"
+ id="org.eclipse.linuxtools.perf.stat.launch"
+ launcher="org.eclipse.linuxtools.internal.perf.handlers.PerfStatDataOpenHandler"
+ name="Perf Statistics">
+ </editor>
</extension>
<extension
point="org.eclipse.linuxtools.profiling.launch.launchProvider">
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/Messages.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/Messages.java
index e5e6d23..714a055 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/Messages.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/Messages.java
@@ -39,6 +39,11 @@ public class Messages extends NLS {
public static String MsgConfirm_title;
public static String MsgConfirm_msg;
public static String ContentDescription_0;
+
+ public static String PerfEditorLauncher_stat_title;
+ public static String PerfEditorLauncher_file_dne_error;
+ public static String PerfEditorLauncher_file_read_error;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDataOpenHandler.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDataOpenHandler.java
new file mode 100644
index 0000000..8860b82
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDataOpenHandler.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.perf.handlers;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.linuxtools.internal.perf.IPerfData;
+import org.eclipse.linuxtools.internal.perf.PerfPlugin;
+import org.eclipse.linuxtools.internal.perf.ui.StatView;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IEditorLauncher;
+
+/**
+ * Class for handling opening of perf stat data files.
+ */
+public class PerfStatDataOpenHandler implements IEditorLauncher {
+
+ private static final String TITLE_EXCERPT = "Performance counter stats for"; //$NON-NLS-1$
+
+ @Override
+ public void open(IPath file) {
+ File statFile = file.toFile();
+ BufferedReader fileReader = null;
+ try {
+ fileReader = new BufferedReader(new FileReader(statFile));
+ final StringBuilder contents = new StringBuilder();
+ final StringBuilder title = new StringBuilder();
+ String line;
+
+ // read file contents
+ while ((line = fileReader.readLine()) != null) {
+ // set data title
+ if (title.length() == 0 && line.contains(TITLE_EXCERPT)) {
+ title.append(line);
+ }
+ contents.append(line);
+ contents.append("\n"); //$NON-NLS-1$
+ }
+
+ // construct basic title if none was found in the file
+ if (title.length() == 0) {
+ title.append(NLS.bind(Messages.PerfEditorLauncher_stat_title,
+ statFile.getName()));
+ }
+
+ PerfPlugin.getDefault().setStatData(new IPerfData() {
+
+ @Override
+ public String getTitle() {
+ return title.toString();
+ }
+
+ @Override
+ public String getPerfData() {
+ return contents.toString();
+ }
+ });
+
+ StatView.refreshView();
+ } catch (FileNotFoundException e) {
+ PerfPlugin.getDefault().openError(e,
+ NLS.bind(Messages.PerfEditorLauncher_file_dne_error, statFile.getName()));
+ } catch (IOException e) {
+ PerfPlugin.getDefault().openError(e,
+ NLS.bind(Messages.PerfEditorLauncher_file_read_error, statFile.getName()));
+ } finally {
+ if (fileReader != null) {
+ try {
+ fileReader.close();
+ } catch (IOException e) {
+ PerfPlugin.getDefault().openError(e, "");
+ }
+ }
+ }
+ }
+}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/messages.properties b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/messages.properties
index fb11ab4..0770a54 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/messages.properties
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/messages.properties
@@ -22,4 +22,8 @@ MsgWarning_0=Warning
MsgWarning_1=Please select two perf statistics files.
MsgConfirm_title=Confirm Selections
MsgConfirm_msg=Old Session: {0} \nNew Session: {1}
-ContentDescription_0=Sessions compared: {0} , {1} \ No newline at end of file
+ContentDescription_0=Sessions compared: {0} , {1}
+
+PerfEditorLauncher_stat_title=Performance counter stats for {0}
+PerfEditorLauncher_file_dne_error=File {0} was not found
+PerfEditorLauncher_file_read_error=Error reading from file {0} \ No newline at end of file