From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795634665; b=16cWbNeESjsoOsd+n7ZqmmKraBzTyZsE7eYxgJLxhQb9qhMvK950eVfGU/Demm5bz8YX WHJo61iB81wigfZEh0Ntk1tZggPeamFJOaa6z7QS7JGQVeS4bBAKUQkyWhTwTG8aPUNId 2H+rF9UA6CCKFyuTTUi8+fNsndpVbnoHqVVp2iB9Sc1tqtERMrwVpMIVZp7HyQrmll5jU hHh12q3bYw658qQBPzEHSaFahRxsniw/Qj7MT43f3mU4SoZTnRY/8uYjNc4GY2jwHehzu xH4SCDZ74vg6stkPcW/GgnOo0eWbk3wERTkQ8VyKQKSQp6p02spy5LtAv2khuLXvw5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795634665; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=KhTN5DwTEuHP0LJt6CxqEOr/MSwp+5y/47uYA/rgoQY=; b=lhk2js6tgvgwdFTgzcr6sRyF3Sd+ObiZtqHLV2rkp6hlZS4AP+4kHnu6sGmj3npUCrnc VLMa1IDj3CJ8+BD+NP5gRHrrr5Tk3ysoX5t0jJVZwvR6IiFxcWo/clN6BO+c3Rlc4edqR EP0eLHaMxtxqi8AZdQIsxrt7QFhwQpXF3uo42+RyzNf3rxWUKjt1RK/+PDrTq7EPGGMp/ OL/dZXS7oVxs14yqkiks23ZzoZ4W0ec8Rl3tFyV0wXrhCCzeHfl0TXftfZGdVrMmnlyLI /iP1XWhuJEfEeP4JaYwRQPyo1yiVBWZ93jL3fraJ7VQfemeClodkIL5g9M3jd9hS12w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Kk9JA/jQ"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F62A606A6B6; Wed, 25 Nov 2026 19:24:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Kk9JA/jQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22B871F000F4; Wed, 25 Nov 2026 19:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795634664; bh=KhTN5DwTEuHP0LJt6CxqEOr/MSwp+5y/47uYA/rgoQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Kk9JA/jQ9St3ErgFiymrnnCNn4Vr3sZBz2QciAcVeqmbkKSV5tFE65VXcAfzcp+P7 +/0wUcEbVwL8ILuYZMbVGT6Gi135eekEZ+jYLExat2Aiw7R0rCOXTO/dRQI+mts6GN SIpFBoLCdu4oO6nKwORe1hzit3O9OGF9lPnoYHRbO8VzyqBqawCa1ePyd29RUWzmi+ R3IgN3ZfssqrWGfe7qxDeOfgdfYX2LL57vfV38yNNtiMJPYaeHWRsvdlIZENr9HAYq 0MzZq3qmkwc1TDwClUQjmiljnmrS6MAZVFXJMArZ511CQTDlpYw19rSqTVdJM2dYdA Wg2n3WwMPwe+A== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v13 19/19] perf scripts: Add a coverage table Date: Wed, 25 Nov 2026 16:23:12 -0300 Message-ID: <20261125192312.34134-20-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125192312.34134-1-acme@kernel.org> References: <20261125192312.34134-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Arnaldo Carvalho de Melo Render the report of the last coverage run as a table of the files with the most uncovered lines, biggest gap first; --all lists every file and -f picks files explicitly, failing when a requested file has no coverage data. Lines and funcs are printed as executed over total, each followed by a coverage bar, both metrics in the same format. coverage.sh prints the table when a run finishes; it is also wired as 'make -C tools/perf coverage-table', to print just the table. It only reads coverage.sh's report.txt, so the measurement and the table are reviewed and changed separately. For example, with --top 4 on a test suite run: $ bash tools/perf/scripts/coverage-table.sh --cov-dir=/tmp/opencode/cov-more-cov --top 4 tools/perf (no tests/ or bench/), 100+ executable lines: the 4 biggest uncovered gaps, start here when adding coverage tests. --all for every file: make -C tools/perf coverage-table COVERAGE_ARGS="--cov-dir /tmp/opencode/cov-more-cov --all" ┌──────────────────────────────────────────┬───────────────┬───────────────────────────┬───────────────┬───────────────────────────┐ │ File │ Lines │ Coverage │ Funcs │ Coverage │ ├──────────────────────────────────────────┼───────────────┼───────────────────────────┼───────────────┼───────────────────────────┤ │ builtin-trace.c │ 155/3661 │ ░░░░░░░░░░░░░░░░░░ 4.2% │ 1/198 │ ░░░░░░░░░░░░░░░░░░ 0.5% │ │ util/intel-pt.c │ 0/3237 │ ░░░░░░░░░░░░░░░░░░ 0.0% │ 0/142 │ ░░░░░░░░░░░░░░░░░░ 0.0% │ │ util/intel-pt-decoder/intel-pt-decoder.c │ 0/3208 │ ░░░░░░░░░░░░░░░░░░ 0.0% │ 0/119 │ ░░░░░░░░░░░░░░░░░░ 0.0% │ │ builtin-sched.c │ 737/3737 │ ███░░░░░░░░░░░░░░░ 19.7% │ 16/141 │ ██░░░░░░░░░░░░░░░░ 11.4% │ ├──────────────────────────────────────────┼───────────────┼───────────────────────────┼───────────────┼───────────────────────────┤ │ TOTAL (perf) │ 75546/174407 │ ███████░░░░░░░░░░░ 43.3% │ 5044/9362 │ █████████░░░░░░░░░ 53.9% │ └──────────────────────────────────────────┴───────────────┴───────────────────────────┴───────────────┴───────────────────────────┘ Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 5 +- tools/perf/Makefile.perf | 3 +- tools/perf/scripts/coverage-table.sh | 339 +++++++++++++++++++++++++++ tools/perf/scripts/coverage.sh | 14 +- 4 files changed, 356 insertions(+), 5 deletions(-) create mode 100755 tools/perf/scripts/coverage-table.sh diff --git a/tools/perf/Makefile b/tools/perf/Makefile index d9ad8c0d796c2852..5da13faa1c18b510 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -150,6 +150,9 @@ coverage-prep: coverage: @./scripts/coverage.sh $(coverage_o) $(COVERAGE_ARGS) +coverage-table: + @./scripts/coverage-table.sh $(coverage_o) $(COVERAGE_ARGS) + # # All other targets get passed through: # @@ -157,4 +160,4 @@ coverage: $(print_msg) $(make) -.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers coverage coverage-prep +.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball check-headers sync-headers coverage coverage-prep coverage-table diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 1b4efe6254fa0370..6427d3a012c465d1 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -878,7 +878,8 @@ help: @echo ' sync-headers - sync those header copies with the kernel, creating commits' @echo ' (SYNC_HEADERS_ARGS="..." passes options to the script)' @echo ' coverage-prep - build perf with clang coverage, ready for a root test run' - @echo ' coverage - build perf with clang coverage, run the tests and report' + @echo ' coverage - build perf with clang coverage, run the tests, report and show the table' + @echo ' coverage-table - print a text table of the last coverage run' @echo ' (O=DIR uses an existing build dir; COVERAGE_ARGS="..." passes options)' diff --git a/tools/perf/scripts/coverage-table.sh b/tools/perf/scripts/coverage-table.sh new file mode 100755 index 0000000000000000..e382307a447657f2 --- /dev/null +++ b/tools/perf/scripts/coverage-table.sh @@ -0,0 +1,339 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026, Red Hat Inc, Arnaldo Carvalho de Melo +# +# Render the report of the last coverage run as a text table, like pahole's +# coverage_table.py. Without -f the default is the tool's files, not its +# tests and benches, with the most uncovered lines, biggest gap first; +# --all lists every tools/perf file, most covered first. The total is the +# tools/perf subtotal, the run summary has the whole report. + +set -euo pipefail + +PERF_DIR=$(cd "$(dirname "$0")/.." && pwd -P) +TOOLS_DIR=$(cd "$PERF_DIR/.." && pwd -P) + +BUILD_DIR=${BUILD_DIR:-} +COV_DIR=${COV_DIR:-} +TOP=${TOP:-20} +MIN_LINES=${MIN_LINES:-100} +TABLE_ALL=0 +FOCUS=() + +die() { printf '\033[0;31merror:\033[0m %s\n' "$*" >&2; exit 1; } + +usage() +{ + cat < 0 && + (path == f || path == g || $1 == f)) { + printf "%s\t%s\t%d\t%d\t%.2f\t%s\t%d\t%s\n", + path, $8, $8 - $9, $9, $10, $5, $5 - $6, $7 + exit + } + }' "$1" +} + +table_rows() +{ + local file + + if [ ${#FOCUS[@]} -gt 0 ]; then + local row rows= missing=() + + for file in "${FOCUS[@]}"; do + row=$(table_row "$REPORT" "$file") + if [ -z "$row" ]; then + missing+=("$file") + continue + fi + rows+=$row$'\n' + done + if [ ${#missing[@]} -gt 0 ]; then + printf 'error: no coverage data in %s for:\n' "$REPORT" >&2 + printf ' %s\n' "${missing[@]}" >&2 + exit 1 + fi + printf '%s' "$rows" | sort -t$'\t' -k5,5gr + return + fi + + if [ "$TABLE_ALL" = 1 ]; then + awk -v build="$BUILD_AWK_DIR" "$AWK_PERF"' + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) && + !generated($1) && $8 > 0 { + printf "%s\t%s\t%d\t%d\t%.2f\t%s\t%d\t%s\n", + perf_relpath($1), $8, $8 - $9, $9, $10, + $5, $5 - $6, $7 + }' "$REPORT" | + sort -t$'\t' -k5,5gr + return + fi + + awk -v min="$MIN_LINES" -v build="$BUILD_AWK_DIR" "$AWK_PERF"' + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) && + !generated($1) && $8 >= min && $9 > 0 && + perf_relpath($1) !~ /^(tests|bench)\// { + printf "%s\t%s\t%d\t%d\t%.2f\t%s\t%d\t%s\n", + perf_relpath($1), $8, $8 - $9, $9, $10, + $5, $5 - $6, $7 + }' "$REPORT" | + sort -t$'\t' -k4,4nr | + if [ "$TOP" -gt 0 ]; then + sed -n "1,${TOP}p" + else + cat + fi +} + +# The table is about tools/perf, so its total is the tools/perf subtotal; +# the run summary prints the whole report, generated files included. +table_total() +{ + awk -v build="$BUILD_AWK_DIR" "$AWK_PERF"' + $1 != "TOTAL" && !generated($1) && + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) { + lines += $8 + missed += $9 + funcs += $5 + funcs_missed += $6 + } + END { + printf "%d\t%d\t%d\t%.2f\t%d\t%d\t%.2f%%\n", + lines, lines - missed, missed, + lines ? 100 * (lines - missed) / lines : 0, + funcs, funcs - funcs_missed, + funcs ? 100 * (funcs - funcs_missed) / funcs : 0 + }' "$REPORT" +} + +# At most three lines: what the table shows and how to see every file. +table_caption() +{ + if [ ${#FOCUS[@]} -gt 0 ]; then + echo "files requested with -f." + elif [ "$TABLE_ALL" = 1 ]; then + echo "every tools/perf file, tests and benches included, most covered first." + return + elif [ "$TOP" -gt 0 ] && [ "$MIN_LINES" -gt 0 ]; then + printf "tools/perf (no tests/ or bench/), %d+ executable lines:\n" "$MIN_LINES" + echo "the $TOP biggest uncovered gaps, start here when adding coverage tests." + elif [ "$TOP" -gt 0 ]; then + printf "tools/perf (no tests/ or bench/): the %d files with the\n" "$TOP" + echo "biggest uncovered gaps, start here when adding coverage tests." + elif [ "$MIN_LINES" -gt 0 ]; then + printf "tools/perf (no tests/ or bench/), %d+ executable lines:\n" "$MIN_LINES" + echo "start here when adding coverage tests, biggest gaps first." + else + echo "tools/perf (no tests/ or bench/), biggest gaps first." + fi + local cmd='make -C tools/perf coverage-table' + local cov_args='--all' + [ "$BUILD_DIR" = "$PERF_DIR" ] || cmd+=" O=$BUILD_DIR" + [ "$COV_DIR" = "$BUILD_DIR/cov" ] || + cov_args="--cov-dir $COV_DIR --all" + printf '%s %s COVERAGE_ARGS="%s"\n' '--all for every file:' "$cmd" "$cov_args" +} + +print_table() +{ + local rows total path lines hit missed pct funcs funcs_hit func_cov func_pct + local row_fmt w d15 d27 d_file + + rows=$(table_rows) + [ -n "$rows" ] || + die "no coverage data in $REPORT for the requested files" + total=$(table_total) + [ -n "$total" ] || die "no coverage data in $REPORT" + + table_caption + printf '\n' + + w=12 # "TOTAL (perf)" + while IFS=$'\t' read -r path _; do + if [ ${#path} -gt "$w" ]; then + w=${#path} + fi + done <<< "$rows" + + d15=$(dashes 15) + d27=$(dashes 27) + d_file=$(dashes $((w + 2))) + + # Lines and Funcs print the executed over the total, each with a + # coverage bar of its own, both in the same format. The bar cell + # holds 18 blocks, a space, the %5.1f value and the sign, one + # space of padding on each side: 27 columns. + printf '┌%s┬%s┬%s┬%s┬%s┐\n' "$d_file" "$d15" "$d27" "$d15" "$d27" + printf '│ %-*s │ %13s │ %s │ %13s │ %s │\n' \ + "$w" "File" "Lines" "$(center Coverage 25)" \ + "Funcs" "$(center Coverage 25)" + printf '├%s┼%s┼%s┼%s┼%s┤\n' "$d_file" "$d15" "$d27" "$d15" "$d27" + + row_fmt=$(printf '│ %%-%ds │ %%13s │ %%s %%5.1f%%%% │ %%13s │' "$w") + row_fmt+=' %s %5.1f%% │\n' + + while IFS=$'\t' read -r path lines hit missed pct funcs funcs_hit func_cov; do + func_pct=${func_cov%\%} + printf "$row_fmt" "$path" "$hit/$lines" \ + "$(bar "$pct" 18)" "$pct" \ + "$funcs_hit/$funcs" "$(bar "$func_pct" 18)" "$func_pct" + done <<< "$rows" + + printf '├%s┼%s┼%s┼%s┼%s┤\n' "$d_file" "$d15" "$d27" "$d15" "$d27" + while IFS=$'\t' read -r lines hit missed pct funcs funcs_hit func_cov; do + func_pct=${func_cov%\%} + printf "$row_fmt" "TOTAL (perf)" "$hit/$lines" \ + "$(bar "$pct" 18)" "$pct" \ + "$funcs_hit/$funcs" "$(bar "$func_pct" 18)" "$func_pct" + done <<< "$total" + printf '└%s┴%s┴%s┴%s┴%s┘\n' "$d_file" "$d15" "$d27" "$d15" "$d27" +} + +# The table code parses llvm-cov's decimal points; keep the numeric locale +# fixed. +export LC_ALL=C +print_table diff --git a/tools/perf/scripts/coverage.sh b/tools/perf/scripts/coverage.sh index e9a4cf807850e1c7..bb075c9a54e820cd 100755 --- a/tools/perf/scripts/coverage.sh +++ b/tools/perf/scripts/coverage.sh @@ -3,8 +3,9 @@ # # Copyright (C) 2026, Red Hat Inc, Arnaldo Carvalho de Melo # -# Build perf with clang source based coverage, run the perf test suite and -# report line coverage. +# Build perf with clang source based coverage, run the perf test suite, +# report line coverage and the table of the files with the most uncovered +# lines. coverage-table.sh renders that table from the last report alone. # The build goes into tools/perf and the profiles and report into # tools/perf/cov; -b and -c override them, following perf's O= layout. # --prep stops after the instrumented build, for running the tests later as @@ -44,7 +45,9 @@ usage() Usage: scripts/coverage.sh [options] [test name fragment...] Builds perf with clang source based coverage, runs the complete perf test -suite and reports line coverage. Use -t to run a subset. +suite, reports line coverage and the files with the most uncovered lines. +Use -t to run a subset; scripts/coverage-table.sh renders the table again +with other options. Options: -b, --build-dir DIR existing perf build directory (default: $PERF_DIR) @@ -64,6 +67,7 @@ Through make: make -C tools/perf coverage make -C tools/perf coverage-prep O=/tmp/build/perf-coverage sudo make -C tools/perf coverage O=/tmp/build/perf-coverage + make -C tools/perf coverage-table O=/tmp/build/perf-coverage EOF } @@ -482,5 +486,9 @@ render_report print_summary update_baseline +printf "\n" +"$PERF_DIR/scripts/coverage-table.sh" --build-dir "$BUILD_DIR" \ + --cov-dir "$COV_DIR" || warn "could not render the coverage table" + printf "\nReport: %s\n" "$REPORT" exit "$test_status" -- 2.56.0