Files
linux/tools/perf/tests/shell/sched.sh
Aaron Tomlin bf10e6ee2a perf sched latency: Add histogram and time interval options
While 'perf sched latency' reports task runtime and delay statistics
(average and maximum delay), it does not provide a visual representation
of how task wait times are distributed across latency ranges between
snapshots (start and finish of the analysis window).

The --histogram option collects CPU wait latencies (time between when
a task becomes runnable and when it gets scheduled onto a CPU) into 22
latency buckets, displaying an ASCII bar chart distribution.

The --hist-mode option configures the bucketing scheme:
  - log (default). Logarithmic latency buckets ranging from
    sub-microsecond (< 1 us) up to >= 1.05 seconds

  - linear. Equal-width linear latency buckets
    (i.e., 100 us steps up to >= 2.1 ms)

The --time option allows filtering trace event processing to a
specific time interval [start,stop].

Example histogram output excerpt:

    ❯ sudo perf sched latency --histogram --CPU 0

     CPU Wait Latency Distribution Histogram (between snapshots) (total samples: 36114)
     -------------------------------------------------------------------
      Latency Range    |      Count |    Pct | Histogram Graph
     -------------------------------------------------------------------
      < 1 us           |         17 |   0.0% | #
      2 - 4 us         |        673 |   1.9% | #
      4 - 8 us         |       6237 |  17.3% | ######
      8 - 16 us        |       3224 |   8.9% | ###
      16 - 32 us       |       1388 |   3.8% | #
      32 - 64 us       |        709 |   2.0% | #
      64 - 128 us      |        690 |   1.9% | #
      128 - 256 us     |        789 |   2.2% | #
      256 - 512 us     |        541 |   1.5% | #
      512 - 1024 us    |       2256 |   6.2% | ##
      1 - 2 ms         |       3577 |   9.9% | ###
      2 - 4 ms         |      13259 |  36.7% | ##############
      4 - 8 ms         |       2523 |   7.0% | ##
      8 - 16 ms        |        222 |   0.6% | #
      16 - 32 ms       |         10 |   0.0% | #
      >= 1.05 s        |          3 |   0.0% | #
     -------------------------------------------------------------------

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
2026-08-07 10:56:23 -07:00

146 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# perf sched tests
# SPDX-License-Identifier: GPL-2.0
set -e
if [ "$(id -u)" != 0 ]; then
echo "[Skip] No root permission"
exit 2
fi
err=0
perfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX)
PID1=0
PID2=0
cleanup() {
rm -f "${perfdata}"
rm -f "${perfdata}".old
trap - EXIT TERM INT
}
trap_cleanup() {
echo "Unexpected signal in ${FUNCNAME[1]}"
cleanup
exit 1
}
trap trap_cleanup EXIT TERM INT
start_noploops() {
# Start two noploop workloads on CPU0 to trigger scheduling.
perf test -w noploop 10 &
PID1=$!
taskset -pc 0 $PID1
perf test -w noploop 10 &
PID2=$!
taskset -pc 0 $PID2
if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID1/status"
then
echo "Sched [Error taskset did not work for the 1st noploop ($PID1)]"
grep Cpus_allowed /proc/$PID1/status
err=1
fi
if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID2/status"
then
echo "Sched [Error taskset did not work for the 2nd noploop ($PID2)]"
grep Cpus_allowed /proc/$PID2/status
err=1
fi
}
cleanup_noploops() {
kill "$PID1" "$PID2" || true
}
test_sched_record() {
echo "Sched record"
start_noploops
perf sched record --no-inherit -o "${perfdata}" sleep 1
cleanup_noploops
}
test_sched_latency() {
echo "Sched latency"
if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop
then
echo "Sched latency [Failed missing output]"
err=1
fi
}
test_sched_latency_histogram() {
echo "Sched latency histogram"
if ! perf sched latency -H -i "${perfdata}" | grep -q "Latency Distribution Histogram"
then
echo "Sched latency histogram [Failed missing log histogram]"
err=1
fi
if ! perf sched latency --histogram --hist-mode linear -i "${perfdata}" | grep -q "Latency Distribution Histogram"
then
echo "Sched latency histogram [Failed missing linear histogram]"
err=1
fi
}
test_sched_latency_time() {
echo "Sched latency time filter"
if ! perf sched latency --time 0, -i "${perfdata}" | grep -q perf-noploop
then
echo "Sched latency time filter [Failed missing output]"
err=1
fi
}
test_sched_script() {
echo "Sched script"
if ! perf sched script -i "${perfdata}" | grep -q perf-noploop
then
echo "Sched script [Failed missing output]"
err=1
fi
}
test_sched_map() {
echo "Sched map"
if ! perf sched map -i "${perfdata}" | grep -q perf-noploop
then
echo "Sched map [Failed missing output]"
err=1
fi
}
test_sched_timehist() {
echo "Sched timehist"
if ! perf sched timehist -i "${perfdata}" | grep -q perf-noploop
then
echo "Sched timehist [Failed missing output]"
err=1
fi
}
test_sched_record
test_sched_latency
test_sched_latency_histogram
test_sched_latency_time
test_sched_script
test_sched_map
test_sched_timehist
cleanup
exit $err