
Tracing Latency Issues on Linux: A Practical Workflow
Start with the one syscall that is slow, not the whole machine. For tracing latency issues, Linux gives you a clean path: use strace or syscount to find the offending calls, prove whether the task is running or waiting, then follow the delay through perf, tracefs, and ftrace. A copied workaround may hide the pause. It won’t explain where the time went.
Last updated: 2026-11-11
Tracing Linux latency means catching your process at the kernel boundary and asking a precise question. Is it waiting on I/O, blocked on a lock, delayed by the scheduler, interrupted by hardware, or calling a cheap syscall ten thousand times? Get that split right and you fix the real layer. Get it wrong and you spend the night tuning a database that was never the problem.
How do I start tracing latency issues on Linux?
Define the symptom before choosing a tracer. “The service is slow” gives you nowhere to start. “Requests pause after connect() returns” gives you an event, a process, and a time window.
The delay usually belongs to one of these buckets, and each one sends you to a different tool:
- Syscall execution: A call enters the kernel and returns late.
- Blocked I/O: The task waits for storage, a socket, or another device.
- Scheduler delay: The task is runnable but doesn’t get CPU time.
- Lock contention: The task sleeps on a mutex or futex.
- Interrupt interference: Long interrupt-disabled sections hold up other work.
- Application waiting: The process pauses before making another syscall.
Start with application timestamps and logs. Tie the pause to one request, job, or transaction. Then capture the process at that moment.
If you don’t have a reproducible workload, stop there and build one. A trace without a time anchor becomes a large file full of unrelated truths.
Measure, correlate, then read the kernel path
The workflow stays the same because each step removes one class of guesswork.
- Mark the slow operation. Record its start and end in the application log.
- Count system calls. Use
strace -cor BCCsyscountto find high time, volume, and errors. - Inspect individual calls. Add timestamps, durations, return values, and focused syscall filters.
- Separate running from waiting. Use
perf schedwhen a task wakes but doesn’t run. - Trace the kernel path. Use tracepoints first, then selective ftrace function tracing.
- Repeat the original workload. The same request must improve for the same measured reason.
Confirm which syscall is hot, confirm whether the time is on-CPU or waiting, then attribute it to a code path. Skip a step and you end up guessing.
Here is how I split the tools. Read the trap column first, because that is where most bad diagnoses come from:
| Tool | What it tells you | Where it fits | Main trap |
|---|---|---|---|
strace | Exact calls, arguments, return values, errors, and durations | Short reproductions and development | It can distort the workload badly |
BCC syscount | Calls, total time, and optional latency by syscall | Finding the hot syscall before drilling down | It doesn’t show every argument |
perf trace | Syscalls plus page faults, task lifetime, and scheduling events | Lower-disturbance live triage | It can still produce too much data |
| ftrace and tracefs | Kernel functions, tracepoints, IRQs, preemption, and wakeups | Explaining the kernel-side path | Broad tracing buries the event you need |
perf sched | Runnable-to-running delay and scheduler behavior | Proving run-queue latency | It doesn’t explain time inside the syscall |
trace-cmd | Repeatable tracefs recording and offline reports | Saving a bounded incident capture | PID filters can hide related worker activity |
Reach for the lightest tool that answers the current question. Starting with function tracing across the whole kernel is how you create a gigabyte of evidence and learn nothing from it.
System call analysis with strace and syscount

