CPU, Memory, I/O, IRQs: Which Code?
HUATUO supports many features, including continuous profiling, the focus of this article. Its profiling capabilities span CPU, memory, interrupts, I/O, and language runtimes.
CPU utilization rises, requests slow down, and memory usage grows. Monitoring helps identify the affected nodes or containers, but the investigation continues: where does this resource usage come from, and which code is responsible? The following eight flame graphs show what clues profiling can provide and how to use them to investigate further.
To Find Where CPU Time Goes, Start with the Widest Call Paths
This PostgreSQL on-CPU flame graph shows query execution and index scans, as well as tcp_sendmsg and the subsequent kernel network processing paths. These call stacks help guide the next step: if query execution accounts for a large share, examine the query plans; if network processing dominates, consider request volume, result set sizes, and network metrics. In a flame graph, frame width represents the cumulative value of the selected metric. Horizontal position does not indicate execution order. Hotspots deserve attention, but a large share may simply reflect necessary work.
Threads Can Spend a Long Time Waiting Even When CPU Utilization Is Low
One of the wider paths in this graph runs through:
PostgresMain → pq_getbyte → secure_read → epoll_wait
This shows that a substantial amount of waiting occurred along this read path during the capture. Correlate it with incoming requests and application latency to determine whether the service was waiting normally for new requests or blocking during request processing. Besides blocked time, off-CPU profiling can also reveal time spent waiting for CPU on the run queue, with details such as runqueue_preempted, runqueue_yielded, and runqueue_missed_wakeup. The accumulated wait time in the graph may come from multiple threads or processes; it cannot be equated directly with the response time of a single request.
Java Analysis Also Requires Visibility into Runtime Activity
This graph shows Elasticsearch and Lucene search paths, along with call stacks related to thread pools and JIT compilation. These details help distinguish CPU time spent executing searches from time spent on runtime compilation or other processing.
HUATUO supports both system-level profiling and language-level profiling for C, C++, Go, Java, and Python.
Distinguish Three Memory Metrics Before Investigating Memory Issues
virtual_alloc records the amount of virtual address space allocated. Following the query execution and tuple processing paths in the graph leads to mmap-related calls, helping identify which call paths request address space.
physical_alloc records physical page allocations during the capture window. The page fault handling paths in the graph help identify which memory accesses triggered those allocations.
physical_usage shows the number of bytes still in use among the physical pages tracked by this sampling session, along with their allocation paths. Large allocation volumes or physical pages that remain in use are only clues; a single graph cannot prove a memory leak. Memory modes and limitations
For Java Memory, Examine Object Allocation and Live Objects Separately
object_alloc shows cumulative object allocations during the capture, helping identify allocation hotspots and sources of GC pressure. This graph mainly involves Netty buffers and Lucene search paths. Cumulative allocations are not the same as current heap usage.
object_usage shows live objects covered by sampling and their allocation paths. This graph mainly shows byte[] allocations for Netty receive buffers, suggesting that their reuse and release logic warrant further inspection. The two graphs cannot be subtracted directly from one another; identifying a leak still requires examining growth trends and object references.
Run It Yourself and Connect Flame Graphs to a Real Workload
Start the development stack from the root of the HUATUO repository:
make compose-dev-up
In another terminal, start the PostgreSQL load test and collect on-CPU and off-CPU profiles in separate runs:
./build/docker/run_test_postgres_profiling.sh --oncpu --offcpu
To collect results for the three memory metrics, run:
./build/docker/run_test_postgres_profiling.sh \
--virtual-alloc --physical-alloc --physical-usage
To view Java on-CPU, object allocation, and live object flame graphs for Elasticsearch, run:
./build/docker/run_test_elasticsearch_profiling.sh \
--oncpu --object-alloc --object-usage
This script uses Rally to generate search and aggregation workloads and collects Java on-CPU, object allocation, and live object profiles separately.
The scripts deploy temporary services, generate test workloads, create profiling tasks through the API, and output a Grafana URL and results directory. They require Kubernetes, containerd, and the related tools on the local machine. The fixed credentials in the development stack are intended only for development use.
After opening the results, first confirm the profiling target, Task ID, time range, and Profile type, then examine the call stacks. When comparing results before and after an optimization, keep the workload and capture conditions consistent.
The greatest value of continuous profiling is that it turns the broad question “why is the service slow?” into specific questions we can test: which paths consume CPU time, where threads wait, and which calls allocate memory. Once these paths are identified, validate them step by step against application metrics and system events to determine what to optimize and whether the changes work.
HUATUO is an open-source project from DiDi, incubated under the China Computer Federation (CCF), that provides observability across operating system kernels and agent sandboxes. It serves infrastructure scenarios including AI sandboxes, AI computing, general-purpose computing, cloud-native systems, and intelligent driving systems.
Project: https://github.com/ccfos/huatuo