Buscar este blog

sábado, 28 de octubre de 2017

Java command tools Cheat sheet

JPS - Java Virtual Machine Process Status Tool

Find all java process in a host:
C:\Program Files\Java\jdk1.7.0_79\bin>jps -lv
6192 sun.tools.jps.Jps -Dapplication.home=C:\Program Files\Java\jdk1.7.0_79 -Xms8m
5348 C:\Desarrollo\eclipse-neon-2\\plugins/org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar -Dosgi.requiredJavaVersion=1.8 -XX:+UseG1GC -XX:+UseStringDeduplication -Dosgi.requiredJavaVersion=1.8 -Xms256m -Xmx2048m
3496 org.jboss.modules.Main -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:49626 -Dprogram.name=JBossTools: Red Hat JBoss EAP 6.1+ -Xms512m -Xmx1024m -XX:MaxPermSize=512m -Dorg.jboss.resolver.warning=true -Djava.net.preferIPv4Stack=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.boot.log.file=C:/Servers/jboss-eap-6.2/standalone/log/boot.log -Dlogging.configuration=file:/C:/Servers/jboss-eap-6.2/standalone/configuration/logging.properties -Djboss.home.dir=C:/Servers/jboss-eap-6.2 -Dorg.jboss.logmanager.nocolor=true -Djboss.bind.address.management=localhost -Dfile.encoding=Cp1252

JMAP - Memory analysis

Print heap usage sumary:
C:\Program Files\Java\jdk1.7.0_79\bin>jmap -heap 3496
Attaching to process ID 3496, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.79-b02

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 0
   MaxHeapFreeRatio = 100
   MaxHeapSize      = 1073741824 (1024.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 536870912 (512.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 241172480 (230.0MB)
   used     = 101086072 (96.40319061279297MB)
   free     = 140086408 (133.59680938720703MB)
   41.914430701214336% used
From Space:
   capacity = 56623104 (54.0MB)
   used     = 0 (0.0MB)
   free     = 56623104 (54.0MB)
   0.0% used
To Space:
   capacity = 56623104 (54.0MB)
   used     = 0 (0.0MB)
   free     = 56623104 (54.0MB)
   0.0% used
PS Old Generation
   capacity = 358088704 (341.5MB)
   used     = 194474744 (185.46556854248047MB)
   free     = 163613960 (156.03443145751953MB)
   54.30909766983323% used
PS Perm Generation
   capacity = 296222720 (282.5MB)
   used     = 144879144 (138.16751861572266MB)
   free     = 151343576 (144.33248138427734MB)
   48.90885614715846% used

44021 interned Strings occupying 5210120 bytes.

Print heap histogram:
C:\Program Files\Java\jdk1.7.0_79\bin>jmap -histo 3496
 num     #instances         #bytes  class name
----------------------------------------------
   1:        105723       53508480  [B
   2:        577164       46177512  [C
   3:        245156       35415432  <constMethodKlass>
   4:        245156       31391216  <methodKlass>
   5:         25900       28928112  <constantPoolKlass>
   6:        628395       25135800  java.util.LinkedHashMap$Entry
   [...]
11430:            1             16  org.jboss.as.platform.mbean.ThreadMXBeanFindDeadlockedThreadsHandler
11431:            1             16  org.jboss.msc.service.ServiceContainerImpl$4
11432:            1             16  org.jboss.as.jmx.JMXExtension$JMXSubsystemParser_1_3
Total       8243462      503304768

JCMD

Show JVM Information:
C:\Program Files\Java\jdk1.7.0_79\bin>jcmd 3496 help
3496:
The following commands are available:
VM.native_memory
VM.commercial_features
GC.rotate_log
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
Thread.print
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help

For more information about a specific command use 'help <command>'.

Print all JVM Threads:
C:\Program Files\Java\jdk1.7.0_79\bin>jcmd 3496 help Thread.print
3496:
Thread.print
Print all threads with stacktraces.

Impact: Medium: Depends on the number of threads.

Syntax : Thread.print [options]

Options: (options must be specified using the <key> or <key>=<value> syntax)
        -l : [optional] print java.util.concurrent locks (BOOLEAN, false)


C:\Program Files\Java\jdk1.7.0_79\bin>jcmd 3496 Thread.print
[...]

Generate a Heap dump:
C:\Program Files\Java\jdk1.7.0_79\bin>jcmd 3496 help GC.heap_dump
3496:
GC.heap_dump
Generate a HPROF format dump of the Java heap.

Impact: High: Depends on Java heap size and content. Request a full GC unless the '-all' option is specified.

Syntax : GC.heap_dump [options] <filename>

Arguments:
        filename :  Name of the dump file (STRING, no default value)

Options: (options must be specified using the <key> or <key>=<value> syntax)
        -all : [optional] Dump all objects, including unreachable objects (BOOLEAN, false)
 
 
C:\Program Files\Java\jdk1.7.0_79\bin>jcmd 3496 GC.heap_dump D:\tmp\test_jboss.hpprof
3496:
Heap dump file created

Important!! When you execute a heap dump, the JVM performs a garbage collector first. Therefore you will not get the heap´s snapshot, but a cleaner version.

JSTAT

Monitor Garbage Colector:
Program Files\Java\jdk1.7.0_79\bin>jstat -options
-cl
-compiler
-gc
-gccapacity
-gccause
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcpermcapacity
-gcutil
-printcompilation


C:\Program Files\Java\jdk1.7.0_79\bin>jstat -gcutil 3496 1000
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
  0,00  24,73  88,78  72,67  99,92     23    0,973     0    0,000    0,973
  0,00  24,73  88,79  72,67  99,92     23    0,973     0    0,000    0,973
  0,00  24,73  89,02  72,67  99,92     23    0,973     0    0,000    0,973