Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java23
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java47
-rw-r--r--perf/org.eclipse.linuxtools.perf/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--perf/org.eclipse.linuxtools.perf/icons/backward_nav.gifbin0 -> 327 bytes
-rw-r--r--perf/org.eclipse.linuxtools.perf/icons/forward_nav.gifbin0 -> 327 bytes
-rw-r--r--perf/org.eclipse.linuxtools.perf/icons/twowaycompare_co.gifbin0 -> 376 bytes
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/AbstractDataManipulator.java16
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/BaseDataManipulator.java120
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java35
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatComparisonData.java83
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/AbstractSaveDataHandler.java26
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/Messages.java7
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveSessionHandler.java33
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveStatsHandler.java2
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDiffMenuAction.java107
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/messages.properties9
-rw-r--r--perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/StatComparisonView.java111
17 files changed, 538 insertions, 83 deletions
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java
index 0e3230f523..dfcd302541 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java
@@ -19,9 +19,13 @@ import java.util.List;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.ReportComparisonData;
import org.eclipse.linuxtools.internal.perf.SourceDisassemblyData;
import org.eclipse.linuxtools.internal.perf.StatData;
+import org.eclipse.linuxtools.internal.perf.handlers.PerfStatDiffMenuAction;
+import org.eclipse.linuxtools.internal.perf.handlers.PerfStatDiffMenuAction.PerfCachedData;
+import org.eclipse.linuxtools.internal.perf.handlers.PerfStatDiffMenuAction.Type;
import org.junit.Test;
public class DataManipulatorTest {
@@ -93,6 +97,25 @@ public class DataManipulatorTest {
assertEquals(expected, diffData.getPerfData().trim());
}
+ @Test
+ public void testPerfDataFile() {
+ String dataTitle = "title";
+ String dataID = "id";
+ String data = "perf stat data stub file\n";
+
+ PerfStatDiffMenuAction action = new PerfStatDiffMenuAction(Type.PERF_DIFF, "0");
+ PerfCachedData dataFile = action.new PerfCachedData(dataID, dataTitle);
+
+ // put test data on cache
+ PerfPlugin.getDefault().cacheData("id", data);
+
+ assertEquals("title", dataFile.getTitle());
+ assertEquals(data, dataFile.getPerfData());
+
+ // remove test data from cache
+ PerfPlugin.getDefault().removeCachedData("id");
+ }
+
/**
* Used for testing SourceDisassemblyData
*/
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java
index 2834b229f0..0621f5665f 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java
@@ -12,6 +12,8 @@ package org.eclipse.linuxtools.internal.perf.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
@@ -21,6 +23,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import org.eclipse.linuxtools.internal.perf.BaseDataManipulator;
+import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.StatComparisonData;
import org.eclipse.linuxtools.internal.perf.model.PMStatEntry;
import org.junit.Before;
@@ -31,7 +35,7 @@ public class StatsComparisonTest {
PMStatEntry statEntry2;
PMStatEntry statEntry3;
PMStatEntry statEntry4;
- private static final String STAT_RES = "resources/stat-data/";
+ public static final String STAT_RES = "resources/stat-data/";
@Before
public void setUp() {
@@ -131,6 +135,47 @@ public class StatsComparisonTest {
}
@Test
+ public void testStatDataComparisonFieldGetters() {
+ File oldStatData = new File(STAT_RES + "perf_old.stat");
+ File newStatData = new File(STAT_RES + "perf_new.stat");
+ String dataTitle = "title";
+ StatComparisonData diffData = new StatComparisonData(dataTitle,
+ oldStatData, newStatData);
+
+ assertEquals(dataTitle, diffData.getTitle());
+ assertEquals("", diffData.getPerfData());
+ assertNotNull(diffData.getDataID());
+ assertEquals(oldStatData.getPath(), diffData.getOldDataPath());
+ assertEquals(newStatData.getPath(), diffData.getNewDataPath());
+ assertEquals(oldStatData.getPath() + diffData.getDataID(),diffData.getOldDataID());
+ assertEquals(newStatData.getPath() + diffData.getDataID(),diffData.getNewDataID());
+ }
+
+ @Test
+ public void testStatDataComparisonCaching() {
+ File oldStatData = new File(STAT_RES + "perf_old.stat");
+ File newStatData = new File(STAT_RES + "perf_new.stat");
+ StatComparisonData diffData = new StatComparisonData("title",
+ oldStatData, newStatData);
+ diffData.cacheData();
+
+ PerfPlugin plugin = PerfPlugin.getDefault();
+ BaseDataManipulator dataMan = new BaseDataManipulator();
+
+ // check data was cached
+ assertEquals(dataMan.fileToString(oldStatData),
+ plugin.getCachedData(diffData.getOldDataID()));
+ assertEquals(dataMan.fileToString(newStatData),
+ plugin.getCachedData(diffData.getNewDataID()));
+
+ diffData.clearCachedData();
+
+ // check cached data was cleared
+ assertNull(plugin.getCachedData(diffData.getOldDataID()));
+ assertNull(plugin.getCachedData(diffData.getNewDataID()));
+ }
+
+ @Test
public void testStatDataComparison() {
File oldStatData = new File(STAT_RES + "perf_old.stat");
File newStatData = new File(STAT_RES + "perf_new.stat");
diff --git a/perf/org.eclipse.linuxtools.perf/.settings/org.eclipse.jdt.core.prefs b/perf/org.eclipse.linuxtools.perf/.settings/org.eclipse.jdt.core.prefs
index 69021e683e..1ac25acb97 100644
--- a/perf/org.eclipse.linuxtools.perf/.settings/org.eclipse.jdt.core.prefs
+++ b/perf/org.eclipse.linuxtools.perf/.settings/org.eclipse.jdt.core.prefs
@@ -42,7 +42,7 @@ org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
diff --git a/perf/org.eclipse.linuxtools.perf/icons/backward_nav.gif b/perf/org.eclipse.linuxtools.perf/icons/backward_nav.gif
new file mode 100644
index 0000000000..4fb4150103
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/icons/backward_nav.gif
Binary files differ
diff --git a/perf/org.eclipse.linuxtools.perf/icons/forward_nav.gif b/perf/org.eclipse.linuxtools.perf/icons/forward_nav.gif
new file mode 100644
index 0000000000..e2f8c3e1fe
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/icons/forward_nav.gif
Binary files differ
diff --git a/perf/org.eclipse.linuxtools.perf/icons/twowaycompare_co.gif b/perf/org.eclipse.linuxtools.perf/icons/twowaycompare_co.gif
new file mode 100644
index 0000000000..12788bafa3
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/icons/twowaycompare_co.gif
Binary files differ
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 519c46f1c0..47b3a99c81 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
@@ -34,7 +34,8 @@ import org.eclipse.ui.console.IOConsole;
* This class represents the general flow of a perf command being
* set up, executed, and having its data collected.
*/
-public abstract class AbstractDataManipulator implements IPerfData {
+public abstract class AbstractDataManipulator extends BaseDataManipulator implements
+ IPerfData {
private String text;
private String title;
@@ -128,19 +129,12 @@ public abstract class AbstractDataManipulator implements IPerfData {
* @param buff BufferedReader to read from.
* @param strBuff StringBuffer to write to.
*/
- private void readStream(final BufferedReader buff, final StringBuffer strBuff) {
+ private void readStream(final BufferedReader buff,
+ final StringBuffer strBuff) {
Thread readThread = new Thread(new Runnable() {
@Override
public void run() {
- String line;
- try {
- while ((line = buff.readLine()) != null) {
- strBuff.append(line);
- strBuff.append("\n"); //$NON-NLS-1$
- }
- } catch (IOException e) {
- // continue
- }
+ strBuff.append(getBufferContents(buff));
}
});
readThread.start();
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/BaseDataManipulator.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/BaseDataManipulator.java
new file mode 100644
index 0000000000..108b3985ad
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/BaseDataManipulator.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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 Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.perf;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Base class providing basic functionality for stream processing.
+ */
+public class BaseDataManipulator {
+
+ /**
+ * Get contents of specified BufferedReader as a String
+ *
+ * @param buffer BufferedReader to read from.
+ * @return String contents of BufferedReader.
+ */
+ public String getBufferContents(BufferedReader buffer) {
+ if (buffer == null) {
+ return ""; //$NON-NLS-1$
+ }
+ StringBuilder fileStr = new StringBuilder();
+ try {
+ String line;
+
+ while ((line = buffer.readLine()) != null) {
+ fileStr.append(line);
+ fileStr.append("\n"); //$NON-NLS-1$
+ }
+
+ } catch (IOException e) {
+ PerfPlugin.getDefault().openError(e, ""); //$NON-NLS-1$
+ }
+
+ return fileStr.toString();
+ }
+
+ /**
+ * Copy contents of File src into Files dest
+ *
+ * @param src File source file to copy from.
+ * @param dest File destination files to copy to.
+ */
+ public void copyFile(File src, File dest) {
+ InputStream destInput = null;
+ OutputStream srcOutput = null;
+ try {
+ destInput = new FileInputStream(src);
+ srcOutput = new FileOutputStream(dest);
+
+ byte[] buffer = new byte[1024];
+
+ int length;
+ while ((length = destInput.read(buffer)) != -1) {
+ srcOutput.write(buffer, 0, length);
+ }
+ } catch (FileNotFoundException e) {
+ PerfPlugin.getDefault().openError(e, ""); //$NON-NLS-1$
+ } catch (IOException e) {
+ PerfPlugin.getDefault().openError(e, ""); //$NON-NLS-1$
+ } finally {
+ closeResource(destInput);
+ closeResource(srcOutput);
+ }
+
+ }
+
+ /**
+ * Utility method to get all file contents as a String.
+ * @param file File to read.
+ * @return String file contents.
+ */
+ public String fileToString(File file) {
+ if (file == null | !file.exists()) {
+ return ""; //$NON-NLS-1$
+ }
+ BufferedReader fileReader = null;
+ String result = ""; //$NON-NLS-1$
+ try {
+ fileReader = new BufferedReader(new FileReader(file));
+ result = getBufferContents(fileReader);
+ } catch (FileNotFoundException e) {
+ } finally {
+ closeResource(fileReader);
+ }
+ return result;
+ }
+
+ /**
+ * Close specified resource
+ *
+ * @param resrc resource to close
+ */
+ public void closeResource(Closeable resrc) {
+ if (resrc != null) {
+ try {
+ resrc.close();
+ } catch (IOException e) {
+ PerfPlugin.getDefault().openError(e, ""); //$NON-NLS-1$
+ }
+ }
+ }
+}
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 f9241c05fc..8083ab33a6 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
@@ -17,7 +17,9 @@ package org.eclipse.linuxtools.internal.perf;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
@@ -137,6 +139,8 @@ public class PerfPlugin extends AbstractUIPlugin {
// Current report comparison data
private IPerfData reportDiffData;
+ private Map<String, String> dataCache = new HashMap<String, String>();
+
public TreeParent getModelRoot() {
return _modelRoot;
}
@@ -236,6 +240,37 @@ public class PerfPlugin extends AbstractUIPlugin {
this._ProfileView = profileView;
}
+ /* Basic cache access methods. */
+
+ /**
+ * Cache data with associated key.
+ *
+ * @param key String key to associate with data.
+ * @param data String data to cache.
+ */
+ public void cacheData(String key, String data) {
+ dataCache.put(key, data);
+ }
+
+ /**
+ * Get cached data corresponding to specified key.
+ *
+ * @param key String key to corresponding cached data.
+ * @return String cached data corresponding to specified key.
+ */
+ public String getCachedData(String key) {
+ return dataCache.get(key);
+ }
+
+ /**
+ * Remove data corresponding to specified key from cache.
+ *
+ * @param key String key of cached data to remove.
+ */
+ public void removeCachedData(String key) {
+ dataCache.remove(key);
+ }
+
/**
* The constructor
*/
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatComparisonData.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatComparisonData.java
index d9f10b4466..a6608784c2 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatComparisonData.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/StatComparisonData.java
@@ -16,6 +16,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -26,7 +27,7 @@ import org.eclipse.linuxtools.internal.perf.model.PMStatEntry.Type;
/**
* Class containing all functionality for comparting perf statistics data.
*/
-public class StatComparisonData implements IPerfData {
+public class StatComparisonData extends BaseDataManipulator implements IPerfData {
// Old stats file.
private File oldFile;
@@ -39,10 +40,14 @@ public class StatComparisonData implements IPerfData {
// Title for this comparison run.
private String title;
+ // Unique data identifier.
+ private String dataID;
+
public StatComparisonData(String title, File oldFile, File newFile) {
this.title = title;
this.oldFile = oldFile;
this.newFile = newFile;
+ this.dataID = String.valueOf(((new Date().getTime())));
}
@Override
@@ -56,6 +61,63 @@ public class StatComparisonData implements IPerfData {
}
/**
+ * Get unique identifier for this data object.
+ *
+ * @return String unique identifier based on this object's creation time.
+ */
+ public String getDataID(){
+ return dataID;
+ }
+
+ /**
+ * Generate a unique identifier based on the given file. The generation is a
+ * simple concatenation between the file path and the time of this object's
+ * creation.
+ *
+ * @param file File to generate uniqure id from.
+ * @return String unique id for specified file.
+ */
+ public String generateFileID(File file) {
+ return file.getPath() + dataID;
+ }
+
+ /**
+ * Get path to old perf data file.
+ *
+ * @return String path corresponding to old perf data.
+ */
+ public String getOldDataPath() {
+ return oldFile.getPath();
+ }
+
+ /**
+ * Get path to new perf data file.
+ *
+ * @return String path corresponding to new perf data.
+ */
+ public String getNewDataPath() {
+ return newFile.getPath();
+ }
+
+ /**
+ * Get a unique to for the old perf data file.
+ *
+ * @return String unique id.
+ */
+ public String getOldDataID() {
+ return generateFileID(oldFile);
+ }
+
+ /**
+ * Get a unique to for the old perf data file.
+ *
+ * @return String unique id.
+ */
+ public String getNewDataID() {
+ return generateFileID(newFile);
+ }
+
+ /**
* Compare stat data files and store the result in the result field.
*/
public void runComparison() {
@@ -91,6 +153,7 @@ public class StatComparisonData implements IPerfData {
* @return
*/
public ArrayList<PMStatEntry> getComparisonStats() {
+ cacheData();
ArrayList<PMStatEntry> oldStats = collectStats(oldFile);
ArrayList<PMStatEntry> newStats = collectStats(newFile);
ArrayList<PMStatEntry> result = new ArrayList<PMStatEntry>();
@@ -108,6 +171,24 @@ public class StatComparisonData implements IPerfData {
}
/**
+ * Save data contents in global cache.
+ */
+ public void cacheData() {
+ PerfPlugin plugin = PerfPlugin.getDefault();
+ plugin.cacheData(getOldDataID(), fileToString(oldFile));
+ plugin.cacheData(getNewDataID(), fileToString(newFile));
+ }
+
+ /**
+ * Remove data contents from global cache.
+ */
+ public void clearCachedData() {
+ PerfPlugin plugin = PerfPlugin.getDefault();
+ plugin.removeCachedData(getNewDataID());
+ plugin.removeCachedData(getOldDataID());
+ }
+
+ /**
* Collect statistics entries from the specified stat data file.
*
* @param file file to collect from
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/AbstractSaveDataHandler.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/AbstractSaveDataHandler.java
index e862c07a66..4c95244b92 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/AbstractSaveDataHandler.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/AbstractSaveDataHandler.java
@@ -10,9 +10,7 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.perf.handlers;
-import java.io.Closeable;
import java.io.File;
-import java.io.IOException;
import java.text.MessageFormat;
import org.eclipse.core.commands.ExecutionEvent;
@@ -23,6 +21,7 @@ import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
+import org.eclipse.linuxtools.internal.perf.BaseDataManipulator;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.swt.widgets.Display;
@@ -30,17 +29,17 @@ import org.eclipse.swt.widgets.Display;
* Class for handling general tasks handled by session saving commands:
* File name creation and validation, command enablement, data file verification.
*/
-public abstract class AbstractSaveDataHandler implements IHandler {
+public abstract class AbstractSaveDataHandler extends BaseDataManipulator implements IHandler {
@Override
public Object execute(ExecutionEvent event) {
InputDialog dialog = new InputDialog(Display.getCurrent()
.getActiveShell(), Messages.PerfSaveSession_title,
- Messages.PerfSaveSession_msg, "", new IInputValidator() {
+ Messages.PerfSaveSession_msg, "", new IInputValidator() { //$NON-NLS-1$
@Override
public String isValid(String newText) {
- if ("".equals(newText)) {
+ if ("".equals(newText)) { //$NON-NLS-1$
return Messages.PerfSaveSession_invalid_filename_msg;
}
return null;
@@ -112,23 +111,6 @@ public abstract class AbstractSaveDataHandler implements IHandler {
}
/**
- * Close specified resource
- *
- * @param resrc resource to close
- * @param resrcName resource name
- */
- public void closeResource(Closeable resrc, String resrcName) {
- if (resrc != null) {
- try {
- resrc.close();
- } catch (IOException e) {
- openErroDialog(Messages.PerfResourceLeak_title,
- Messages.PerfResourceLeak_msg, resrcName);
- }
- }
- }
-
- /**
* Save data to file with specified name and return handle
*
* @param filename the file name
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 714a0554e4..f8e040c14d 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
@@ -24,6 +24,12 @@ public class Messages extends NLS {
public static String PerfSaveStat_error_msg;
public static String PerfSaveSession_failure_title;
public static String PerfSaveSession_failure_msg;
+ public static String PerfStatDiffMenuAction_diff_text;
+ public static String PerfStatDiffMenuAction_new_tooltip;
+ public static String PerfStatDiffMenuAction_new_text;
+ public static String PerfStatDiffMenuAction_old_tooltip;
+ public static String PerfStatDiffMenuAction_old_text;
+ public static String PerfStatDiffMenuAction_stats_tooltip;
public static String PerfResourceLeak_title;
public static String PerfResourceLeak_msg;
@@ -43,6 +49,7 @@ public class Messages extends NLS {
public static String PerfEditorLauncher_stat_title;
public static String PerfEditorLauncher_file_dne_error;
public static String PerfEditorLauncher_file_read_error;
+ public static String StatComparisonData_temp_files_error;
static {
// initialize resource bundle
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveSessionHandler.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveSessionHandler.java
index d0ae9c5152..5e729efa95 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveSessionHandler.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveSessionHandler.java
@@ -11,12 +11,7 @@
package org.eclipse.linuxtools.internal.perf.handlers;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import org.eclipse.core.runtime.IPath;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
@@ -62,32 +57,4 @@ public class PerfSaveSessionHandler extends AbstractSaveDataHandler {
IPath defaultDataLoc = PerfPlugin.getDefault().getPerfProfileData();
return defaultDataLoc != null && !defaultDataLoc.isEmpty();
}
-
- private void copyFile(File src, File dest) {
- InputStream destInput = null;
- OutputStream srcOutput = null;
- try {
- destInput = new FileInputStream(src);
- srcOutput = new FileOutputStream(dest);
-
- byte[] buffer = new byte[1024];
-
- int length;
- while ((length = destInput.read(buffer)) != -1) {
- srcOutput.write(buffer, 0, length);
- }
- } catch (FileNotFoundException e) {
- openErroDialog(Messages.PerfSaveSession_failure_title,
- Messages.PerfSaveSession_failure_msg,
- dest.toString());
- } catch (IOException e) {
- openErroDialog(Messages.PerfSaveSession_failure_title,
- Messages.PerfSaveSession_failure_msg,
- dest.toString());
- } finally {
- closeResource(destInput, dest.getName());
- closeResource(srcOutput, src.getName());
- }
-
- }
}
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveStatsHandler.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveStatsHandler.java
index 42da8d933c..855cede093 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveStatsHandler.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfSaveStatsHandler.java
@@ -45,7 +45,7 @@ public class PerfSaveStatsHandler extends AbstractSaveDataHandler {
Messages.PerfSaveStat_error_msg,
newDataLoc.lastSegment());
} finally {
- closeResource(bw, statsData.getName());
+ closeResource(bw);
}
}
return null;
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDiffMenuAction.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDiffMenuAction.java
new file mode 100644
index 0000000000..fbc1354283
--- /dev/null
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/handlers/PerfStatDiffMenuAction.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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 Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.perf.handlers;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.linuxtools.internal.perf.IPerfData;
+import org.eclipse.linuxtools.internal.perf.PerfPlugin;
+import org.eclipse.linuxtools.internal.perf.StatComparisonData;
+import org.eclipse.linuxtools.internal.perf.ui.StatComparisonView;
+import org.eclipse.swt.widgets.Event;
+
+/**
+ * Class representing a menu action for {@link StatComparisonView}.
+ */
+public class PerfStatDiffMenuAction extends Action {
+
+ /**
+ * Perf data types:
+ * - PERF_OLD : Represents older perf data file.
+ * - PERF_NEW : Represents newer perf data file.
+ * - PERF_DIFF: Represents diff data.
+ */
+ public static enum Type {
+ PERF_OLD, PERF_NEW, PERF_DIFF;
+ }
+
+ // type of perf data this actions is to handle
+ private Type dataType;
+
+ // secondary id of view where this menu action is located
+ private String secondaryID;
+
+ public PerfStatDiffMenuAction(Type type, String sID){
+ dataType = type;
+ secondaryID = sID;
+ switch (dataType) {
+ case PERF_OLD:
+ setToolTipText(Messages.PerfStatDiffMenuAction_old_tooltip);
+ setImageDescriptor(PerfPlugin.getImageDescriptor("icons/backward_nav.gif")); //$NON-NLS-1$
+ break;
+ case PERF_NEW:
+ setToolTipText(Messages.PerfStatDiffMenuAction_new_tooltip);
+ setImageDescriptor(PerfPlugin.getImageDescriptor("icons/forward_nav.gif")); //$NON-NLS-1$
+ break;
+ case PERF_DIFF:
+ setToolTipText(Messages.PerfStatDiffMenuAction_stats_tooltip);
+ setImageDescriptor(PerfPlugin.getImageDescriptor("icons/twowaycompare_co.gif")); //$NON-NLS-1$
+ break;
+ }
+ }
+
+ @Override
+ public void runWithEvent(Event event) {
+ StatComparisonView view = (StatComparisonView) StatComparisonView.getView(secondaryID);
+ StatComparisonData data = (view == null) ? null: (StatComparisonData) view.getDiffData();
+ if (view != null && data !=null) {
+ IPerfData perfData = null;
+ boolean style = false;
+ switch (dataType) {
+ case PERF_OLD:
+ perfData = new PerfCachedData(data.getOldDataID(), data.getOldDataPath());
+ break;
+ case PERF_NEW:
+ perfData = new PerfCachedData(data.getNewDataID(), data.getNewDataPath());
+ break;
+ case PERF_DIFF:
+ perfData = data;
+ style = true;
+ break;
+ }
+ view.updateData(perfData, style);
+ }
+ }
+
+ /**
+ * Basic Perf data container providing functionality for accessing globally
+ * cached perf data files.
+ */
+ public class PerfCachedData implements IPerfData {
+ private String cachedDataID;
+ private String title;
+
+ public PerfCachedData(String dataID, String dataTitle) {
+ cachedDataID = dataID;
+ title = dataTitle;
+ }
+
+ @Override
+ public String getPerfData() {
+ return PerfPlugin.getDefault().getCachedData(cachedDataID);
+
+ }
+
+ @Override
+ public String getTitle() {
+ return title;
+ }
+ }
+}
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 0770a548e7..f63810693d 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
@@ -8,6 +8,12 @@ PerfSaveSession_failure_title= Error Saving Session
PerfSaveSession_failure_msg= Could not save profiling session to {0}
PerfSaveStat_error_title=Error Saving Statistics
PerfSaveStat_error_msg=Could not save statistics to {0}
+PerfStatDiffMenuAction_diff_text=Diff
+PerfStatDiffMenuAction_new_tooltip=Show New Statistics
+PerfStatDiffMenuAction_new_text=New
+PerfStatDiffMenuAction_old_tooltip=Show Old Statistics
+PerfStatDiffMenuAction_old_text=Old
+PerfStatDiffMenuAction_stats_tooltip=Show Statistics Comparison
PerfResourceLeak_title=Resource Leak
PerfResourceLeak_msg=Could not close {0}
@@ -26,4 +32,5 @@ 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
+PerfEditorLauncher_file_read_error=Error reading from file {0}
+StatComparisonData_temp_files_error=Could not create temporary files.
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 fbfb3c9d9d..b0de15acd7 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
@@ -10,8 +10,11 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.perf.ui;
+import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -21,6 +24,8 @@ import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.linuxtools.internal.perf.IPerfData;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
import org.eclipse.linuxtools.internal.perf.StatComparisonData;
+import org.eclipse.linuxtools.internal.perf.handlers.PerfStatDiffMenuAction;
+import org.eclipse.linuxtools.internal.perf.handlers.PerfStatDiffMenuAction.Type;
import org.eclipse.linuxtools.internal.perf.model.PMStatEntry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
@@ -29,6 +34,8 @@ import org.eclipse.swt.graphics.Color;
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.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
@@ -48,6 +55,8 @@ public class StatComparisonView extends ViewPart {
+ PMStatEntry.DECIMAL + ").*"; //$NON-NLS-1$
private StyledText text;
+ private IPerfData diffData;
+ private String timestamp;
private static int SECONDARY_ID = 0;
public StatComparisonView() {
@@ -59,13 +68,16 @@ public class StatComparisonView extends ViewPart {
text = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
text.setEditable(false);
+ timestamp = getTimestamp();
IPerfData statsDiff = PerfPlugin.getDefault()
.getStatDiffData();
if (statsDiff != null) {
- setStyledText(statsDiff.getPerfData());
- setContentDescription(statsDiff.getTitle());
+ diffData = statsDiff;
+ updateData(statsDiff, true);
}
+
+ fillToolbarActions();
}
@Override
@@ -74,21 +86,25 @@ public class StatComparisonView extends ViewPart {
}
/**
+ * Get perf data associated with the current view.
+ * @return IPerfData data associated with this view.
+ */
+ public IPerfData getDiffData(){
+ return diffData;
+ }
+
+ /**
* 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);
+ setBasicStyledText(input);
List<StyleRange> styles = new ArrayList<StyleRange>();
int ptr = 0;
- // set default TextConsole font (monospaced).
- text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
-
- String[] lines = input.split("\n");
+ String[] lines = input.split("\n"); //$NON-NLS-1$
for(String line : lines){
if (Pattern.matches(OCCURRENCE, line)) {
@@ -116,22 +132,76 @@ public class StatComparisonView extends ViewPart {
text.setStyleRanges(styles.toArray(new StyleRange[0]));
}
+ private void setBasicStyledText(String input){
+ text.setText(input);
+ text.setAlignment(SWT.LEFT);
+ // set default TextConsole font (monospaced).
+ text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
+ }
+
/**
- * Show new view with provided input.
+ * Create toolbar actions associated with this view.
*/
- public static void refreshView() {
+ private void fillToolbarActions() {
+ // create [Old] [New] [Diff] actions.
+ IActionBars bars = getViewSite().getActionBars();
+ for (Type type : PerfStatDiffMenuAction.Type.values()) {
+ bars.getToolBarManager().add(
+ new PerfStatDiffMenuAction(type, getViewSite().getSecondaryId()));
+ }
+ }
+
+ /**
+ * Update contents of current view, replacing the containing data and text styling.
+ *
+ * @param data IPerfData data replacement.
+ * @param style boolean true if styling is to be applied, false otherwise.
+ */
+ public void updateData(IPerfData data, boolean style){
+ if(data != null){
+ if (style) {
+ setStyledText(data.getPerfData());
+ } else {
+ setBasicStyledText(data.getPerfData());
+ }
+ setContentDescription(data.getTitle() + timestamp);
+ }
+ }
+
+ /**
+ * Get current timestamp.
+ * @return String current timestamp.
+ */
+ public String getTimestamp(){
+ Date date = new Date();
+ Timestamp timestamp = new Timestamp(date.getTime());
+ return " [" + timestamp.toString() + "]"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ /**
+ * Utility method to get an instance of a {@link StatComparisonView} by
+ * providing the secondary identifier.
+ *
+ * @param sID String secondary identifier.
+ * @return IViewPart {@link StatComparisonView} associated with the
+ * specified secondary identifier.
+ */
+ public static IViewPart getView(final String sID) {
+ final AtomicReference<IViewPart> viewRef = new AtomicReference<IViewPart>();
+
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
- PlatformUI
+ IViewPart view = PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.showView(PerfPlugin.STAT_DIFF_VIEW_ID,
- Integer.toString(SECONDARY_ID++),
+ sID,
IWorkbenchPage.VIEW_CREATE);
+ viewRef.set(view);
} catch (PartInitException e) {
IStatus status = new Status(IStatus.ERROR,
PerfPlugin.PLUGIN_ID, e.getMessage(), e);
@@ -139,5 +209,22 @@ public class StatComparisonView extends ViewPart {
}
}
});
+ return viewRef.get();
+ }
+
+ /**
+ * Create new view.
+ */
+ public static void refreshView() {
+ getView(Integer.toString(SECONDARY_ID++));
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ // remove file contents from cache
+ if (diffData != null) {
+ ((StatComparisonData) diffData).clearCachedData();
+ }
}
}

Back to the top