Small set of tools for JVM troublshooting, monitoring and profiling.

Related tags

jvm-tools
Overview

Swiss Java Knife (SJK)

SJK is a command line tool for JVM diagnostic, troubleshooting and profiling.

SJK exploits standard diagnostic interfaces of JVM (such as JMX, JVM attach and perf counters) and adds some more logic on top useful for common troubleshooting cases. SJK can also be used as a library for building application specific diagnostic tools or to enhance your code with self monitoring features.

What you can do with SJK?

See full command reference.

Download

Latest prebuild binaries Last Version

Starting sjk

java -jar sjk.jar <cmd> <arguments>
java -jar sjk.jar --commands
java -jar sjk.jar --help <cmd>

Below a few command from SJK (full command reference).

ttop

Pools thread CPU usage of the target JVM and periodically reports to the console.

  • can attach via PID or open JMX port
  • displays thread memory allocation rate and cumulative process allocation rate
  • displays safe point time consumption (only if attache via PID)

More details

hh

Similar to jmap -histo.

  • plus can show a histogram of dead objects (histograms of all and live requested, then difference is calculated)
  • plus can show N top buckets in histogram

More details

stcap, stcpy, ssa and flame

These commands provide basic sample profiler capabilities. stcap produces hyper-dense stack trace dump (about 1000 compression rate compared to text format) and ssa provides few reports over dump files. stcpy can copy data in archives produced by stcap (e.g. merging dumps or filtering selected threads).

So far following reports are available:

  • sophisticated filtering (time, stack trace, thread name)
  • stack frame histogram with advanced filtering options
  • flame graph visualization (SVG or interactive HTML)
  • per thread summary (CPU usage, memory allocation, etc)
  • converting back to text format

Dump file can be also processed programatically.

More details

mx

This command allows you to do basic operations with MBean from command line.

It can:

  • read MBean attributes
  • update MBean writeable attributes
  • invoke MBean operations (arguments are supported)
  • display composite and tabular data in a human readable format
  • use wild cards to shorten MBean names (e.g. *:*,name=CodeCacheManager instead of java.lang:type=MemoryManager,name=CodeCacheManager)
  • connect to local JVM processes by PID (e.i. any Java process, you do not need to enable JMX server)
  • connect to JMX using host:port (password authentication is supported)

More details

jps

Similar to jps from JDK.

  • plus can display specific system properties of process in output
  • plus can display values of specific -XX for HotSpot JVM processes
  • plus can filter process java processes by their system properties

More details

gc

Report information about GC in real time. Data is retrieved via JMX.

More details

mxdump

Dumps all MBeans of target java process to JSON.