Run strace -c against the target process while you reproduce the pause. Stop it after the event happens.
sudo strace -c -f -p "$PID"
The -c option counts time, calls, and errors for each syscall in a summary. The -f option follows child processes. Check total time first, then call volume and the error column.
Next, record the suspect calls with timestamps and durations:
sudo strace -f -ttt -T \
-e trace=%file,%network \
-o trace.log \
-p "$PID"
The -ttt flag prints an absolute timestamp. The -T flag shows the time spent in each syscall. A duration appears after the return value. Failures appear as negative returns with names such as ETIMEDOUT, ENOENT, or EAGAIN.
Watch for these patterns. The first three explain most of the cases worth chasing:
- One call with consistently long durations.
- A cheap call repeated at high volume.
- Repeated failures followed by retries.
futex()calls that point to lock contention.poll(),epoll_wait(), orselect()calls that reflect expected waiting.- Calls shown as unfinished and later resumed.
- Signals interrupting calls and forcing restart behavior.
A long read() does not prove slow storage. It may be waiting on a pipe, socket, terminal, or device. Read the file descriptor and surrounding calls before blaming the disk.
Is BCC syscount lighter than strace?
Yes, and that is the reason to use it for a summary. Package names differ, so the executable may be syscount or syscount-bpfcc.
sudo syscount-bpfcc -L -p "$PID"
syscount summarizes syscall counts across the system or one process, with optional latency information. Its output lists calls by name, such as write, read, and wait4. That makes it useful when call volume owns the latency budget.
For setup and tool naming differences, see the guide to BCC kernel tracing tools.
Measure call latency without ruining the result
Use strace for a short, controlled reproduction. It uses ptrace, which stops the target around syscall events. One measured workload ran 173 times slower under strace. So a live service can look far worse than the original fault.
Run the same representative operation each time. Keep the request shape, data set, concurrency, and cache state consistent. Otherwise, you’re comparing different workloads and calling the difference a fix.
Use separate captures for separate questions:
sudo strace -c -f -p "$PID"
sudo strace -f -ttt -T -o trace.log -p "$PID"
sudo strace -f -ttt -T \
-e trace=%file,%network \
-o focused.log \
-p "$PID"
For exact flags and filter syntax, use the official strace documentation. Forum commands age badly, especially around syscall groups and architecture names.
Should I use perf trace on a live system?
Usually, yes. On a live system, try perf trace before attaching strace:
sudo perf trace -p "$PID"
perf trace initially shows syscalls. However, it can also report page faults, scheduling events, and task lifetime events. It doesn’t stop the process at every syscall the way strace does. Still, measure its effect against an untraced baseline.
Don’t confuse perf trace with frequency-based perf record. On modern Linux, perf record commonly samples at 4000 Hz by default. Raising that frequency collects more samples and burns more CPU.
Estimated time overhead of system calls on Linux
A single system call on Linux costs roughly 1 to 2 microseconds of pure overhead. That is the cost of crossing into the kernel and returning with little real work done. Treat it as a rough floor for the target machine, not a constant supplied by physics.
The visible duration contains several costs:
- Entry into and return from the kernel.
- Argument checks and security hooks.
- The work performed by the syscall.
- Time blocked on I/O, locks, or another task.
- Scheduler delay before the task runs again.
- Overhead added by the tracer.
Linux inter-process communication syscalls commonly benchmark in the tens of microseconds. However, a storage or network call may wait far longer. Its duration includes the work and any blocking behind it.
So measure the target kernel, hardware, and workload. A tight test around getpid() estimates entry overhead. It tells you little about read() against a cold filesystem or connect() through a congested network.
Raw counts matter as much as durations. The slowest call is interesting. Total time across every invocation is what consumes the latency budget.
For background on what occurs at the boundary, read the Linux system call walkthrough.
Mount and configure tracefs safely
Use tracefs only after user-space tracing gives you a suspect. First, confirm whether it is already mounted:
findmnt -t tracefs
The usual mount point is /sys/kernel/tracing. If findmnt returns nothing, mount it explicitly:
sudo mount -t tracefs tracefs /sys/kernel/tracing
Do not fix access by making the entire tree writable. Tracefs controls active kernel tracing, buffer allocation, and filters. Run the capture with the required privilege or grant narrow access through your system’s policy.
Before recording, stop tracing and clear stale state:
TRACE=/sys/kernel/tracing
echo 0 | sudo tee "$TRACE/tracing_on"
echo nop | sudo tee "$TRACE/current_tracer"
sudo sh -c ": > '$TRACE/trace'"
sudo sh -c ": > '$TRACE/set_ftrace_pid'"
sudo sh -c ": > '$TRACE/set_graph_function'"
Which trace clock should I use?
Inspect the available tracers and clocks first:
cat "$TRACE/available_tracers"
cat "$TRACE/trace_clock"
Pick one clock and keep it for the capture. If you need to compare CPUs, use a clock that produces coherent timestamps across them. To align with an application, add an explicit marker. Don’t assume its wall clock matches the trace clock.
You can also set the per-CPU buffer through buffer_size_kb. Larger buffers retain more history and consume more kernel memory. Size it for the incident window instead of allocating blindly.
The Linux kernel tracing documentation lists the tracefs files and tracer behavior from the source that owns them.
Follow the slow kernel path with ftrace

