Skip to content

Instantly share code, notes, and snippets.

@apangin
Last active January 6, 2021 11:07
Show Gist options
  • Save apangin/254eff29f6ff7eff898d78528fa69cdd to your computer and use it in GitHub Desktop.
Save apangin/254eff29f6ff7eff898d78528fa69cdd to your computer and use it in GitHub Desktop.
java.ci.totalTime = 8135593
java.cls.loadedClasses = 3053
java.cls.sharedLoadedClasses = 0
java.cls.sharedUnloadedClasses = 0
java.cls.unloadedClasses = 0
java.property.java.class.path = C:/Program Files (x86)/IDEA 2017.1/lib/jps-launcher.jar;C:/Program Files/Java/jdk1.8.0_102/lib/tools.jar;C:/Program Files (x86)/IDEA 2017.1/lib/optimizedFileManager.jar
java.property.java.endorsed.dirs = ""
java.property.java.ext.dirs = C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
java.property.java.home = C:\Program Files\Java\jdk1.8.0_102\jre
java.property.java.library.path = C:\Program Files\Java\jdk1.8.0_102\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS
java.property.java.version = 1.8.0_102
java.property.java.vm.info = mixed mode
java.property.java.vm.name = Java HotSpot(TM) 64-Bit Server VM
java.property.java.vm.specification.name = Java Virtual Machine Specification
java.property.java.vm.specification.vendor = Oracle Corporation
java.property.java.vm.specification.version = 1.8
java.property.java.vm.vendor = Oracle Corporation
java.property.java.vm.version = 25.102-b14
java.rt.vmArgs = -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs="" -Djava.net.preferIPv4Stack=true
java.rt.vmFlags =
java.threads.daemon = 5
java.threads.live = 7
java.threads.livePeak = 11
java.threads.started = 12
sun.ci.compilerThread.0.compiles = 137
sun.ci.compilerThread.0.method =
sun.ci.compilerThread.0.time = 84
sun.ci.compilerThread.0.type = 1
sun.ci.compilerThread.1.compiles = 83
sun.ci.compilerThread.1.method =
sun.ci.compilerThread.1.time = 141
sun.ci.compilerThread.1.type = 1
sun.ci.compilerThread.2.compiles = 1197
sun.ci.compilerThread.2.method =
sun.ci.compilerThread.2.time = 483
sun.ci.compilerThread.2.type = 1
sun.ci.lastFailedMethod = sun/misc/URLClassPath$JarLoader getResource
sun.ci.lastFailedType = 1
sun.ci.lastInvalidatedMethod =
sun.ci.lastInvalidatedType = 0
sun.ci.lastMethod = io/netty/channel/nio/NioEventLoop select
sun.ci.lastSize = 803
sun.ci.lastType = 1
sun.ci.nmethodCodeSize = 2203488
sun.ci.nmethodSize = 3634736
sun.ci.osrBytes = 2648
sun.ci.osrCompiles = 5
sun.ci.osrTime = 212524
sun.ci.standardBytes = 193843
sun.ci.standardCompiles = 1410
sun.ci.standardTime = 7923069
sun.ci.threads = 3
sun.ci.totalBailouts = 2
sun.ci.totalCompiles = 1415
sun.ci.totalInvalidates = 0
sun.classloader.findClassTime = 1561767971
sun.classloader.findClasses = 1742
sun.classloader.parentDelegationTime = 310208916
sun.cls.appClassBytes = 7153134
sun.cls.appClassLoadCount = 2096
sun.cls.appClassLoadTime = 3983933
sun.cls.appClassLoadTime.self = 2026183
sun.cls.classInitTime = 4704107
sun.cls.classInitTime.self = 2235415
sun.cls.classLinkedTime = 2633438
sun.cls.classLinkedTime.self = 410722
sun.cls.classVerifyTime = 2223139
sun.cls.classVerifyTime.self = 789936
sun.cls.defineAppClassTime = 1380705
sun.cls.defineAppClassTime.self = 91952
sun.cls.defineAppClasses = 1755
sun.cls.initializedClasses = 2216
sun.cls.isUnsyncloadClassSet = 0
sun.cls.jniDefineClassNoLockCalls = 7
sun.cls.jvmDefineClassNoLockCalls = 1752
sun.cls.jvmFindLoadedClassNoLockCalls = 6386
sun.cls.linkedClasses = 2602
sun.cls.loadInstanceClassFailRate = 0
sun.cls.loadedBytes = 5850872
sun.cls.lookupSysClassTime = 289125
sun.cls.methodBytes = 3064672
sun.cls.nonSystemLoaderLockContentionRate = 0
sun.cls.parseClassTime = 1726329
sun.cls.parseClassTime.self = 1352678
sun.cls.sharedClassLoadTime = 969
sun.cls.sharedLoadedBytes = 0
sun.cls.sharedUnloadedBytes = 0
sun.cls.sysClassBytes = 4070355
sun.cls.sysClassLoadTime = 869322
sun.cls.systemLoaderLockContentionRate = 0
sun.cls.time = 7960542
sun.cls.unloadedBytes = 0
sun.cls.unsafeDefineClassCalls = 85
sun.cls.verifiedClasses = 2582
sun.gc.cause = No GC
sun.gc.collector.0.invocations = 2
sun.gc.collector.0.lastEntryTime = 9444314
sun.gc.collector.0.lastExitTime = 9460538
sun.gc.collector.0.name = PSScavenge
sun.gc.collector.0.time = 40671
sun.gc.collector.1.invocations = 0
sun.gc.collector.1.lastEntryTime = 0
sun.gc.collector.1.lastExitTime = 0
sun.gc.collector.1.name = PSParallelCompact
sun.gc.collector.1.time = 0
sun.gc.compressedclassspace.capacity = 1966080
sun.gc.compressedclassspace.maxCapacity = 1073741824
sun.gc.compressedclassspace.minCapacity = 0
sun.gc.compressedclassspace.used = 1835944
sun.gc.generation.0.capacity = 42991616
sun.gc.generation.0.maxCapacity = 244318208
sun.gc.generation.0.minCapacity = 42991616
sun.gc.generation.0.name = new
sun.gc.generation.0.space.0.capacity = 32505856
sun.gc.generation.0.space.0.initCapacity = 0
sun.gc.generation.0.space.0.maxCapacity = 243269632
sun.gc.generation.0.space.0.name = eden
sun.gc.generation.0.space.0.used = 24416464
sun.gc.generation.0.space.1.capacity = 5242880
sun.gc.generation.0.space.1.initCapacity = 0
sun.gc.generation.0.space.1.maxCapacity = 81264640
sun.gc.generation.0.space.1.name = s0
sun.gc.generation.0.space.1.used = 5210176
sun.gc.generation.0.space.2.capacity = 5242880
sun.gc.generation.0.space.2.initCapacity = 0
sun.gc.generation.0.space.2.maxCapacity = 81264640
sun.gc.generation.0.space.2.name = s1
sun.gc.generation.0.space.2.used = 0
sun.gc.generation.0.spaces = 3
sun.gc.generation.1.capacity = 87031808
sun.gc.generation.1.maxCapacity = 489684992
sun.gc.generation.1.minCapacity = 87031808
sun.gc.generation.1.name = old
sun.gc.generation.1.space.0.capacity = 87031808
sun.gc.generation.1.space.0.initCapacity = 87031808
sun.gc.generation.1.space.0.maxCapacity = 489684992
sun.gc.generation.1.space.0.name = old
sun.gc.generation.1.space.0.used = 17117040
sun.gc.generation.1.spaces = 1
sun.gc.lastCause = Allocation Failure
sun.gc.metaspace.capacity = 15335424
sun.gc.metaspace.maxCapacity = 1088421888
sun.gc.metaspace.minCapacity = 0
sun.gc.metaspace.used = 14966512
sun.gc.policy.avgBaseFootprint = 268435456
sun.gc.policy.avgMajorIntervalTime = 0
sun.gc.policy.avgMajorPauseTime = 0
sun.gc.policy.avgMinorIntervalTime = 2016
sun.gc.policy.avgMinorPauseTime = 8
sun.gc.policy.avgOldLive = 0
sun.gc.policy.avgPretenuredPaddedAvg = 0
sun.gc.policy.avgPromotedAvg = 169904
sun.gc.policy.avgPromotedDev = 43984
sun.gc.policy.avgPromotedPaddedAvg = 301856
sun.gc.policy.avgSurvivedAvg = 5111588
sun.gc.policy.avgSurvivedDev = 178230
sun.gc.policy.avgSurvivedPaddedAvg = 5646278
sun.gc.policy.avgYoungLive = 4982652
sun.gc.policy.boundaryMoved = 0
sun.gc.policy.changeOldGenForMajPauses = 0
sun.gc.policy.changeOldGenForMinPauses = 0
sun.gc.policy.changeYoungGenForMajPauses = 0
sun.gc.policy.changeYoungGenForMinPauses = 0
sun.gc.policy.collectors = 2
sun.gc.policy.decideAtFullGc = 0
sun.gc.policy.decreaseForFootprint = 0
sun.gc.policy.decrementTenuringThresholdForGcCost = 0
sun.gc.policy.decrementTenuringThresholdForSurvivorLimit = 0
sun.gc.policy.desiredSurvivorSize = 5242880
sun.gc.policy.edenSize = 32505856
sun.gc.policy.freeSpace = 65011712
sun.gc.policy.fullFollowsScavenge = 0
sun.gc.policy.gcTimeLimitExceeded = 0
sun.gc.policy.generations = 3
sun.gc.policy.increaseOldGenForThroughput = 0
sun.gc.policy.increaseYoungGenForThroughput = 0
sun.gc.policy.incrementTenuringThresholdForGcCost = 0
sun.gc.policy.liveAtLastFullGc = 32505856
sun.gc.policy.liveSpace = 273418112
sun.gc.policy.majorCollectionSlope = 0
sun.gc.policy.majorGcCost = 0
sun.gc.policy.majorPauseOldSlope = 0
sun.gc.policy.majorPauseYoungSlope = 0
sun.gc.policy.maxTenuringThreshold = 15
sun.gc.policy.minorCollectionSlope = 0
sun.gc.policy.minorGcCost = 0
sun.gc.policy.minorPauseOldSlope = 0
sun.gc.policy.minorPauseTime = 6
sun.gc.policy.minorPauseYoungSlope = 0
sun.gc.policy.mutatorCost = 99
sun.gc.policy.name = ParScav:MSC
sun.gc.policy.oldCapacity = 87031808
sun.gc.policy.oldEdenSize = 32505856
sun.gc.policy.oldPromoSize = 32505856
sun.gc.policy.promoSize = 32505856
sun.gc.policy.promoted = 257872
sun.gc.policy.scavengeSkipped = 0
sun.gc.policy.survived = 5210176
sun.gc.policy.survivorOverflowed = 1
sun.gc.policy.tenuringThreshold = 7
sun.gc.policy.youngCapacity = 37748736
sun.gc.tlab.alloc = 4173747
sun.gc.tlab.allocThreads = 6
sun.gc.tlab.fastWaste = 1428
sun.gc.tlab.fills = 79
sun.gc.tlab.gcWaste = 84930
sun.gc.tlab.maxFastWaste = 1408
sun.gc.tlab.maxFills = 27
sun.gc.tlab.maxGcWaste = 38939
sun.gc.tlab.maxSlowAlloc = 4
sun.gc.tlab.maxSlowWaste = 948
sun.gc.tlab.slowAlloc = 5
sun.gc.tlab.slowWaste = 1460
sun.os.hrt.frequency = 2338437
sun.os.hrt.ticks = 187327328386
sun.perfdata.majorVersion = 2
sun.perfdata.minorVersion = 0
sun.perfdata.overflow = 0
sun.perfdata.size = 65536
sun.perfdata.timestamp = 445600
sun.perfdata.used = 20040
sun.property.sun.boot.class.path = C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\classes
sun.property.sun.boot.library.path = C:\Program Files\Java\jdk1.8.0_102\jre\bin
sun.rt._sync_ContendedLockAttempts = 123
sun.rt._sync_Deflations = 42
sun.rt._sync_EmptyNotifications = 0
sun.rt._sync_FailedSpins = 0
sun.rt._sync_FutileWakeups = 2
sun.rt._sync_Inflations = 44
sun.rt._sync_MonExtant = 256
sun.rt._sync_MonInCirculation = 0
sun.rt._sync_MonScavenged = 0
sun.rt._sync_Notifications = 21
sun.rt._sync_Parks = 53
sun.rt._sync_PrivateA = 0
sun.rt._sync_PrivateB = 0
sun.rt._sync_SlowEnter = 0
sun.rt._sync_SlowExit = 0
sun.rt._sync_SlowNotify = 0
sun.rt._sync_SlowNotifyAll = 0
sun.rt._sync_SuccessfulSpins = 0
sun.rt.applicationTime = 12597920143
sun.rt.createVmBeginTime = 1486817667168
sun.rt.createVmEndTime = 1486817667346
sun.rt.internalVersion = Java HotSpot(TM) 64-Bit Server VM (25.102-b14) for windows-amd64 JRE (1.8.0_102-b14), built on Jun 22 2016 13:15:21 by "java_re" with MS VC++ 10.0 (VS2010)
sun.rt.interruptedBeforeIO = 0
sun.rt.interruptedDuringIO = 0
sun.rt.javaCommand = org.jetbrains.jps.cmdline.Launcher
sun.rt.jvmCapabilities = 1100000000000000000000000000000000000000000000000000000000000000
sun.rt.jvmVersion = 426115086
sun.rt.safepointSyncTime = 10145
sun.rt.safepointTime = 59359
sun.rt.safepoints = 31
sun.rt.threadInterruptSignaled = 0
sun.rt.vmInitDoneTime = 1486817667230
sun.threads.vmOperationTime = 43465
sun.urlClassLoader.readClassBytesTime = 235520122
sun.zip.zipFile.openTime = 44745703
sun.zip.zipFiles = 111
import sun.jvmstat.monitor.Monitor;
import sun.jvmstat.monitor.MonitoredHost;
import sun.jvmstat.monitor.MonitoredVm;
import sun.jvmstat.monitor.VmIdentifier;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class PerfCounterProfiler {
public static void main(String[] args) throws Exception {
MonitoredHost host = MonitoredHost.getMonitoredHost((String) null);
MonitoredVm vm = host.getMonitoredVm(new VmIdentifier("<PID>"));
List<Monitor> monitors = vm.findByPattern(".*");
Map<Monitor, Object> values = monitors.stream()
.collect(Collectors.toMap(Function.identity(), Monitor::getValue));
while (true) {
Thread.sleep(1000);
System.out.println(" --- ");
monitors.forEach(m -> {
Object newValue = m.getValue();
Object oldValue = values.put(m, newValue);
if (!oldValue.equals(newValue)) {
System.out.println(m.getName() + " : " + newValue);
}
});
}
}
}
@kedarmhaswade
Copy link

