JProfiler Deep Dive: Profiling Java Apps, Analyzing Dumps & Memory
This guide introduces JProfiler, explains how to attach it to a running JVM, choose profiling modes, capture CPU and memory data, generate and analyze heap dumps using both JProfiler and jmap, and details the various views such as Memory, CPU, Thread, Monitor, and Telemetry for comprehensive Java performance troubleshooting.
1. JProfiler Introduction
JProfiler is a performance analysis tool for Java that can monitor execution efficiency, thread states, memory usage, and object allocation, and also analyze dump files.
Official website:
Download the appropriate version for your operating system:
2. Feature Overview
Select "attach to a locally running JVM".
Choose the target JVM and click Start .
Wait for the progress to finish and select the profiling mode.
Click OK .
Choose Live Memory to view objects and their sizes in memory.
In the CPU view, click the button in the highlighted area to record CPU execution time.
The results clearly show method execution paths and time consumption ratios; in Instrumentation mode, call counts are also displayed.
Thread view shows real‑time thread states: yellow = wait, red = blocked, green = runnable, blue = network/I‑O.
Select Thread Dumps to capture instantaneous thread stack traces.
3. Dump File Generation and Analysis
3.1 Dump Generation
Using JProfiler (online) : after connecting to the JVM, open Heap Walker , click the Take snapshot icon and wait for the dump to be created. Large heaps may require correct parameter settings; small heaps are less problematic.
Using JProfiler menu : choose Profiling → Save HPROF snapshot , select a location, and the snapshot file is saved for later analysis.
Using jmap : jmap -dump:format=b,file=filename pid On Windows, enclose the file path in quotes, e.g.: jmap -dump:format=b,file="D:\a.dump" 8632 The filename is the path where the dump will be stored; pid is the JVM process ID.
JVM startup parameters for automatic dumps (use only for debugging, not in production):
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=D:\heapdumpNote: Dumps generated by WAS in PHD format lack object values and are not useful for pinpointing problematic templates.
3.2 Dump File Analysis
After generating a dump, compress it, transfer it locally, rename the file to .hprof, and open it directly in JProfiler. Opening large dumps may take considerable time due to preprocessing; avoid clicking "skip" to ensure proper loading.
Open the .hprof file directly.
Follow the on‑screen steps (do not click "skip") to load the dump and begin analysis.
4. Module Feature Details
4.1 Memory Views
JProfiler provides dynamic memory usage visualizations and allocation information:
All Objects : shows all objects with class and package statistics; you can mark current values and view differences.
Record Objects : displays only the objects that have been recorded during profiling.
Allocation Call Tree : a tree of allocation events grouped by method, class, package, or J2EE component.
Allocation Hot Spots : lists methods, classes, or packages with the highest allocation rates; each hotspot can be expanded to show its call tree.
Class Tracker : charts the instance count of selected classes over time.
4.2 Heap Walker
Background : Identify rapidly growing object types in the Memory view, right‑click the class, and choose "Show Selection In Heap Walker". Ensure "Select recorded objects" is chosen; otherwise the analysis will include all Tomcat objects, which is slow and inaccurate.
The Heap Walker offers five sub‑views:
Classes : shows all classes and their instances; right‑click a class to "Use Selected Instances" for deeper inspection.
Allocations : displays allocation trees and hot spots for recorded objects.
References : provides an index of paths from objects to GC roots and can merge input/output views.
Time : a bar chart of recorded objects over time.
Inspections : filters the current object set based on selected criteria.
Finding leaked objects : Switch to the References tab, locate the suspect class, right‑click the instance and choose "Use Selected Instances" to narrow the scope. Then click Show Paths To GC Root to reveal why the object is not being collected.
Analyzing creation : If the leak is still unclear, use the Allocations tab to trace object creation back to the allocating methods, examining each call site until the source of the leak is identified.
4.3 Graph View
Manually add objects from the References or Biggest views to a graph to visualize incoming and outgoing references, helping locate GC roots. Tip: clicking "Go To Start" resets the heap counting to the initial state.
4.4 CPU Views
JProfiler offers several CPU analysis perspectives:
Call Tree : an aggregated top‑down tree of recorded method calls, including JDBC, JMS, and JNDI requests.
Hot Spots : a list of methods consuming the most time, with back‑trace trees for each hotspot.
Call Graph : a graph of method, class, package, or J2EE component interactions starting from a selected node.
Method Statistics : detailed timing information for methods over a selected time interval.
4.5 Thread Views
Thread analysis includes:
Thread History : a timeline showing thread activity and state changes.
Thread Monitor : a list of all active threads with their current status.
Thread Dumps : captures stack traces of all threads at a point in time.
4.6 Monitor Views
Monitoring views display lock and monitor information:
Current Locking Graph : visualizes current JVM lock states.
Current Monitors : shows threads currently waiting or blocked on monitors.
Locking History Graph : historical lock activity.
Monitor History : history of waiting and blocking events.
Monitor Usage Statistics : statistical data about monitor usage.
4.7 VM Telemetry Views
Telemetry views provide time‑series charts of JVM internals:
Memory : heap usage and size over time.
Recorded Objects : activity chart of objects and arrays.
Recorded Throughput : cumulative object allocation and release.
GC Activity : garbage‑collection events timeline.
Classes : loaded class activity.
Threads : dynamic thread activity.
CPU Load : CPU usage over time.
5. References
Using JProfiler for memory analysis.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JavaEdge
First‑line development experience at multiple leading tech firms; now a software architect at a Shanghai state‑owned enterprise and founder of Programming Yanxuan. Nearly 300k followers online; expertise in distributed system design, AIGC application development, and quantitative finance investing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
