From nobody Sat Feb 7 09:20:47 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BF5E26AD9; Tue, 3 Jun 2025 06:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748931457; cv=none; b=bg0dBedv4sOYQ7tXn1qj/Lyd3GYhmJ3jRrxqlUDpuqAWr6DkwF/y7kW8mW8G0jG8w4lv02j4uZsyOg8SKnAt11z7s31uAHpZxXD4IhaxVPP5Ukdk1H2/jPsivMWcLkIObqkWLdKEMDvQtDAraopeHMfbTc91B4/9FSJ/EkiwPeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748931457; c=relaxed/simple; bh=ktVyNmKC36IoJfDT1n47jZdc8uH8RN0+HUXL0beA/Us=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KYoA4R2VCsjylzZQ3xL3Y4V4KJGMUCIXyGrAi4Pp7yFvS4rclFX9amFP0pSXvKR9yrikQmNitLFHLZ/B/uzZz3pE4AdWt2ccrCa7qAZjXW8apD/JBl5t/4d3oP89AIaqtPOjLrvvN7FttAlkogUyZ/UxCsFd4VFc6WciU6enE1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fiSUL1+e; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fiSUL1+e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1748931456; x=1780467456; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ktVyNmKC36IoJfDT1n47jZdc8uH8RN0+HUXL0beA/Us=; b=fiSUL1+eH4qWlwroz1lYFuMC4xaX2QPXyKfeAHbJVQfA7/Xk3SUdbbi1 QPJCSb8J/Ihh/JVjy/JdhiebN0nxwM86+QlIUXVgiL+ZKNMW8bBktjD5a QGLJRas6XaNKTlgpPmzFrBIk5vBZZBMcEtACVCcDRcQKecjfnMY6ijdSA jzJzUbD/g5dS+HlAQpaJEMVz5+6qVr7ujRkoUpvz9xtDT537iAiFGGM9F Lt7u/kTV8D9v/iRyxuCkqq24z3cbd0/gHPEWaut6JuhUPulLZLKtxNXgc KOLGYa0gGURE3BE5cWwqOKMZ6hR8hz83bEYmr15mwmo8O7pIRtKTNkRkD A==; X-CSE-ConnectionGUID: C39ryNPkSTm1DjihhwnoXg== X-CSE-MsgGUID: cq0GflALQNq2Gcrm8zkF7A== X-IronPort-AV: E=McAfee;i="6700,10204,11451"; a="51101230" X-IronPort-AV: E=Sophos;i="6.16,205,1744095600"; d="scan'208";a="51101230" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2025 23:17:36 -0700 X-CSE-ConnectionGUID: iqjzXgopRDis4cHMswXQlQ== X-CSE-MsgGUID: HmtBv1OfR6eADbm4x8woXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,205,1744095600"; d="scan'208";a="144638834" Received: from linux-pnp-server-27.sh.intel.com ([10.239.147.41]) by fmviesa006.fm.intel.com with ESMTP; 02 Jun 2025 23:17:31 -0700 From: Tianyou Li To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , tianyou.li@intel.com, wangyang.guo@intel.com, pan.deng@intel.com, zhiguo.zhou@intel.com, tim.c.chen@intel.com, tim.c.chen@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Minor improvements for perf script flamegraph Date: Tue, 3 Jun 2025 15:10:48 +0800 Message-ID: <20250603071048.180674-1-tianyou.li@intel.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When processing the perf data file generated with multiple events, the flamegraph script will count all the events regardless of different event names. If specify the perf data file with -i option, the script will try to read the header information regardless of the file name specified, instead it will try to access the perf.data. This patch tries to add a -e option to specify the event name that the flamegraph will be generated accordingly. If the -e option omitted, the behavior remains unchanged. If the -i option specified, the header information will be read from that file. Signed-off-by: Tianyou Li Reviewed-by: Pan Deng Reviewed-by: Zhiguo Zhou Reviewed-by: Wangyang Guo Reviewed-by: Tim Chen --- tools/perf/scripts/python/flamegraph.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts/p= ython/flamegraph.py index cf7ce8229a..eb78b93925 100755 --- a/tools/perf/scripts/python/flamegraph.py +++ b/tools/perf/scripts/python/flamegraph.py @@ -94,6 +94,11 @@ class FlameGraphCLI: return child =20 def process_event(self, event): + # ignore events where the event name does not match + # the one specified by the user + if self.args.event_name and event.get("ev_name") !=3D self.args.ev= ent_name: + return + pid =3D event.get("sample", {}).get("pid", 0) # event["dso"] sometimes contains /usr/lib/debug/lib/modules/*/vml= inux # for user-space processes; let's use pid for kernel or user-space= distinction @@ -123,8 +128,15 @@ class FlameGraphCLI: return "" =20 try: - output =3D subprocess.check_output(["perf", "report", "--heade= r-only"]) - return output.decode("utf-8") + if self.args.input: + output =3D subprocess.check_output(["perf", "script", "--h= eader-only", "-i", self.args.input]) + else: + output =3D subprocess.check_output(["perf", "report", "--h= eader-only"]) + + result =3D output.decode("utf-8") + if self.args.event_name: + result +=3D "\nFocused event: " + self.args.event_name + return result except Exception as err: # pylint: disable=3Dbroad-except print("Error reading report header: {}".format(err), file=3Dsy= s.stderr) return "" @@ -235,6 +247,11 @@ if __name__ =3D=3D "__main__": default=3DFalse, action=3D"store_true", help=3D"allow unprompted downloading of HTML templ= ate") + parser.add_argument("-e", "--event", + default=3D"", + dest=3D"event_name", + type=3Dstr, + help=3D"specify the event to generate flamegraph f= or") =20 cli_args =3D parser.parse_args() cli =3D FlameGraphCLI(cli_args) --=20 2.43.5