Great, thank you! I got the list of perf counters thus (this adds units to output):

    public static void main(String[] args) throws MonitorException, URISyntaxException {
        MonitoredHost host =
            MonitoredHost.getMonitoredHost((String) null);
        MonitoredVm vm = host.getMonitoredVm(new VmIdentifier("<JVM pid>")); // TODO replace it with PID
        vm.findByPattern(".*").forEach(monitor -> System.out.println(monitor.getName()
            + "(base name: " + monitor.getBaseName() + ")"
            + "(unit: " + monitor.getUnits() + ")"
            + " = " +
            monitor.getValue()));
    }

It would be awesome to get answers to questions like:

  • What is a tick? A millisecond?
  • My guess is that these counters is a dump of what is collected by default and hence are readily available, or don't really stress a VM that may already be under duress. Is that right?
  • Which of the perf counters relate more to the overall health of the Hotspot VM? I am guessing that if we monitor those counters over a few seconds, minutes, then perhaps we can get a rough idea of how the VM is behaving. IOW, if I were to pick top 10, which ones would you advise me to pick?
  • How might one know if sun.rt._sync_ContendedLockAttempts is actually "Number of contended synchronizations"? So, yeah, some explanation of (at least the significant) counters would be a great help! That way, we can actually collect, say top n counters that are the most important from a dynamic profile standpoint.
  • Do other Monitoring tools (e.g. JConsole, VisualVM) show some/all of these? IOW, how much of this is mapped to the standard MXBeans?

