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