Option Name and Value Description Default --------------------- ----------- ------- heap=dump|sites|all heap profiling all cpu=samples|times|old CPU usage off monitor=y|n monitor contention n format=a|b text(txt) or binary output a file=<file> write data to file java.hprof[{.txt}] net=<host>:<port> send data over a socket off depth=<size> stack trace depth 4 interval=<ms> sample interval in ms 10 cutoff=<value> output cutoff point 0.0001 lineno=y|n line number in traces? y thread=y|n thread in traces? n doe=y|n dump on exit? y msa=y|n Solaris micro state accounting n force=y|n force output to <file> y verbose=y|n print messages about dumps y
jps Experimental: JVM Process Status Tool - Lists instrumented HotSpot Java virtual machines on a target system. (formerly jvmps)
jstat Experimental: JVM Statistics Monitoring Tool - Attaches to an instrumented HotSpot Java virtual machine and collects and logs performance statistics as specified by the command line options. (formerly jvmstat)
jstatd :Experimental: JVM jstat Daemon - Launches an RMI server application that monitors for the creation and termination of instrumented HotSpot Java virtual machines and provides a interface to allow remote monitoring tools to attach to Java virtual machines running on the local system. (formerly perfagent)
Configuring the installer... Searching for JVM on the system... Extracting installation data (can take a while, please wait)... Running the installer wizard... /tmp/ossi-c2x_test-20160509142618.silent.log: [2016-05-09 14:26:18.764]: WARNING - Your OS distribution is not supported. The list of supported systems can be found in the Oracle Solaris Studio documentation. While it might be possible to install Oracle Solaris Studio on your system, it might not function properly.
运行analyzer -v显示
1 2 3 4 5 6 7 8
analyzer: Oracle Solaris Studio 12.4 Performance Analyzer 12.4 Linux_x64 2014/10/21 Java at /usr/java/jdk1.8.0_25/bin/java selected by PATH java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode) WARNING: Linux CentOS_6.7 system "c2x_test" is not supported by the Performance tools. Running /usr/java/jdk1.8.0_25/bin/java -version /opt/oracle/solarisstudio12.4/bin/analyzer: ERROR: environment variable DISPLAY is not set
D:\work\test\target\classes>jstack -help Usage: jstack [-l] <pid> (to connect to running process, 连接正在运行的进程) jstack -F [-m] [-l] <pid> (to connect to a hung process, 连接已经宕掉的进程) jstack [-m] [-l] <executable> <core> (to connect to a core file, 连接一个core文件) jstack [-m] [-l] [server_id@]<remote server IP or hostname> (to connect to a remote debug server, 连接一个远程的debug Server)
Options: -F to force a thread dump. Use when jstack <pid> does not respond (process is hung). 当正常输出的请求不被响应时,强制说出线程堆栈 -m to print both java and native frames (mixed mode). 如果调用本地方法的话,可以显示c/c++的堆栈 -l long listing. Prints additional information about locks. 除堆栈外,显示关于锁的附加信息 -h or -help to print this help message
jstack日志, 下面摘抄的是NETTY中空epoll的一段记录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
"nioEventLoopGroup-2461-1" #4955 prio=10 os_prio=0 tid=0x00007fd857e9a000 nid=0x5e19 runnable [0x00007fd7374bc000] java.lang.Thread.State: RUNNABLE at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method) at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269) at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:79) at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86) - locked <0x00000000e673cf38> (a io.netty.channel.nio.SelectedSelectionKeySet) - locked <0x00000000e673cd30> (a java.util.Collections$UnmodifiableSet) - locked <0x00000000e673cc58> (a sun.nio.ch.EPollSelectorImpl) at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97) at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:622) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:310) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745)
D:\>jmap -help Usage: jmap [option] <pid> (to connect to running process) jmap [option] <executable <core> (to connect to a core file) jmap [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server)
where <option> is one of: <none> to print same info as Solaris pmap -heap 打印Java堆概览 -histo[:live] 打印Java堆得对象柱状分布图; 如果指定"live" 的话, 那么就只统计存活的对象 -clstats 打印class 加载的统计信息 -finalizerinfo to print information on objects awaiting finalization -dump:<dump-options> 以二进制格式dump JVM 堆内存信息 (示例: jmap -dump:live,format=b,file=heap.bin <pid>) dump-options: live 只dump 存活的对象; 如果不指定的话, 堆内存内的所有对象都会被dump出来. format=b 二进制格式 file=<file> dump 堆内存到哪个文件
-F force. Use with -dump:<dump-options> <pid> or -histo to force a heap dump or histogram when <pid> does not respond. The "live" suboption is not supported in this mode. -h | -help to print this help message -J<flag> to pass <flag> directly to the runtime system
// -dump option needs to be handled in a special way if (option.startsWith(DUMP_OPTION_PREFIX)) { // first check that the option can be parsed String fn = parseDumpOptions(option); if (fn == null) usage(); // tool for heap dumping tool = "sun.jvm.hotspot.tools.HeapDumper";
// HeapDumper -f <file> args = prepend(fn, args); args = prepend("-f", args); } else { int i=0; while (i < tools.length) { if (option.equals(tools[i][0])) { tool = tools[i][1]; break; } i++; } } if (tool == null) { usage(); // no mapping to tool }
privatestaticvoiddump(String pid, String options)throws IOException { // 从options中将dump filename解析出来 String filename = parseDumpOptions(options); if (filename == null) { usage(); // invalid options or no filename }
// get the canonical path - important to avoid just passing // a "heap.bin" and having the dump created in the target VM // working directory rather than the directory where jmap // is executed. filename = new File(filename).getCanonicalPath();
// 是否只dump 存活的对象 boolean live = isDumpLiveObjects(options);
VirtualMachine vm = attach(pid); System.out.println("Dumping heap to " + filename + " ..."); InputStream in = ((HotSpotVirtualMachine)vm). dumpHeap((Object)filename, (live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION)); drain(vm, in); }
for (int i=0; i<options.length; i++) { String option = options[i];
if (option.equals("format=b")) { // ignore format (not needed at this time) } elseif (option.equals("live")) { // a valid suboption } else { // file=<file> - check that <file> is specified if (option.startsWith("file=")) { filename = option.substring(5); if (filename.length() == 0) { returnnull; } } else { returnnull; // option not recognized } } } return filename; }
privatestaticbooleanisDumpLiveObjects(String arg){ String options[] = arg.substring(DUMP_OPTION_PREFIX.length()).split(","); for (String suboption : options) { if (suboption.equals("live")) { returntrue; } } returnfalse; }
// Attach to <pid>, existing if we fail to attach privatestatic VirtualMachine attach(String pid){ try { return VirtualMachine.attach(pid); } catch (Exception x) { String msg = x.getMessage(); if (msg != null) { System.err.println(pid + ": " + msg); } else { x.printStackTrace(); } if ((x instanceof AttachNotSupportedException) && haveSA()) { System.err.println("The -F option can be used when the " + "target process is not responding"); } System.exit(1); returnnull; // keep compiler happy } }
// Read the stream from the target VM until EOF, then detach privatestaticvoiddrain(VirtualMachine vm, InputStream in)throws IOException { // read to EOF and just print output byte b[] = newbyte[256]; int n; do { n = in.read(b); if (n > 0) { String s = new String(b, 0, n, "UTF-8"); System.out.print(s); } } while (n > 0); in.close(); vm.detach(); }
privatestaticbooleanhaveSA(){ Class c = loadClass("sun.jvm.hotspot.tools.HeapSummary"); return (c != null); }
// print usage message privatestaticvoidusage(){ System.out.println("Usage:"); if (haveSA()) { System.out.println(" jmap [option] <pid>"); System.out.println(" (to connect to running process)"); System.out.println(" jmap [option] <executable <core>"); System.out.println(" (to connect to a core file)"); System.out.println(" jmap [option] [server_id@]<remote server IP or hostname>"); System.out.println(" (to connect to remote debug server)"); System.out.println(""); System.out.println("where <option> is one of:"); System.out.println(" <none> to print same info as Solaris pmap"); System.out.println(" -heap to print java heap summary"); System.out.println(" -histo[:live] to print histogram of java object heap; if the \"live\""); System.out.println(" suboption is specified, only count live objects"); System.out.println(" -permstat to print permanent generation statistics"); System.out.println(" -finalizerinfo to print information on objects awaiting finalization"); System.out.println(" -dump:<dump-options> to dump java heap in hprof binary format"); System.out.println(" dump-options:"); System.out.println(" live dump only live objects; if not specified,"); System.out.println(" all objects in the heap are dumped."); System.out.println(" format=b binary format"); System.out.println(" file=<file> dump heap to <file>"); System.out.println(" Example: jmap -dump:live,format=b,file=heap.bin <pid>"); System.out.println(" -F force. Use with -dump:<dump-options> <pid> or -histo"); System.out.println(" to force a heap dump or histogram when <pid> does not"); System.out.println(" respond. The \"live\" suboption is not supported"); System.out.println(" in this mode."); System.out.println(" -h | -help to print this help message"); System.out.println(" -J<flag> to pass <flag> directly to the runtime system"); } else { System.out.println(" jmap -histo <pid>"); System.out.println(" (to connect to running process and print histogram of java object heap"); System.out.println(" jmap -dump:<dump-options> <pid>"); System.out.println(" (to connect to running process and dump java heap)"); System.out.println(""); System.out.println(" dump-options:"); System.out.println(" format=b binary default"); System.out.println(" file=<file> dump heap to <file>"); System.out.println(""); System.out.println(" Example: jmap -dump:format=b,file=heap.bin <pid>"); }
System.exit(1); } }
jinfo
实时查看和调整虚拟机的各项参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
jinfo [ option ] pid Usage: jinfo [option] <pid> (to connect to running process) jinfo [option] <executable <core> (to connect to a core file) jinfo [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server)
where <option> is one of: -flag <name> 打印指定name的vm flag的值 -flag [+|-]<name> 将指定名称的 VM flag打开或者关闭 -flag <name>=<value> 将指定名称的 VM flag重新设置值 -flags 打印所有的 VM flags -sysprops 打印 Java system properties <no option> 如果没有选项的话就是执行上面的所有选项 -h | -help to print this help message
// Read the stream from the target VM until EOF, then detach privatestaticvoiddrain(VirtualMachine vm, InputStream in)throws IOException { // read to EOF and just print output byte b[] = newbyte[256]; int n; do { n = in.read(b); if (n > 0) { String s = new String(b, 0, n, "UTF-8"); System.out.print(s); } } while (n > 0); in.close(); vm.detach(); }
// print usage message privatestaticvoidusage(){
Class c = loadClass("sun.jvm.hotspot.tools.JInfo"); boolean usageSA = (c != null);
System.out.println("Usage:"); if (usageSA) { System.out.println(" jinfo [option] <pid>"); System.out.println(" (to connect to running process)"); System.out.println(" jinfo [option] <executable <core>"); System.out.println(" (to connect to a core file)"); System.out.println(" jinfo [option] [server_id@]<remote server IP or hostname>"); System.out.println(" (to connect to remote debug server)"); System.out.println(""); System.out.println("where <option> is one of:"); System.out.println(" -flag <name> to print the value of the named VM flag"); System.out.println(" -flag [+|-]<name> to enable or disable the named VM flag"); System.out.println(" -flag <name>=<value> to set the named VM flag to the given value"); System.out.println(" -flags to print VM flags"); System.out.println(" -sysprops to print Java system properties"); System.out.println(" <no option> to print both of the above"); System.out.println(" -h | -help to print this help message"); } else { System.out.println(" jinfo <option> <pid>"); System.out.println(" (to connect to a running process)"); System.out.println(""); System.out.println("where <option> is one of:"); System.out.println(" -flag <name> to print the value of the named VM flag"); System.out.println(" -flag [+|-]<name> to enable or disable the named VM flag"); System.out.println(" -flag <name>=<value> to set the named VM flag to the given value"); System.out.println(" -h | -help to print this help message"); }