Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tests timechart: Add a perf timechart test

Basic coverage for `perf timechart` doing a record and then a basic
sanity test of the generated SVG file.

Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
279385cf 75e96173

+67
+67
tools/perf/tests/shell/timechart.sh
··· 1 + #!/bin/bash 2 + # perf timechart tests 3 + # SPDX-License-Identifier: GPL-2.0 4 + 5 + set -e 6 + 7 + err=0 8 + perfdata=$(mktemp /tmp/__perf_timechart_test.perf.data.XXXXX) 9 + output=$(mktemp /tmp/__perf_timechart_test.output.XXXXX.svg) 10 + 11 + cleanup() { 12 + rm -f "${perfdata}" 13 + rm -f "${output}" 14 + trap - EXIT TERM INT 15 + } 16 + 17 + trap_cleanup() { 18 + echo "Unexpected signal in ${FUNCNAME[1]}" 19 + cleanup 20 + exit 1 21 + } 22 + trap trap_cleanup EXIT TERM INT 23 + 24 + test_timechart() { 25 + echo "Basic perf timechart test" 26 + 27 + # Try to record timechart data. 28 + # perf timechart record uses system-wide recording and specific tracepoints. 29 + # If it fails (e.g. permissions, missing tracepoints), skip the test. 30 + if ! perf timechart record -o "${perfdata}" true > /dev/null 2>&1; then 31 + echo "Basic perf timechart test [Skipped: perf timechart record failed (permissions/events?)]" 32 + return 33 + fi 34 + 35 + # Generate the timechart 36 + if ! perf timechart -i "${perfdata}" -o "${output}" > /dev/null 2>&1; then 37 + echo "Basic perf timechart test [Failed: perf timechart command failed]" 38 + err=1 39 + return 40 + fi 41 + 42 + # Check if output file exists and is not empty 43 + if [ ! -s "${output}" ]; then 44 + echo "Basic perf timechart test [Failed: output file is empty or missing]" 45 + err=1 46 + return 47 + fi 48 + 49 + # Check if it looks like an SVG 50 + if ! grep -q "svg" "${output}"; then 51 + echo "Basic perf timechart test [Failed: output doesn't look like SVG]" 52 + err=1 53 + return 54 + fi 55 + 56 + echo "Basic perf timechart test [Success]" 57 + } 58 + 59 + if ! perf check feature -q libtraceevent ; then 60 + echo "perf timechart is not supported. Skip." 61 + cleanup 62 + exit 2 63 + fi 64 + 65 + test_timechart 66 + cleanup 67 + exit $err