@apangin
Copy link
Author

apangin commented Feb 16, 2017

  • Ticks are platform-dependent units used to measure time intervals. On Linux ticks are nanoseconds. On Windows ticks correspond to the units of QueryPerformanceCounter / QueryPerformanceFrequency WinAPI functions.
  • Performance Counters are collected by default and can be read without JVM assistance (and without any significant overhead).

@apangin
Copy link
Author

apangin commented Feb 16, 2017

I can't really tell which counters are more useful than others, because this depends on a particlar application. I would suggest creating a simple profiler that watches all counters and collects diffs (i. e. values changing between measurements). This way it would be possible to automatically detect counters applicable to a particular situation. Look at the attached PerfCountersProfiler.java, for example.

@apangin
Copy link
Author

apangin commented Feb 16, 2017

Here is an example of counters I may check from time to time.

// Total time spent on JIT compilation
java.ci.totalTime = 1664764413

// Number of successfully compiled methods
sun.ci.totalCompiles = 66267

// Number of failed compilations
sun.ci.totalBailouts = 1

// Cumulative number of threads ever started
java.threads.started = 2417

// Total time spent in ClassLoader.findClass
sun.classloader.findClassTime = 26643927072

// Total bytes loaded by non-bootstrap ClassLoaders
sun.cls.appClassBytes = 152811197

