Applicable scenarios: machine CPU spikes, application response slowdown, abnormally elevated load.
Principle: First use low-risk tools to identify "which thread is busy," then gradually narrow down to "which method/code path."
1) First confirm the current overall JVM state (low risk)
- Use
dashboardto view CPU/thread/GC overview (recommended to set a limited number of iterations):- Pay attention to: whether CPU, thread count, and GC count/duration are abnormal.
2) Locate the busiest threads (key step)
- Use
threadto find the top N busiest threads and print their stacks:- For example:
topN=3ortopN=5
- For example:
- Record each hot thread's
threadIdand key stack method names (you can usetake_notesto record evidence).
Determine the direction:
- If the stack shows it is in
java.util.regex, JSON serialization, log formatting, etc.: it may be CPU-intensive computation. - If the stack shows lock contention: continue checking whether there is a large amount of
BLOCKED, and consider usingthread(blocking=true)to find the source thread of the blocking.
3) Further confirm the call path of the hot method (on demand, with limits)
When the hot thread stack points to a "suspicious method":
- Prefer using
stack/traceto confirm the path for that method (avoid broad matching). - If you need to observe input parameters/return values, then consider
watchortt, and set reasonable execution counts and timeouts to avoid putting pressure on production.
4) Output diagnostic conclusions
The report should include at least:
- Symptoms and evidence: dashboard summary + key fragments of topN thread stacks
- Preliminary conclusion: what type of logic CPU is mainly consumed by (computation/locks/GC/logging, etc.)
- Next steps: the target methods recommended for further trace/watch (give the precise scope of class name + method name), or recommend that the user provide the main package name/key interface information to continue narrowing down