diff options
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 6808f0b045..8c19d9f0b5 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 e5e6d23ca8..714a0554e4 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 0000000000..8860b82d31 --- /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 fb11ab400e..0770a548e7 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 |