From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Clark Williams <williams@redhat.com>,
linux-perf-users@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Athira Rajeev <atrajeev@linux.ibm.com>
Subject: [PATCH v3 14/18] perf tests kmem: Add a basic perf kmem test
Date: Wed, 2 Dec 2026 09:14:30 -0300 [thread overview]
Message-ID: <20261202121434.2224-15-acme@kernel.org> (raw)
In-Reply-To: <20261202121434.2224-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Exercise the slab and page allocators, their sort, caller and
allocation views, the live page stats and the time filter.
Reviewed-by: Athira Rajeev <atrajeev@linux.ibm.com>
Tested-by: Athira Rajeev <atrajeev@linux.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/kmem.sh | 222 +++++++++++++++++++++++++++++++++
1 file changed, 222 insertions(+)
create mode 100755 tools/perf/tests/shell/kmem.sh
diff --git a/tools/perf/tests/shell/kmem.sh b/tools/perf/tests/shell/kmem.sh
new file mode 100755
index 0000000000000000..196f1a723930161b
--- /dev/null
+++ b/tools/perf/tests/shell/kmem.sh
@@ -0,0 +1,222 @@
+#!/bin/bash
+# perf kmem tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+# Root permissions required for tracing events.
+if [ "$(id -u)" != 0 ]; then
+ echo "[Skip] No root permission"
+ exit 2
+fi
+
+# Without libtraceevent cmd_kmem is a stub that fails instead of
+# reporting the tracepoints below as unavailable.
+if ! perf check feature -q libtraceevent; then
+ echo "[Skip] No libtraceevent support"
+ exit 2
+fi
+
+if [ ! -e /sys/kernel/tracing/events/kmem/kmalloc ] &&
+ [ ! -e /sys/kernel/debug/tracing/events/kmem/kmalloc ]; then
+ echo "[Skip] No kmem tracepoints"
+ exit 2
+fi
+
+err=0
+slabdata=$(mktemp /tmp/__perf_test_kmem.slab.XXXXX)
+pagedata=$(mktemp /tmp/__perf_test_kmem.page.XXXXX)
+out=$(mktemp /tmp/__perf_test_kmem.out.XXXXX)
+
+cleanup() {
+ rm -f "${slabdata}" "${slabdata}".old
+ rm -f "${pagedata}" "${pagedata}".old
+ rm -f "${out}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+fail() {
+ echo "$1 [Failed: $2]"
+ cat "${out}"
+ err=1
+}
+
+test_kmem_record() {
+ echo "Kmem record"
+ perf kmem record -o "${slabdata}" -- sleep 1
+ echo "Kmem record [Success]"
+}
+
+test_kmem_slab_stat() {
+ echo "Kmem slab stat"
+ if ! perf kmem -i "${slabdata}" stat > "${out}" 2>&1; then
+ fail "Kmem slab stat" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab stat" "missing summary"
+ return
+ fi
+ echo "Kmem slab stat [Success]"
+}
+
+test_kmem_slab_stat_options() {
+ echo "Kmem slab stat options"
+ if ! perf kmem -i "${slabdata}" --sort hit,bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem slab stat options" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab stat options" "missing summary"
+ return
+ fi
+ echo "Kmem slab stat options [Success]"
+}
+
+test_kmem_page_record() {
+ echo "Kmem page record"
+ perf kmem --page record -c 1000 -o "${pagedata}" -- sleep 1
+ echo "Kmem page record [Success]"
+}
+
+test_kmem_page_stat() {
+ echo "Kmem page stat"
+ if ! perf kmem --page -i "${pagedata}" stat > "${out}" 2>&1; then
+ fail "Kmem page stat" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page stat" "missing summary"
+ return
+ fi
+ echo "Kmem page stat [Success]"
+}
+
+test_kmem_page_stat_options() {
+ echo "Kmem page stat options"
+ if ! perf kmem --page -i "${pagedata}" --sort order,gfp --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page stat options" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page stat options" "missing summary"
+ return
+ fi
+ echo "Kmem page stat options [Success]"
+}
+
+test_kmem_slab_alloc() {
+ echo "Kmem slab alloc stats"
+ if ! perf kmem -i "${slabdata}" --alloc --sort bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem slab alloc stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab alloc stats" "missing summary"
+ return
+ fi
+ echo "Kmem slab alloc stats [Success]"
+}
+
+test_kmem_page_caller() {
+ echo "Kmem page caller stats"
+ if ! perf kmem --page -i "${pagedata}" --caller --sort bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page caller stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page caller stats" "missing summary"
+ return
+ fi
+ echo "Kmem page caller stats [Success]"
+}
+
+test_kmem_page_caller_raw() {
+ echo "Kmem page caller raw ip stats"
+ if ! perf kmem --page -i "${pagedata}" --caller --raw-ip --sort callsite --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page caller raw ip stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page caller raw ip stats" "missing summary"
+ return
+ fi
+ echo "Kmem page caller raw ip stats [Success]"
+}
+
+test_kmem_page_alloc() {
+ echo "Kmem page alloc stats"
+ if ! perf kmem --page -i "${pagedata}" --alloc --sort bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page alloc stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page alloc stats" "missing summary"
+ return
+ fi
+ echo "Kmem page alloc stats [Success]"
+}
+
+test_kmem_page_live() {
+ echo "Kmem page live stats"
+ if ! perf kmem --page --live -i "${pagedata}" --sort page --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page live stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page live stats" "missing summary"
+ return
+ fi
+ echo "Kmem page live stats [Success]"
+}
+
+test_kmem_slab_caller() {
+ echo "Kmem slab caller stats"
+ if ! perf kmem -i "${slabdata}" --caller --sort callsite --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem slab caller stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab caller stats" "missing summary"
+ return
+ fi
+ echo "Kmem slab caller stats [Success]"
+}
+
+test_kmem_time_filter() {
+ echo "Kmem time filter"
+ if ! perf kmem -i "${slabdata}" --time 0, stat > "${out}" 2>&1; then
+ fail "Kmem time filter" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem time filter" "missing summary"
+ return
+ fi
+ echo "Kmem time filter [Success]"
+}
+
+test_kmem_record
+test_kmem_slab_stat
+test_kmem_slab_stat_options
+test_kmem_slab_alloc
+test_kmem_slab_caller
+test_kmem_time_filter
+test_kmem_page_record
+test_kmem_page_stat
+test_kmem_page_stat_options
+test_kmem_page_caller
+test_kmem_page_caller_raw
+test_kmem_page_alloc
+test_kmem_page_live
+
+cleanup
+exit $err
--
2.56.0
next prev parent reply other threads:[~2026-12-02 12:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:14 [PATCH v3 00/18] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 01/18] perf kmem: Use the allocation order when matching page frees Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 02/18] perf tests top: Pin the ring buffer size Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 03/18] perf tests sched: Exercise the sched views and options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 04/18] perf tests help: Add a basic perf help test Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 05/18] perf tests config: Exercise the config file and list options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 06/18] perf tests script: Exercise the list, fields and dump options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 07/18] perf tests sort: Exercise the report and diff sort keys Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 08/18] perf tests diff: Exercise the output options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 09/18] perf tests annotate: Exercise the output and filter options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 10/18] perf tests report: Exercise the output and format options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 11/18] perf tests record: Exercise more record options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 12/18] perf tests trace: Exercise the tracing options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 13/18] perf tests timechart: Exercise the report options Arnaldo Carvalho de Melo
2026-12-02 12:14 ` Arnaldo Carvalho de Melo [this message]
2026-12-02 12:14 ` [PATCH v3 15/18] perf tests bench: Add smoke tests for perf bench Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 16/18] perf tests lock: Exercise perf lock report and info Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 17/18] perf tests probe: Exercise the variable and line listing Arnaldo Carvalho de Melo
2026-12-02 12:14 ` [PATCH v3 18/18] perf tests report: Exercise the TUI browsers Arnaldo Carvalho de Melo
2026-12-02 12:30 ` [PATCH v3 00/18] perf tests: Add coverage for the untested perf subcommands sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202121434.2224-15-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=atrajeev@linux.ibm.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.