A count tells you which syscall is expensive. Ftrace shows which kernel functions consumed the time.
Use function graph tracing only after you have a likely entry function. First, confirm that the function exists in this kernel:
TRACE=/sys/kernel/tracing
FUNC=vfs_read
grep -w "$FUNC" "$TRACE/available_filter_functions"
Kernel function names change across versions and configurations. If the lookup returns nothing, inspect the available list. Then choose the function that matches your captured path.
Then restrict the graph to the function and process:
echo function_graph | sudo tee "$TRACE/current_tracer"
echo "$FUNC" | sudo tee "$TRACE/set_graph_function"
echo "$PID" | sudo tee "$TRACE/set_ftrace_pid"
echo 1 | sudo tee "$TRACE/tracing_on"
Reproduce the pause, stop tracing, and read the buffer:
echo 0 | sudo tee "$TRACE/tracing_on"
sudo cat "$TRACE/trace"
The function graph shows nested calls and time spent beneath each function. That can expose a filesystem lock, block-layer wait, network path, or security hook under the original syscall.
Reset the tracer when you finish:
echo nop | sudo tee "$TRACE/current_tracer"
sudo sh -c ": > '$TRACE/set_ftrace_pid'"
sudo sh -c ": > '$TRACE/set_graph_function'"
sudo sh -c ": > '$TRACE/trace'"
Tracing every function across every CPU is rarely useful. The kernel is busy even when your application isn’t.
Record stable events with tracepoints and trace-cmd
Prefer tracepoints when they expose the event you need. Syscall, block, scheduler, and interrupt tracepoints have stable fields compared with internal function names.
trace-cmd wraps tracefs recording and gives you a report you can review after the incident:
sudo trace-cmd record \
-e syscalls \
-e sched \
-e block \
-e irq \
-- <reproducer>
Then read the capture:
sudo trace-cmd report
Start with fewer event groups when you already know the subsystem. For example, record syscall and block events for suspected storage latency. Add scheduler events only if the task’s wakeup behavior matters.
Be careful with PID filters. Disk completions may run in interrupt context, while filesystem work can continue in kernel workers. Filtering everything to the application PID can remove the event that explains the delay.
For a custom question that existing tracepoints cannot answer, move to a small probe. The guide on building a focused eBPF trace shows the right scope: one hook, one measurement, one answer.
Interrupt-disabled and preemption latency
Syscall duration and interrupt latency are different failure modes. A task can enter the kernel normally and then lose time. Another kernel path may keep interrupts disabled or prevent preemption.
Check which latency tracers the kernel provides:
TRACE=/sys/kernel/tracing
cat "$TRACE/available_tracers"
For interrupt-disabled latency, use irqsoff if listed:
echo 0 | sudo tee "$TRACE/tracing_on"
echo irqsoff | sudo tee "$TRACE/current_tracer"
echo 0 | sudo tee "$TRACE/tracing_max_latency"
echo 1 | sudo tee "$TRACE/tracing_on"
Reproduce the spike, stop tracing, and inspect the saved worst case:
echo 0 | sudo tee "$TRACE/tracing_on"
sudo cat "$TRACE/trace"
Use preemptoff for long preemption-disabled sections. Use preemptirqsoff when you need the combined case. The trace header reports the measured delay, while the function entries identify the kernel path responsible.
These tracers add overhead and can alter timing. Keep the capture bounded, and reset current_tracer to nop afterward.
A long irqsoff trace points at kernel or driver behavior. It does not prove the original syscall performed expensive work.
Measure wakeup-to-running delay with perf sched