Issues
  • Failed to add tools.jar to classpath

    Failed to add tools.jar to classpath

    Java home points to D:\fuck\jdk1.8 make sure it is not a JRE path Failed to add tools.jar to classpath java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.gridkit.lab.jvm.attach.AttachAPI.(AttachAPI.java:45) at org.gridkit.lab.jvm.attach.AttachManager.(AttachManager.java:73) at org.gridkit.jvmtool.cmd.ProcListCmd$JPS.run(ProcListCmd.java:74) at org.gridkit.jvmtool.cli.CommandLauncher.start(Comman

    .... but i can't undertand why?

    opened by 941112341 12
  • error while trying to access java program

    error while trying to access java program

    so while trying to use ttop I get a error strange thing is that jps detects it...

    thanks RF

    [email protected]:~$ sudo java -jar sjk-plus-0.4.2.jar jps
    25987   sjk-plus-0.4.2.jar jps
    23691   /usr/share/graylog-server/graylog.jar server -f /etc/graylog/server/server.conf -np
    [email protected]:~$ sudo java -jar sjk-plus-0.4.2.jar ttop -p 23691 -n 20 -o CPU
    Failed to access MBean server: 23691
    
    opened by rsff 8
  • retained size of objects issue

    retained size of objects issue

    I'm trying to use your nice library in order to compute the retained size of an object, because I have a huge hprof file.

    I used HeapFactory.createHeap(), because I see that getRetainedSize() is not implemeted for FastHprofHeap.

    It works, the only thing is that it gives a different result compared with Yourkit or Eclipse Memory Analyzer (those two give the exact same number of bytes each time).

    Example

                    Map<Integer, String> map = new HashMap<>();
    		for (int i = 0; i < numberOfItems; i++) {
    			map.put(i, Integer.toString(i));
    		}
    

    The bigger the numberOfItems, the bigger the difference in retained size between this api and the standard tools. E.g for 5 items, this library returns 730 and Yourkit and EMA return 544 for 10_000 items, this library returns 1,366,404 and Yourkit and EMA return 1,023,568

    Any ideas? Thank you!

    opened by jackmalkovick 6
  • Cant invoke an operation with comma in arguments

    Cant invoke an operation with comma in arguments

    It will split on the comma and treats each as own argument, so if theres a jmx operation that takes a comma seperated string its impossible to use.

    opened by clohfink 5
  • Add more security to MXPR

    Add more security to MXPR

    it would be nice to add more security tomxpr, for example, ability to specify user name & password for remote connection.

    It would be also useful to add SSL, but it could be too much work.

    opened by alexott 5
  • Java 10 fix for HeapWalker.stringValue()

    Java 10 fix for HeapWalker.stringValue()

    I think it works. Compatible with heap dumps from any Java version.

    opened by stefan-reich 5
  • Editable JMX connection string

    Editable JMX connection string

    Hello, Alexey.

    I have a topic to discuss and JMX connection string customization is a subject.

    Recent applications servers, for instance Wildfly, offers JMX connection over http-remoting-jmx. As jvm-tools has RMI hard coded in the connection string at JmxConnectionInfo.java, a code change has to be made in order to change the connection type.

    I need to know your opinion as for customization of a protocol string, mostly designing related question. final String uri = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";

    Have I to implement customization in one of the preferable ways while using -cp with provider's protocol realization:

    • Override service:jmx:rmi:///jndi/rmi:// with my own hardcoded string service:jmx:remoting-jmx:///jndi/rmi:// while always using WildFly http-jmx interface?
    • Allow for override of JMX protocol string with the property setting via -D flag?
    • Use -s flag value as fully overriding JMX connection string?
    • Add new flag to have a chance to form own JMX connection string?

    Please, let me know if I need to issue a pull request. Thank you for your job!

    opened by kyxap1 5
  • Question about GC CPU Utilization

    Question about GC CPU Utilization

    Hi Alexey,

    Many thanks for this great tool!

    I have a question. I noticed an interesting metric about GC CPU utilization in the output of the 'ttop' tool:

    2016-06-29T15:44:56.789+0200 Process summary process cpu=12.74% application cpu=10.03% (user=9.55% sys=0.47%) other: cpu=2.71% GC cpu=0.05% (young=0.05%, old=0.00%)

    Question: is this the actual amount of CPU that is consumed by the JVM GC threads?

    If so, I wonder where does it come from. I have seen this metric in GC logs (i.e. Times usr= sys=), is it the same? Was not aware that it was exposed also via JMX...

    opened by stefanodoni 4
  • Add documentation about connecting to JVMs

    Add documentation about connecting to JVMs

    As a newcomer, I wish I had read some advice to troubleshoot connection between sjk and my app:

    $ java -jar sjk.jar ttop -p <pid>
    Failed to access MBean server: <pid>
    
    • Always use the same user to run sjk as the application: sudo -u elasticsearch java -jar sjk.jar ttop -p <elasticsearch pid> and test the connection with jstack before using sjk
    • Disable firewalls (iptables and the like): even if you're connecting locally using a PID, sockets are still used for communication.

    This would have saved me hours of investigation.

    opened by gquintana 3
  • feature request: show stacktrace in ttop

    feature request: show stacktrace in ttop

    Currently only thread name is showed. Could the stackstrace of the thread be showed? Just like the output of jstack.

    opened by ismlsmile 3
  • Wrong usage of Java home

    Wrong usage of Java home

    When calling the program, e.g.

     java -jar sjk.jar hh -p 12556
    

    the first output is:

    Java home points to C:\Program Files\Java\jre1.8.0_202 make sure it is not a JRE path
    

    However, my JAVA_HOME variable is set as follows (result of set JAVA_HOME):

    JAVA_HOME=C:\Program Files\Java\jdk1.8.0_202
    

    So apparently the tool uses some other Java home, which I don't know how to change. I'd suggest to use the value of the JAVA_HOME environment variable instead. Currently I am unable to use the tool at all.

    I downloaded the newest version using wget https://bit.ly/2H3Uqck -O sjk.jar. My OS is Microsoft Windows 10 Pro (Version: 10.0.19042 Build 19042) and I tried cmd and Powershell. Please let me know if you need any further information.

    opened by MetaColon 0
  • Vulnerable Dependency: jcommander 1.30

    Vulnerable Dependency: jcommander 1.30

    https://github.com/aragozin/jvm-tools/blob/378285cc3b8a72a5547b428d8715b6665f91f95c/sjk-cli/pom.xml#L38 jcommander 1.30 is from 2012 and has a number of vulnerabilities. Should update to either jcommander 1.78 or 1.80

    opened by sirkojac 0
  • Unable to parse visualvm nps generated by visualvm 2.0.1

    Unable to parse visualvm nps generated by visualvm 2.0.1

    Hi, I ran into issue where sjk seems unable to understand nps format.

    VisualVM: v2.0.1 Jdk: v14

    Unable to parse file './profiler-snapshot2.nps'. Parser config: SJK Thread Dump (Magic: TRACEDUMP_1, TRACEDUMP_2), SJK Genereic Event Dump (Magic: EVENTDUMP_1), JStack dump parser
    Input files
      ./profiler-snapshot2.nps
    
    Unable to parse file './profiler-snapshot2.nps'. Parser config: SJK Thread Dump (Magic: TRACEDUMP_1, TRACEDUMP_2), SJK Genereic Event Dump (Magic: EVENTDUMP_1), JStack dump parser
    Stream reader error: java.io.IOException: Invalid magic
    java.io.IOException: Invalid magic
    	at org.gridkit.jvmtool.stacktrace.MagicReader.readMagic(MagicReader.java:33)
    	at org.gridkit.jvmtool.stacktrace.ThreadEventCodec.createEventReader(ThreadEventCodec.java:30)
    	at org.gridkit.jvmtool.AbstractEventDumpSource.openReader(AbstractEventDumpSource.java:151)
    	at org.gridkit.jvmtool.AbstractThreadDumpSource.openReader(AbstractThreadDumpSource.java:119)
    	at org.gridkit.jvmtool.AbstractEventDumpSource$1.produceNext(AbstractEventDumpSource.java:128)
    	at org.gridkit.jvmtool.event.ChainedEventReader.hasNext(ChainedEventReader.java:68)
    	at org.gridkit.jvmtool.event.ShieldedEventReader.seekNext(ShieldedEventReader.java:66)
    	at org.gridkit.jvmtool.event.ShieldedEventReader.hasNext(ShieldedEventReader.java:95)
    	at org.gridkit.jvmtool.event.ShieldedEventReader.seekNext(ShieldedEventReader.java:66)
    	at org.gridkit.jvmtool.event.ShieldedEventReader.hasNext(ShieldedEventReader.java:95)
    	at org.gridkit.jvmtool.event.MorphingEventReader.hasNext(MorphingEventReader.java:33)
    	at org.gridkit.jvmtool.hflame.JsonFlameDataSet.feed(JsonFlameDataSet.java:97)
    	at org.gridkit.jvmtool.hflame.cmd.FlameGraphGeneratorCmd$FlameGen.run(FlameGraphGeneratorCmd.java:100)
    	at org.gridkit.jvmtool.cli.CommandLauncher.start(CommandLauncher.java:134)
    	at org.gridkit.jvmtool.SJK.main(SJK.java:14)
    0 samples processed
    No data omit report generation```
    opened by crzyjcky 3
  • bump junit to 4.11

    bump junit to 4.11

    unify junit versions to avoid inconsistency...

    opened by kaifeng-h 2
  • Inconsistent library versions notice.

    Inconsistent library versions notice.

    Hi. I have implemented a tool to detect library version inconsistencies. Your project have 3 inconsistent libraries.

    Take org.gridkit.lab:jvm-attach-api for example, this library is declared as version 1.5 in hprof-heap, 1.2 in bstub and etc... Such version inconsistencies may cause unnecessary maintenance effort in the long run. For example, if two modules become inter-dependent, library version conflict may happen. It has already become a common issue and hinders development progress. Thus a version harmonization is necessary.

    Provided we applied a version harmonization, I calculated the cost it may have to harmonize to all upper versions including an up-to-date one. The cost refers to POM config changes and API invocation changes. Take org.gridkit.lab:jvm-attach-api for example, if we harmonize all the library versions into 1.5. The concern is, how much should the project code adapt to the newer library version. We list an effort table to quantify the harmonization cost.

    The effort table is listed below. It shows the overall harmonization effort by modules. The columns represents the number of library APIs and API calls(NA,NAC), deleted APIs and API calls(NDA,NDAC) as well as modified API and API calls(NMA,NMAC). Modified APIs refers to those APIs whose call graph is not the same as previous version. Take the first row for example, if upgrading the library into version 1.5. Given that 6 APIs is used in module sjk-core, 0 of them is deleted in a recommended version(which will throw a NoMethodFoundError unless re-compiling the project), 0 of them is regarded as modified which could break the former API contract.

    |Index|Module|NA(NAC)|NDA(NDAC)|NMA(NMAC)| |-|-|-|-|-| |1|sjk-core|6(8)|0(0)|0(0)| |2|hprof-heap|1(1)|0(0)|0(0)| |3|bstub|0(0)|0(0)|0(0)|

    Also we provided another table to show the potential files that may be affected due to library API change, which could help to spot the concerned API usage and rerun the test cases.

    If you are interested, you can have a more complete and detailed report in the attached PDF file. aragozin jvm-tools.pdf

    opened by kaifeng-h 0
  • Added basic build and connect description

    Added basic build and connect description

    Hi, I had a bit of trouble working out how to connect your tool to my VM, and noticed that someone else had already raised that issue. So, when I made some progress, I figured I'd try to write up what I found in hopes it might be useful to others.

    Obviously, I'm totally new to your tool, so might have made all kinds of mistakes, but if you think this is close enough to be helpful, well, here it is. Also, if you think it needs more (or less) to be useful, don't hesitate to say so, and I'll attempt to improve this with your guidance.

    Meanwhile, thanks for a very interesting looking tool. I'm excited to start discovering what it can do for me.

    opened by SimonHGR 1
  • Bundle.properties in the right folder?

    Bundle.properties in the right folder?

    https://github.com/aragozin/jvm-tools/blob/0f9fcb920848423cb0103f2e015002adf0908a59/hprof-heap/src/main/java/org/netbeans/lib/profiler/heap/Bundle.properties#L1

    Is this file really in the correct folder? I ran into a trouble with

    Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name org/netbeans/lib/profiler/heap/Bundle, locale en_US
     	at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1573)
     	at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1396)
     	at java.util.ResourceBundle.getBundle(ResourceBundle.java:782)
     	at org.netbeans.lib.profiler.heap.HprofByteBuffer.readHeader(HprofByteBuffer.java:140)
    

    and if I look into http://central.maven.org/maven2/org/gridkit/jvmtool/hprof-heap/0.10.1/hprof-heap-0.10.1.jar into folder /org/netbeans/lib/profiler/heap I don't see the Bundle.properties file there. AFAIK, the file should be located in src/main/resources/org/netbeans/lib/profiler/heap instead of src/main/java/org/netbeans/lib/profiler/heap.

    opened by eaglerainbow 0
  • feature request:relationship of objects on Java Heap

    feature request:relationship of objects on Java Heap

    The reference relationship of objects on Java Heap is needed to debug memory leak

    opened by ismlsmile 6
  • Add documentation for API around HeapPath

    Add documentation for API around HeapPath

    I know there are some tests exists, but javadoc for packages involved + minimal general description will be nice to have.

    opened by sshikov 0
Owner
Alexey Ragozin
Alexey Ragozin
Simple JVM Profiler Using StatsD and Other Metrics Backends

statsd-jvm-profiler statsd-jvm-profiler is a JVM agent profiler that sends profiling data to StatsD. Inspired by riemann-jvm-profiler, it was primaril

Etsy, Inc. 327 Aug 5, 2021
Small set of tools for JVM troublshooting, monitoring and profiling.

Swiss Java Knife (SJK) SJK is a command line tool for JVM diagnostic, troubleshooting and profiling. SJK exploits standard diagnostic interfaces of JV

Alexey Ragozin 3k Sep 13, 2021
Sends stacktrace-level performance data from a JVM process to Riemann.

Riemann JVM Profiler riemann-jvm-profiler is a JVM agent that you can inject into any JVM process--one written in Clojure, Java, Scala, Groovy, etc.--

Riemann 288 Jul 20, 2021
Performance visualisation tools

grav A collection of tools to help visualise process execution. This blog post has some detail on the rationale and implementation detail. Scheduler p

Mark Price 268 Sep 5, 2021
A java agent to generate method mappings to use with the linux `perf` tool

perf-map-agent A java agent to generate /tmp/perf-<pid>.map files for just-in-time(JIT)-compiled methods for use with the Linux perf tools. Build Make

null 1.4k Sep 12, 2021
Tool for creating reports from Java Flight Recorder dumps

jfr-report-tool Tool for creating reports from Java Flight Recorder dumps. Influenced by https://github.com/chrishantha/jfr-flame-graph . Kudos to @ch

Lari Hotari 43 Mar 29, 2021
A short and practical intro into project loom

project-loom Project loom is all about making concurrency easier (for developers) on the JVM. It is in experimental phase. Download the early access b

Ashwin Bhaskar 15 Sep 9, 2021
production heap profiling for the JVM. compatible with google-perftools.

Heapster Heapster provides an agent library to do heap profiling for JVM processes with output compatible with Google perftools. The goal of Heapster

marius a. eriksen 391 Aug 26, 2021
Get Method Sampling from Java Flight Recorder Dump and convert to FlameGraph compatible format.

Note: Travis has removed the support for Oracle JDK 8. Therefore the build status is removed temporarily. Converting JFR Method Profiling Samples to F

M. Isuru Tharanga Chrishantha Perera 235 Sep 2, 2021
Turn -XX:+TraceBytecodes output into a FlameGraph compatible stack format

A tool to turn the output of -XX:+TraceBytecodes (a JDK debug-only feature to print every bytecode executed by the interpreter) into a simple stack fo

Claes Redestad 28 Jul 2, 2021
One file java script for visualizing JDK flight recorder execution logs as flamegraphs without any dependencies except Java and a browser.

Flamegraph from JFR logs Simple one file Java script to generate flamegraphs from Java flight recordings without installing Perl and the Brendan Gregg

Billy Sjöberg 15 May 21, 2021
An application metrics facade for the most popular monitoring tools. Think SLF4J, but for metrics.

Micrometer Application Metrics An application metrics facade for the most popular monitoring tools. Instrument your code with dimensional metrics with

Micrometer Metrics 3k Sep 15, 2021
PerfJ is a wrapper of linux perf for java programs.

PerfJ PerfJ is a wrapper of linux perf for java programs. As Brendan Gregg's words In order to profile java programs, you need a profiler that can sam

Min Zhou 356 Jun 20, 2021
Fork of tagtraum industries' GCViewer. Tagtraum stopped development in 2008, I aim to improve support for Sun's / Oracle's java 1.6+ garbage collector logs (including G1 collector)

GCViewer 1.36 GCViewer is a little tool that visualizes verbose GC output generated by Sun / Oracle, IBM, HP and BEA Java Virtual Machines. It is free

null 3.8k Sep 9, 2021
Java memory allocation profiler

Aprof - Java Memory Allocation Profiler What is it? The Aprof project is a Java Memory Allocation Profiler with very low performance impact on profile

Devexperts 205 Jul 7, 2021
Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.

JITWatch Log analyser and visualiser for the HotSpot JIT compiler. Video introduction to JITWatch video Slides from my LJC lightning talk on JITWatch

AdoptOpenJDK 2.5k Sep 10, 2021
Utilities for HDR Histogram logs manipulation

HdrLogProcessing Utilities for HDR Histogram logs manipulation. This repo currently includes utilities for summarizing and unioning of logs. Requires

Nitsan Wakart 26 Feb 23, 2021
Tools for tracking down memory / JVM problems & generating predictable-as-possible VM behaviour

Hawkshaw Tools for tracking down memory / JVM problems & generating predictable-as-possible VM behaviour You can Use Hawkshaw to mimic application obj

Martijn Verburg 40 Jan 9, 2021
Java monitoring for the command-line, profiler included

jvmtop is a lightweight console application to monitor all accessible, running jvms on a machine. In a top-like manner, it displays JVM internal metri

null 1.1k Sep 17, 2021