# Arthas Diagnostic Playbooks

## 1. High CPU Usage Troubleshooting
### Symptoms:
- Host CPU reaches 90%+, thread pool saturated, alerts triggering.
### Procedure:
1. `thread -n 3`
   - Retrieve the top 3 threads consuming the highest CPU along with their stack traces.
   - Analyze whether the thread is busy in business logic (e.g. infinite loop, complex regex, heavy computation) or JVM GC threads (`VM Thread` / `GC task thread#`).
2. `thread -i 1000 -n 3`
   - Calculate real-time CPU consumption sampled over 1000 milliseconds.
3. `thread -b`
   - Check if any thread is blocked on an object monitor or synchronized lock.
4. If GC threads dominate CPU:
   - Call `dashboard` or `memory` to verify if old generation is full, triggering continuous Full GC.

---

## 2. Slow Request & High Latency Troubleshooting
### Symptoms:
- API response time spikes (e.g., > 1s), upstream gateway times out.
### Procedure:
1. Search and inspect the target class:
   - `sc -d *OrderService*`
2. Trace method execution and filter by latency:
   - `trace com.example.service.OrderService createOrder -n 5 '#cost > 50'`
   - Pinpoints sub-method calls exceeding 50ms (e.g., DB query, Redis call, remote RPC).
3. If deep internal method needs tracing:
   - Trace nested methods directly or inspect call stack:
   - `stack com.example.dao.OrderDao queryOrder -n 3`
4. Inspect input parameters for specific slow calls:
   - `watch com.example.service.OrderService createOrder '{params, returnObj, #cost}' '#cost > 200' -x 2 -n 3`

---

## 3. Unexpected Exception or Data Inconsistency
### Symptoms:
- Intermittent HTTP 500, business logic branch error, unexpected return values.
### Procedure:
1. Capture exceptions thrown by the method:
   - `watch com.example.service.PaymentService pay '{params, throwExp}' -e -x 2 -n 5`
2. Record invocation history using Time Tunnel:
   - `tt -t com.example.service.PaymentService pay -n 10`
   - `tt -l` (list captured invocations)
   - `tt -i <INDEX>` (inspect specific invocation detail)
3. Decompile loaded bytecode to rule out dirty deployment:
   - `jad com.example.service.PaymentService pay`

---

## 4. Class Loading & Version Conflict Troubleshooting
### Symptoms:
- `NoSuchMethodError`, `ClassNotFoundException`, `AbstractMethodError`, configuration not updating.
### Procedure:
1. Locate loaded class instances and classloader:
   - `sc -d com.example.model.User`
2. Inspect classloader hierarchy:
   - `classloader -t`
3. Inspect runtime static fields or Spring context beans:
   - `getstatic com.example.Constant CONFIG_CACHE`
   - `vmtool --action getInstances --className com.example.service.UserService --limit 1`
