summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCamilo Bernal2013-03-27 13:42:05 (EDT)
committer Alexander Kurtakov2013-04-01 05:18:02 (EDT)
commitceb8a7d83741118d42363a7747c1666d3b996523 (patch)
tree5673fa108878d11d2dac3275a1385ac87ef6ae2d
parenta6ed688bb5159799f8e8ff4f15d6739acfd4843a (diff)
downloadorg.eclipse.linuxtools-ceb8a7d83741118d42363a7747c1666d3b996523.zip
org.eclipse.linuxtools-ceb8a7d83741118d42363a7747c1666d3b996523.tar.gz
org.eclipse.linuxtools-ceb8a7d83741118d42363a7747c1666d3b996523.tar.bz2
Refactor PerfLaunchConfigDelegaterefs/changes/26/11526/4
* Isolate functionality for displaying stat and source disassembly views. * Externalize message strings. * Move functionality for tracking most recent/previous perf stat result. Change-Id: I90d00208e901d943a36bf92d792f7c7995619868 Reviewed-on: https://git.eclipse.org/r/11526 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/AbstractDataManipulator.java3
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatData.java42
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/Messages.java28
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfLaunchConfigDelegate.java139
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/messages.properties13
5 files changed, 165 insertions, 60 deletions
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/AbstractDataManipulator.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/AbstractDataManipulator.java
index a248514..9b1e6e3 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/AbstractDataManipulator.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/AbstractDataManipulator.java
@@ -48,6 +48,9 @@ public abstract class AbstractDataManipulator {
return text;
}
+ protected File getWorkDir(){
+ return workDir;
+ }
public String getTitle () {
return title;
}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatData.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatData.java
index 3d8c1ee..d1e25a4 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatData.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatData.java
@@ -15,6 +15,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.internal.perf.handlers.PerfSaveStatsHandler;
+
/**
* This class handles the execution of the perf stat command
* and stores the resulting data.
@@ -67,4 +71,42 @@ public class StatData extends AbstractDataManipulator {
return args;
}
+ /**
+ * Save latest perf stat result under $workingDirectory/perf.stat. If file
+ * already exists rename it to perf.old.stat, in order to keep a reference
+ * to the previous session and be consistent with the way perf handles perf
+ * report data files.
+ */
+ public void updateStatData() {
+
+ // build file name format
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(PerfPlugin.PERF_COMMAND);
+ stringBuilder.append("%s."); //$NON-NLS-1$
+ stringBuilder.append(PerfSaveStatsHandler.DATA_EXT);
+ String statNameFormat = stringBuilder.toString();
+
+ // get current stat file
+ Path workingDir = new Path(getWorkDir().getAbsolutePath());
+ String curStatName = String.format(statNameFormat, ""); //$NON-NLS-1$
+ IPath curStatPath = workingDir.append(curStatName);
+ File curStatFile = new File(curStatPath.toOSString());
+
+ if (curStatFile.exists()) {
+ // get previous stat file
+ String oldStatName = String.format(statNameFormat, ".old"); //$NON-NLS-1$
+ IPath oldStatPath = workingDir.append(oldStatName);
+ File oldStatFile = oldStatPath.toFile();
+
+ if (oldStatFile.exists()) {
+ oldStatFile.delete();
+ }
+
+ curStatFile.renameTo(oldStatFile);
+ }
+
+ PerfSaveStatsHandler saveStats = new PerfSaveStatsHandler();
+ saveStats.saveData(PerfPlugin.PERF_COMMAND);
+ }
+
}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/Messages.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/Messages.java
new file mode 100644
index 0000000..6807275
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/Messages.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.launch;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.perf.launch"; //$NON-NLS-1$
+ public static String PerfLaunchConfigDelegate_perf_not_found;
+ public static String PerfLaunchConfigDelegate_analyzing;
+ public static String PerfLaunchConfigDelegate_stat_title;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfLaunchConfigDelegate.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfLaunchConfigDelegate.java
index c8244d6..3c9d19c 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfLaunchConfigDelegate.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfLaunchConfigDelegate.java
@@ -22,6 +22,7 @@ package org.eclipse.linuxtools.internal.perf.launch;
import java.io.File;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,7 +42,6 @@ import org.eclipse.linuxtools.internal.perf.PerfCore;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.SourceDisassemblyData;
import org.eclipse.linuxtools.internal.perf.StatData;
-import org.eclipse.linuxtools.internal.perf.handlers.PerfSaveStatsHandler;
import org.eclipse.linuxtools.internal.perf.ui.SourceDisassemblyView;
import org.eclipse.linuxtools.internal.perf.ui.StatView;
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationDelegate;
@@ -62,17 +62,11 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
ILaunch launch, IProgressMonitor monitor) throws CoreException {
// check if Perf exists in $PATH
if (! PerfCore.checkPerfInPath()) {
- IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID, "Error: Perf was not found on PATH"); //$NON-NLS-1$
+ IStatus status = new Status(IStatus.ERROR, PerfPlugin.PLUGIN_ID,
+ Messages.PerfLaunchConfigDelegate_perf_not_found); //$NON-NLS-1$
throw new CoreException(status);
}
- //Find the binary path
- IPath exePath = CDebugUtils.verifyProgramPath( config );
-
- // Build the commandline string to run perf recording the given project
- // Program args from launch config.
- String arguments[] = getProgramArgumentsArray(config);
-
// Get working directory
File wd = getWorkingDirectory(config);
if (wd == null) {
@@ -83,51 +77,16 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
if (config.getAttribute(PerfPlugin.ATTR_ShowStat,
PerfPlugin.ATTR_ShowStat_default)) {
+ showStat(config, launch);
+ } else {
- int runCount = config.getAttribute(PerfPlugin.ATTR_StatRunCount,
- PerfPlugin.ATTR_StatRunCount_default);
- StringBuffer args = new StringBuffer();
- for (String arg : arguments) {
- args.append(arg);
- args.append(" "); //$NON-NLS-1$
- }
- String title = renderProcessLabel("Performance counter stats for "
- + exePath.toOSString()
- + " " + args.toString() //$NON-NLS-1$
- + " (" + runCount + " runs)" ); //$NON-NLS-1$ /$NON-NLS-2$
-
- StatData sd = null;
- List<String> configEvents = config.getAttribute(PerfPlugin.ATTR_SelectedEvents, PerfPlugin.ATTR_SelectedEvents_default);
- String[] statEvents = new String [] {};
-
- if(!config.getAttribute(PerfPlugin.ATTR_DefaultEvent, PerfPlugin.ATTR_DefaultEvent_default)){
- // gather selected events
- statEvents = (configEvents == null) ? statEvents : configEvents.toArray(new String[]{});
- }
-
- sd = new StatData(title, wd, exePath.toOSString(), arguments, runCount, statEvents);
- sd.setLaunch(launch);
- sd.parse();
- PerfPlugin.getDefault().setStatData(sd);
-
- StringBuilder perfStatFile = new StringBuilder();
- perfStatFile.append(PerfPlugin.PERF_COMMAND);
- perfStatFile.append("."); //$NON-NLS-1$
- perfStatFile.append(PerfSaveStatsHandler.DATA_EXT);
-
- // perf.stat will be replaced by the most recent session
- File latestStatData = new File(workingDir.append(
- perfStatFile.toString()).toOSString());
- if(latestStatData.exists()){
- latestStatData.delete();
- }
+ //Find the binary path
+ IPath exePath = CDebugUtils.verifyProgramPath( config );
- // keep track of most recent session in file perf.stat
- PerfSaveStatsHandler saveStats = new PerfSaveStatsHandler();
- saveStats.saveData(PerfPlugin.PERF_COMMAND);
+ // Build the commandline string to run perf recording the given project
+ // Program args from launch config.
+ String arguments[] = getProgramArgumentsArray(config);
- StatView.refreshView();
- } else {
ArrayList<String> command = new ArrayList<String>();
// Get the base commandline string (with flags/options based on config)
command.addAll(Arrays.asList(PerfCore.getRecordString(config)));
@@ -135,7 +94,8 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
command.add(exePath.toOSString());
command.addAll(Arrays.asList( arguments));
String[] commandArray = command.toArray(new String[] {});
- boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT);
+ boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL,
+ ICDTLaunchConfigurationConstants.USE_TERMINAL_DEFAULT);
Process process;
try {
@@ -156,7 +116,8 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
// Find the console
for(IConsole x : existing) {
- if (x.getName().contains(renderProcessLabel(commandArray[0]))) {
+ if (x.getName().contains(renderProcessLabel(commandArray[0]))
+ && x instanceof IOConsole) {
binaryOutCons = (IOConsole)x;
}
}
@@ -174,12 +135,12 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
print = new PrintStream(outputTo);
for (int i = 0; i < commandArray.length; i++) {
- print.print(commandArray[i] + " ");
+ print.print(commandArray[i] + " "); //$NON-NLS-1$
}
// Print Message
print.println();
- print.println("Analysing recorded perf.data, please wait...");
+ print.println(Messages.PerfLaunchConfigDelegate_analyzing);
// Possibly should pass this (the console reference) on to
// PerfCore.Report if theres anything we ever want to spit
// out to user.
@@ -191,11 +152,7 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
if (config.getAttribute(PerfPlugin.ATTR_ShowSourceDisassembly,
PerfPlugin.ATTR_ShowSourceDisassembly_default)) {
- String title = renderProcessLabel(workingDir + "perf.data"); //$NON-NLS-1$
- SourceDisassemblyData sdData = new SourceDisassemblyData(title, workingDir);
- sdData.parse();
- PerfPlugin.getDefault().setSourceDisassemblyData(sdData);
- SourceDisassemblyView.refreshView();
+ showSourceDisassembly(workingDir);
}
} catch (InterruptedException e) {
@@ -205,4 +162,66 @@ public class PerfLaunchConfigDelegate extends ProfileLaunchConfigurationDelegate
}
}
+ /**
+ * Show source disassembly view.
+ * @param workingDir working directory.
+ */
+ private void showSourceDisassembly(IPath workingDir) {
+ String title = renderProcessLabel(workingDir + "perf.data"); //$NON-NLS-1$
+ SourceDisassemblyData sdData = new SourceDisassemblyData(title, workingDir);
+ sdData.parse();
+ PerfPlugin.getDefault().setSourceDisassemblyData(sdData);
+ SourceDisassemblyView.refreshView();
+ }
+
+ /**
+ * Show statistics view.
+ * @param config launch configuration
+ * @param launch launch
+ * @throws CoreException
+ */
+ private void showStat(ILaunchConfiguration config, ILaunch launch)
+ throws CoreException {
+ //Find the binary path
+ IPath exePath = CDebugUtils.verifyProgramPath( config );
+
+ // Build the command line string
+ String arguments[] = getProgramArgumentsArray(config);
+
+ // Get working directory
+ IPath workingDir = PerfPlugin.getDefault().getWorkingDir();
+ File wd = workingDir.toFile();
+
+ int runCount = config.getAttribute(PerfPlugin.ATTR_StatRunCount,
+ PerfPlugin.ATTR_StatRunCount_default);
+ StringBuffer args = new StringBuffer();
+ for (String arg : arguments) {
+ args.append(arg);
+ args.append(" "); //$NON-NLS-1$
+ }
+
+ Object[] titleArgs = new Object[]{exePath.toOSString(), args.toString(), String.valueOf(runCount)};
+ String title = MessageFormat.format(Messages.PerfLaunchConfigDelegate_stat_title, titleArgs);
+
+ @SuppressWarnings("unchecked")
+ List<String> configEvents = config.getAttribute(PerfPlugin.ATTR_SelectedEvents,
+ PerfPlugin.ATTR_SelectedEvents_default);
+
+ String[] statEvents = new String [] {};
+
+ if(!config.getAttribute(PerfPlugin.ATTR_DefaultEvent, PerfPlugin.ATTR_DefaultEvent_default)){
+ // gather selected events
+ statEvents = (configEvents == null) ? statEvents : configEvents.toArray(new String[]{});
+ }
+
+ StatData sd = new StatData(title, wd, exePath.toOSString(), arguments, runCount, statEvents);
+ sd.setLaunch(launch);
+ sd.parse();
+ PerfPlugin.getDefault().setStatData(sd);
+
+ sd.updateStatData();
+
+ StatView.refreshView();
+ }
+
}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/messages.properties b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/messages.properties
new file mode 100644
index 0000000..4c741c9
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/messages.properties
@@ -0,0 +1,13 @@
+###############################################################################
+# 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
+###############################################################################
+PerfLaunchConfigDelegate_perf_not_found=Error: Perf was not found on PATH
+PerfLaunchConfigDelegate_analyzing=Analyzing recorded perf.data, please wait...
+PerfLaunchConfigDelegate_stat_title=Performance counter stats for {0} {1} ({2} runs) \ No newline at end of file