summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCamilo Bernal2012-12-18 17:01:13 (EST)
committer Roland Grunberg2012-12-20 10:23:22 (EST)
commit295b6fb8f5622c0f2cb816981594aefb3e3dcf27 (patch)
treea3ed1749247ac570fdc6cb1ccb0fdc5ca8f09505
parent809d5c0811317138f9e47a5c9eae2f022a549c44 (diff)
downloadorg.eclipse.linuxtools-295b6fb8f5622c0f2cb816981594aefb3e3dcf27.zip
org.eclipse.linuxtools-295b6fb8f5622c0f2cb816981594aefb3e3dcf27.tar.gz
org.eclipse.linuxtools-295b6fb8f5622c0f2cb816981594aefb3e3dcf27.tar.bz2
Clean up and fix various warnings in PerfCore.refs/changes/96/9296/2
Removed unused code and fixed various warnings reported from the sonar build, https://dev.eclipse.org/sonar/resource/index/3714?tab=violations. Change-Id: I53b5703ed1b9fbb4d09d7fe16e18bf200d87af24 Reviewed-on: https://git.eclipse.org/r/9296 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/src/org/eclipse/linuxtools/internal/perf/PerfCore.java110
1 files changed, 39 insertions, 71 deletions
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java
index 51eb36b..4beafc3 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java
@@ -21,11 +21,9 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -52,25 +50,21 @@ public class PerfCore {
String line = null;
try {
while (( line = br.readLine()) != null){
- strBuf.append(line + "\n");
+ strBuf.append(line);
+ strBuf.append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
String str = strBuf.toString();
- if (!str.trim().equals("")) {
- if (print != null) {
+ if (!str.trim().equals("") && print != null) {
print.println(blockTitle + ": \n" +str + "\n END OF " + blockTitle);
- }
}
return str;
}
// Maps event lists to host names for caching
private static HashMap<String,HashMap<String, ArrayList<String>>> eventsHostMap = null;
private static HashMap<String,ArrayList<String>> eventList = null;
- public static HashMap<String,ArrayList<String>> getEventList() {
- return getEventList(null);
- }
/**
* Gets the list of events for a given launch configuration. Uses a cache for each host
@@ -122,33 +116,42 @@ public class PerfCore {
}
- public static HashMap<String,ArrayList<String>> loadEventList(ILaunchConfiguration config) {
- HashMap<String,ArrayList<String>> events = new HashMap<String,ArrayList<String>>();
- IProject project = null;
- if (config==null) {
- if (!PerfCore.checkPerfInPath()) {
- return events;
- }
+ private static IProject getProject(ILaunchConfiguration config){
+ if(config == null){
+ return null;
} else {
ConfigUtils configUtils = new ConfigUtils(config);
try {
String projectName = configUtils.getProjectName();
// an empty string is not a legal path to file argument for ConfigUtils.getProject
- if(projectName != null && !projectName.equals("")){
- project = ConfigUtils.getProject(projectName);
+ if (projectName != null && !projectName.equals("")) {
+ return ConfigUtils.getProject(projectName);
}
-
} catch (CoreException e1) {
e1.printStackTrace();
}
- if (!PerfCore.checkRemotePerfInPath(project)) {
+ }
+
+ return null;
+ }
+
+ private static HashMap<String,ArrayList<String>> loadEventList(ILaunchConfiguration config){
+ HashMap<String,ArrayList<String>> events = new HashMap<String,ArrayList<String>>();
+ IProject project = getProject(config);
+
+ if (project == null) {
+ if (!PerfCore.checkPerfInPath()) {
return events;
}
+ } else if (!PerfCore.checkRemotePerfInPath(project)) {
+ return events;
}
+
Process p = null;
BufferedReader input = null;
try {
- // Alternatively can try with -i flag
+ // Execute "perf list" to get list of all symbolic event types.
+ // Alternatively can try with -i flag.
p = RuntimeProcessFactory.getFactory().exec(new String[] {PerfPlugin.PERF_COMMAND, "list"}, project); //(char 1 as -t is a custom field seperator
/*
@@ -160,35 +163,36 @@ public class PerfCore {
} catch( IOException e ) {
e.printStackTrace();
}
+
String line;
try {
+ // Process list of events. Each line is of the form <event>\s+<category>.
while (( line = input.readLine()) != null){
if (line.contains("[")) {
String event;
- String cat;
+ String category;
if (line.contains(PerfPlugin.STRINGS_HWBREAKPOINTS)) {
- cat = PerfPlugin.STRINGS_HWBREAKPOINTS;
- event = line.substring(1,line.indexOf("[", 0)).trim();
+ category = PerfPlugin.STRINGS_HWBREAKPOINTS;
+ event = line.substring(1,line.indexOf('[', 0)).trim();
} else if (line.contains(PerfPlugin.STRINGS_RAWHWEvents)) {
- cat = PerfPlugin.STRINGS_RAWHWEvents;
- event = line.substring(1,line.indexOf("[", 0)).trim();
+ category = PerfPlugin.STRINGS_RAWHWEvents;
+ event = line.substring(1,line.indexOf('[', 0)).trim();
} else {
- event = line.substring(1,line.indexOf("[", 0)).trim();
+ event = line.substring(1,line.indexOf('[', 0)).trim();
if (event.contains("OR")) {
event = event.split("OR")[0]; //filter out the abbreviations.
}
- cat = line.replaceFirst(".*\\[(.+)\\]", "$1").trim();
+ category = line.replaceFirst(".*\\[(.+)\\]", "$1").trim();
}
- ArrayList<String> catevs = events.get(cat);
- if (catevs == null) {
- catevs = new ArrayList<String>();
- events.put(cat, catevs);
+ ArrayList<String> categoryEvents = events.get(category);
+ if (categoryEvents == null) {
+ categoryEvents = new ArrayList<String>();
+ events.put(category, categoryEvents);
}
- catevs.add(event.trim());
+ categoryEvents.add(event.trim());
}
}
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (null != input) {
@@ -235,7 +239,6 @@ public class PerfCore {
}
}
- //p.waitFor();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
return spitStream(input, "Perf --version", null);
}
@@ -266,12 +269,6 @@ public class PerfCore {
return true;
}
- public String getRemoteProjectPath(String projectName) {
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- IProject project = root.getProject(projectName);
- return project.getName();
- }
-
//Generates a perf record command string with the options set in the given config. (If null uses default).
public static String [] getRecordString(ILaunchConfiguration config) {
String [] base = new String [] {PerfPlugin.PERF_COMMAND, "record", "-f"};
@@ -360,36 +357,7 @@ public class PerfCore {
//(Annotate string per symbol)
return base.toArray( new String[base.size()] );
}
- //Runs Perf Record on the given binary and records into perf.data before calling Report() to feed in the results.
- public static void Record(ILaunchConfiguration config, String binaryPath) {
- ConfigUtils configUtils = new ConfigUtils(config);
- IProject project = null;
- try {
- project = ConfigUtils.getProject(configUtils.getProjectName());
- } catch (CoreException e1) {
- e1.printStackTrace();
- }
- BufferedReader error = null;
- Process perfRecord = null;
- try {
- if (project==null) {
- perfRecord = Runtime.getRuntime().exec(ArrayUtil.addAll(getRecordString(null), new String [] {binaryPath}));
- } else {
- perfRecord = RuntimeProcessFactory.getFactory().exec(ArrayUtil.addAll(getRecordString(null), new String [] {binaryPath}), project);
- }
- error = new BufferedReader(new InputStreamReader(perfRecord.getErrorStream()));
- perfRecord.waitFor();
- spitStream(error,"Perf Record", null);
- } catch( IOException e ) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- //Report();
- }
- public static void Report() {
- Report(null,null,null,null,null,null);
- }
+
// Runs assuming perf.data has already been recorded, environ and workingDir can be set to null to use default
//perfDataLoc is optional - it is used to provide a pre-existing data file instead of something recorded from
//whatever project is being profiled. It is only used for junit tests atm.