JVM调试命令


(一)jps   显示java进程,即使用java命令启动的进程
常用用法
1、jps:显示进程id与进程名称
2、jps -l:显示主类的全名,如果进程执行的是jar包,则输出Jar路径
3、jps -v:输出JVM参数

hadoop@gdc-dn06-formal:~$ jps -lv | grep -i datanode
48150 org.apache.hadoop.hdfs.server.datanode.DataNode -Dproc_datanode -Xmx4096m -Dhadoop.log.dir=/home/hadoop/logs -Dhadoop.log.file=hadoop-hadoop-datanode-gdc-dn06-formal.i.nease.net.log -Dhadoop.home.dir=/home/hadoop/hadoop -Dhadoop.id.str=hadoop -Dhadoop.root.logger=INFO,RFA -Djava.library.path=/home/hadoop/hadoop/lib/native -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=log4j_dn.properties -Xmx20480m -Dcom.sun.management.jmxremote -XX:+UseConcMarkSweepGC -XX:-TraceClassUnloading -Dcom.sun.management.jmxremote.port=65302 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -XX:ErrorFile=/home/hadoop/logs/error.log -Dhadoop.security.logger=INFO,RFAS

(二)jstat    虚拟机统计信息监视工具

1、监视gc相关的信息,监控进程48150,每5秒一次,共20次
hadoop@gdc-dn06-formal:~$ jstat -gcutil 48150 5000 20
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
 48.28   0.00  61.09  75.35  60.28   3616  107.032    24    1.368  108.399
 48.28   0.00  67.19  75.35  60.28   3616  107.032    24    1.368  108.399
 48.28   0.00  70.44  75.35  60.28   3616  107.032    24    1.368  108.399


(三)jinfo:java配置信息工具,显示jvm参数,类似于jps -v
hadoop@gdc-dn06-formal:~$ jinfo -flags 48150
Attaching to process ID 48150, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.65-b04

-Dproc_datanode -Xmx4096m -Dhadoop.log.dir=/home/hadoop/logs -Dhadoop.log.file=hadoop-hadoop-datanode-gdc-dn06-formal.i.nease.net.log -Dhadoop.home.dir=/home/hadoop/hadoop -Dhadoop.id.str=hadoop -Dhadoop.root.logger=INFO,RFA -Djava.library.path=/home/hadoop/hadoop/lib/native -Dhadoop.policy.file=hadoop-policy.xml -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=log4j_dn.properties -Xmx20480m -Dcom.sun.management.jmxremote -XX:+UseConcMarkSweepGC -XX:-TraceClassUnloading -Dcom.sun.management.jmxremote.port=65302 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -XX:ErrorFile=/home/hadoop/logs/error.log -Dhadoop.security.logger=INFO,RFAS

(四)jmap:java内存映像工具
$ jmap -dump:file=1.txt 48150
Dumping heap to /home/hadoop/1.txt ...
Heap dump file created

$ more 1.txt
JAVA PROFILE 1.0.2xitValueLjava/util/Set<TE;>;Ljava/lang/Object;)Val/util/MessageFormatterential;kMethod che/commons/collections/collection/AbstractCollectionDecoratorksum typeOption;)VtableChannel;J)Vava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;CT_SIGNING_CAment/ThreadMXBean;>;
/DataTransferProtos$BaseHeaderProto;)Lorg/apache/hadoop/hdfs/protocol/proto/DataTransferProtos$ClientOperationHeaderProto$Builder;qDeleaming/Name;[Ljavax/naming/directory/ModificationItem;)VnputStream;Ljava/nio/charset/CharsetDecoder;)VkConstructionStagegoogle/protobuf/meGetterdeProtocolProtos$DatanodeRegistrationProto;ax/management/NotificationBroadcasterSupport$ListenerInfo;>;hdfs/protocol/proto/Datalockmanagement/DatanodeDescriptor$BlockTargetPair;>;)V.Remotea/lang/Object;V:Ljava/lang/Object;>()Ljava/util/HashMap<TK;TV;>;9.(I)Lorg/tucky/Louisvillemt mt_MT nl no pl pt pt_BR pt_PT ro ru sk sl sq sr sr_Latn_BA sr_Latn_ME sr_Latn_RS sv tr uk |  ar hi iw ja ko th vi zh Sortbase/Predicate<-TT;>;)Lcom/google/common/base/Optional<TT;>;bstractMapEntryDecorator;kPoolSliceScanner$LogEntry;S1饀serid_oidReplacementServerConstants$1yzert}+)))[pP]([-+])?(\p{Digit}+)[fFdD]?cConstraintsp<TK;TV;>;)Ljava/util/Map<TK;TV;>;doop/fs/CacheFlagt<+TE;>;)Vflect/WeakCache$Value<TV;>;BERcheckAcceptCredPermissionDeltahmRequestProtoOrBuilderm/sun/jmx/mbeanserver/MBeanAnalyzer$1nodeStorageProto$StorageState;)Lorg/apache/hadoop/hdfs/server/protocol/DatanodeStorage$State;Manager$1;ovider selectionLjava/lang/String;Ljavax/management/ObjectName$Property;>;II)VBuilder;

(五)jhat: 虚拟机堆转储快照分析工具
对jmap的结果进行分析,但一般使用visualvm等工具

(六)jstack:java堆栈跟踪工具
查看各个线程信息
$ jstack -l 48150 >> 2.txt
hadoop@gdc-dn06-formal:~$ more 2.txt
2015-05-24 11:16:27
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode):

"DataXceiver for client DFSClient_NONMAPREDUCE_1067049541_1 at /10.160.254.91:59578 [Sending block BP-1320426528-10.120.75.79-136177508
6190:blk_1545471492_1100790319712]" daemon prio=10 tid=0x00007ff12cc5b000 nid=0xa424 runnable [0x00007ff135594000]
   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:87)
 - locked <0x00000003017d1f88> (a sun.nio.ch.Util$2)
 - locked <0x00000003017d1f78> (a java.util.Collections$UnmodifiableSet)

你可能感兴趣的:(JVM调试命令)