From nobody Sat Feb 7 21:30:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43471EB64D9 for ; Fri, 16 Jun 2023 03:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240617AbjFPDQM (ORCPT ); Thu, 15 Jun 2023 23:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242057AbjFPDPJ (ORCPT ); Thu, 15 Jun 2023 23:15:09 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD25297F; Thu, 15 Jun 2023 20:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686885301; x=1718421301; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=815xhyqBJVkUcTa8Wnb+dhIrshSrEjCMA06FFhOLA18=; b=OHnhaKX2p9ab1owBuTAdcbyAgIGMQH0O77JsMC9sdcNdbGrOgy9wly9i rRrqgY4hXvldSgPlsip7bEr55EG1QqhnudkSCS9E8k0mNhUn5HahCusHu 4sKflNS6O1EQVUu54BOfcXqf+8aP9d7l3VXcJxYAhOqaNSQSJoXTWD5bH qqSElxSUgRb3fMTKp8qgkEC4S8qOTLaAws5bZxgE+0STH5k1gjvI7S4QB tQAbTVWzPiPq0vkpreiAaxz/V5cSdBrPY/VzjWye9uR3LlA6wCgb49L3J Ip+tHbMdzOHWPI2pof8mcqwP0tSkkkK5UrJ3Tk2jUAbxwm1/cUxkImlZ+ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="338718222" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="338718222" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 20:14:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="825555628" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="825555628" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmsmga002.fm.intel.com with ESMTP; 15 Jun 2023 20:14:55 -0700 From: kan.liang@linux.intel.com To: acme@kernel.org, mingo@redhat.com, peterz@infradead.org, irogers@google.com, namhyung@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, eranian@google.com, ahmad.yasin@intel.com, Kan Liang Subject: [PATCH V4 4/5] perf test: Add test case for the standard perf stat output Date: Thu, 15 Jun 2023 20:14:19 -0700 Message-Id: <20230616031420.3751973-5-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230616031420.3751973-1-kan.liang@linux.intel.com> References: <20230616031420.3751973-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Kan Liang Add a new test case to verify the standard perf stat output with different options. Reviewed-by: Ian Rogers Signed-off-by: Kan Liang --- tools/perf/tests/shell/stat+std_output.sh | 108 ++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 tools/perf/tests/shell/stat+std_output.sh diff --git a/tools/perf/tests/shell/stat+std_output.sh b/tools/perf/tests/s= hell/stat+std_output.sh new file mode 100755 index 000000000000..98cc3356a04a --- /dev/null +++ b/tools/perf/tests/shell/stat+std_output.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# perf stat STD output linter +# SPDX-License-Identifier: GPL-2.0 +# Tests various perf stat STD output commands for +# default event and metricgroup + +set -e + +. $(dirname $0)/lib/stat_output.sh + +stat_output=3D$(mktemp /tmp/__perf_test.stat_output.std.XXXXX) + +event_name=3D(cpu-clock task-clock context-switches cpu-migrations page-fa= ults cycles instructions branches branch-misses stalled-cycles-frontend sta= lled-cycles-backend) +event_metric=3D("CPUs utilized" "CPUs utilized" "/sec" "/sec" "/sec" "GHz"= "insn per cycle" "/sec" "of all branches" "frontend cycles idle" "backend = cycles idle") + +metricgroup_name=3D(TopdownL1 TopdownL2) + +cleanup() { + rm -f "${stat_output}" + + trap - EXIT TERM INT +} + +trap_cleanup() { + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +function commachecker() +{ + local -i cnt=3D0 + local prefix=3D1 + + case "$1" + in "--interval") prefix=3D2 + ;; "--per-thread") prefix=3D2 + ;; "--system-wide-no-aggr") prefix=3D2 + ;; "--per-core") prefix=3D3 + ;; "--per-socket") prefix=3D3 + ;; "--per-node") prefix=3D3 + ;; "--per-die") prefix=3D3 + ;; "--per-cache") prefix=3D3 + esac + + while read line + do + # Ignore initial "started on" comment. + x=3D${line:0:1} + [ "$x" =3D "#" ] && continue + # Ignore initial blank line. + [ "$line" =3D "" ] && continue + # Ignore "Performance counter stats" + x=3D${line:0:25} + [ "$x" =3D "Performance counter stats" ] && continue + # Ignore "seconds time elapsed" and break + [[ "$line" =3D=3D *"time elapsed"* ]] && break + + main_body=3D$(echo $line | cut -d' ' -f$prefix-) + x=3D${main_body%#*} + # Check default metricgroup + y=3D$(echo $x | tr -d ' ') + [ "$y" =3D "" ] && continue + for i in "${!metricgroup_name[@]}"; do + [[ "$y" =3D=3D *"${metricgroup_name[$i]}"* ]] && break + done + [[ "$y" =3D=3D *"${metricgroup_name[$i]}"* ]] && continue + + # Check default event + for i in "${!event_name[@]}"; do + [[ "$x" =3D=3D *"${event_name[$i]}"* ]] && break + done + + [[ ! "$x" =3D=3D *"${event_name[$i]}"* ]] && { + echo "Unknown event name in $line" 1>&2 + exit 1; + } + + # Check event metric if it exists + [[ ! "$main_body" =3D=3D *"#"* ]] && continue + [[ ! "$main_body" =3D=3D *"${event_metric[$i]}"* ]] && { + echo "wrong event metric. expected ${event_metric[$i]} in $line" 1>&2 + exit 1; + } + done < "${stat_output}" + return 0 +} + +perf_cmd=3D"-o ${stat_output}" + +skip_test=3D$(check_for_topology) +check_no_args "STD" "$perf_cmd" +check_system_wide "STD" "$perf_cmd" +check_interval "STD" "$perf_cmd" +check_per_thread "STD" "$perf_cmd" +check_per_node "STD" "$perf_cmd" +if [ $skip_test -ne 1 ] +then + check_system_wide_no_aggr "STD" "$perf_cmd" + check_per_core "STD" "$perf_cmd" + check_per_cache_instance "STD" "$perf_cmd" + check_per_die "STD" "$perf_cmd" + check_per_socket "STD" "$perf_cmd" +else + echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die an= d per_socket since socket id exposed via topology is invalid" +fi +cleanup +exit 0 --=20 2.35.1