Use perf sched when a task wakes promptly but waits before running. That gap belongs to scheduler latency, run-queue contention, CPU placement, or throttling.
Record the workload:
sudo perf sched record -- <reproducer>
Then report per-task scheduling latency:
sudo perf sched latency
perf sched latency reports per-task scheduling latencies and related scheduling properties. Check which tasks wait longest, how often they wait, and which CPUs run them.
For a timeline view, use:
sudo perf sched timehist
The time history shows wakeups, context switches, migrations, and runtime placement. It is useful when the average looks harmless but one migration or run-queue delay matches the application pause.
Say the process spends a long time inside read(). Scheduler data may show that it woke after I/O completion and then waited for CPU time. That is a different fix from storage tuning.
Correlate calls, kernel events, and logs
One suspicious line is not a diagnosis. Build a chain from the application event to the syscall, kernel activity, and final wakeup.
Use application logs to mark the operation. Record strace with absolute timestamps. Meanwhile, write a marker into tracefs around the reproduction:
TRACE=/sys/kernel/tracing
echo "repro-start" | sudo tee "$TRACE/trace_marker"
<reproducer>
echo "repro-end" | sudo tee "$TRACE/trace_marker"
Tracefs timestamps usually use a kernel clock, while application logs may use wall time. The markers give you a shared boundary without pretending those clocks are identical.
How do I line up the evidence?
Work through it in order:
- Find the slow request in the application log.
- Find the syscall active during that request.
- Check its return value, duration, and file descriptor.
- Find matching scheduler, block, IRQ, or function events.
- Read
journalctland the kernel ring buffer for errors in the same window.
For kernel messages, use a bounded time range:
journalctl -k --since "<start-time>" --until "<end-time>"
A useful diagnosis explains the entire delay. For example, read() blocked and block events showed a delayed request. The task then woke, and perf sched showed run-queue delay before it resumed. Each tool owns one part of that story.
Validate the original latency mechanism
Repeat the exact workload and the same measurements after the change. If you change both the workload and the tracer, you lose the comparison.
Check every point below. Latency that moved somewhere else looks a lot like latency that got fixed:
- The original syscall consumes less total time.
- Call volume did not move into another syscall.
- Scheduler delay did not shift to another CPU.
- A queue did not grow elsewhere in the path.
- Errors and retries did not increase.
- Application latency improved in the same operation that first exposed the problem.
Also run an untraced baseline. Tracing overhead can hide an improvement or create one by changing scheduling and timing.
The fix is complete when the measured mechanism changes and the user-visible pause follows it. A quieter graph by itself proves very little.
FAQ
Can I trace syscall latency inside a container without the host PID?
Yes. Use a cgroup-aware BCC or eBPF tracer and filter on the container’s cgroup. That keeps up with the workload as processes fork and exit, which a single PID filter never will.
If you need strace, enter the container’s PID namespace or map its process to the host PID first. Attaching to the wrong namespace is a good way to trace a process that has the right number and nothing else in common.
Why does tracefs show no events even as root?
Check available_events, available_tracers, and the running kernel configuration. The event may be disabled at build time, unavailable in that kernel, or blocked by a lockdown policy. Lockdown is the one people forget, so read /sys/kernel/security/lockdown before you rebuild anything.
Also confirm that tracing_on is enabled and no stale PID or event filter remains. Old filters survive long enough to waste an evening.
Can a virtual machine hide the real latency source?
Yes. The guest can show a runnable task waiting without revealing why the host withheld CPU time. Host scheduling, storage contention, and CPU steal time sit outside the guest kernel’s trace. If top in the guest shows a nonzero st value, the host is taking CPU back, and no guest tracer will name the culprit.
Collect the guest trace first, then compare it with host scheduler and hypervisor data. A complete guest trace can still end at the virtualization boundary.
What should I do if the latency disappears under tracing?
Use a lighter event-based recorder and keep the event set narrow. BCC histograms, selected tracepoints, and a bounded trace-cmd capture disturb the workload less than full strace or broad function graph tracing.
Also preserve a pre-trigger buffer where possible. If starting the tracer changes the behavior, the act of attaching is now part of the bug.