// Time spent on loading classes by non-bootstrap ClassLoaders
sun.cls.appClassLoadTime = 86351166

// Total time spent on class initialization
sun.cls.classInitTime = 26259674

// Cumulative number of unloaded classes
java.cls.unloadedClasses = 5816

// Distribution of young generation by object age (age = number of survived collections)
sun.gc.generation.0.agetable.*

// Young GC collection count
sun.gc.collector.0.invocations = 1868

// Total young GC time
sun.gc.collector.0.time = 49520297

// Old GC collection count
sun.gc.collector.1.invocations = 68

// Total Old GC time
sun.gc.collector.1.time = 68420228

// Number of contended synchronizations
sun.rt._sync_ContendedLockAttempts = 23820

// Total stop-the-world pause time
sun.rt.safepointTime = 136996329

// Total time spent on entering safepoints
sun.rt.safepointSyncTime = 11110028

@apangin
Copy link
Author

apangin commented Feb 16, 2017

I doubt you'll find an exhaustive explanation for all the counters. The best way to understand what the counter measures is to look into OpenJDK source code (search for PerfCounter instances).

The comments in the source code are really verbose sometimes:
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/file/e765322578aa/src/share/vm/runtime/perfData.hpp

@apangin
Copy link
Author

apangin commented Feb 16, 2017

About a half of PerfCounters are exposed through MXBeans or available through jstat, so it is often possible to get useful statistics elsewhere. But anyway it is convenient to have all the counters in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment