8148659: Add all option to JSnap

Reviewed-by: dsamersoff
This commit is contained in:
Yasumasa Suenaga 2016-03-23 12:26:14 +09:00
parent a3b37b6372
commit cdbfbb48aa
2 changed files with 27 additions and 3 deletions

View File

@ -88,7 +88,7 @@ public class SALauncher {
}
private static boolean jsnapHelp() {
System.out.println(" <no option>\tdump performance counters");
System.out.println(" --all\tto print all performance counters");
return commonHelp();
}
@ -331,7 +331,7 @@ public class SALauncher {
private static void runJSNAP(String[] oldArgs) {
SAGetopt sg = new SAGetopt(oldArgs);
String[] longOpts = {"exe=", "core=", "pid="};
String[] longOpts = {"exe=", "core=", "pid=", "all"};
ArrayList<String> newArgs = new ArrayList();
String exe = null;
@ -352,6 +352,10 @@ public class SALauncher {
pid = sg.getOptarg();
continue;
}
if (s.equals("all")) {
newArgs.add("-a");
continue;
}
}
buildAttachArgs(newArgs, pid, exe, core);

View File

@ -25,11 +25,15 @@
package sun.jvm.hotspot.tools;
import java.io.*;
import java.util.*;
import java.util.stream.*;
import sun.jvm.hotspot.debugger.JVMDebugger;
import sun.jvm.hotspot.runtime.*;
public class JSnap extends Tool {
private boolean all;
public JSnap() {
super();
}
@ -45,7 +49,7 @@ public class JSnap extends Tool {
if (prologue.accessible()) {
PerfMemory.iterate(new PerfMemory.PerfDataEntryVisitor() {
public boolean visit(PerfDataEntry pde) {
if (pde.supported()) {
if (all || pde.supported()) {
out.print(pde.name());
out.print('=');
out.println(pde.valueAsString());
@ -62,8 +66,24 @@ public class JSnap extends Tool {
}
}
@Override
protected void printFlagsUsage() {
System.out.println(" -a\tto print all performance counters");
super.printFlagsUsage();
}
public static void main(String[] args) {
JSnap js = new JSnap();
js.all = Arrays.stream(args)
.anyMatch(s -> s.equals("-a"));
if (js.all) {
args = Arrays.stream(args)
.filter(s -> !s.equals("-a"))
.collect(Collectors.toList())
.toArray(new String[0]);
}
js.execute(args);
}
}