From: Ravi Bangoria <ravi.bangoria@amd.com>
To: Ian Rogers <irogers@google.com>
Cc: "acme@kernel.org" <acme@kernel.org>,
"namhyung@kernel.org" <namhyung@kernel.org>,
"peterz@infradead.org" <peterz@infradead.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"eranian@google.com" <eranian@google.com>,
"kan.liang@linux.intel.com" <kan.liang@linux.intel.com>,
"jolsa@kernel.org" <jolsa@kernel.org>,
"adrian.hunter@intel.com" <adrian.hunter@intel.com>,
"alexander.shishkin@linux.intel.com"
<alexander.shishkin@linux.intel.com>,
"bp@alien8.de" <bp@alien8.de>,
"mark.rutland@arm.com" <mark.rutland@arm.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-perf-users@vger.kernel.org"
<linux-perf-users@vger.kernel.org>,
"Shukla, Santosh" <Santosh.Shukla@amd.com>,
"Narayan, Ananth" <Ananth.Narayan@amd.com>,
"Das1, Sandipan" <Sandipan.Das@amd.com>,
"Bangoria, Ravikumar" <ravi.bangoria@amd.com>
Subject: Re: [RFC] perf script AMD/IBS: Add scripts to show function/instruction level granular profile
Date: Mon, 27 Jan 2025 14:29:31 +0530 [thread overview]
Message-ID: <c8a2d737-1c27-461e-8609-99a448004ca4@amd.com> (raw)
In-Reply-To: <CAP-5=fW4Vzhs7BOeAhom5csRUk+UkCFdc1H9HT4AhMdei8FRKQ@mail.gmail.com>
Hi Ian,
>> diff --git a/tools/perf/scripts/python/amd-ibs-fetch-metrics.py b/tools/perf/scripts/python/amd-ibs-fetch-metrics.py
>> new file mode 100644
>> index 000000000000..63a91843585f
>> --- /dev/null
>> +++ b/tools/perf/scripts/python/amd-ibs-fetch-metrics.py
>> @@ -0,0 +1,219 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +#
>> +# Copyright (C) 2025 Advanced Micro Devices, Inc.
>> +#
>> +# Print various metric events at function granularity using AMD IBS Fetch PMU.
>> +
>> +from __future__ import print_function
>
> I think at some future point we should go through the perf python code
> and strip out python2-isms like this. There's no need to add more as
> python2 doesn't exist any more.
Ack.
>> +allowed_sort_keys = ("nr_samples", "oc_miss", "ic_miss", "l2_miss", "l3_miss", "abort", "l1_itlb_miss", "l2_itlb_miss")
>> +default_sort_order = ("nr_samples",) # Trailing comman is needed for single member tuple
>
> Given these are lists of strings, I'm not sure why you're trying to use tuples?
I'm not a python expert, but AFAIU, tuple is the data-structure for
immutable list. No?
>> +data = {};
>> +
>> +def init_data_element(symbol, cpumode, dso):
>
> Consider types and using mypy? Fwiw, I sent this (reviewed but not merged):
> https://lore.kernel.org/lkml/20241025172303.77538-1-irogers@google.com/
> which adds build support for mypy and pylint, although not enabled by
> default given the number of errors.
Sure. I'll explore this.
>> +def get_cpumode(cpumode):
>> + if (cpumode == 1):
>> + return 'K'
>> + if (cpumode == 2):
>> + return 'U'
>> + if (cpumode == 3):
>> + return 'H'
>> + if (cpumode == 4):
>> + return 'GK'
>> + if (cpumode == 5):
>> + return 'GU'
>> + return '?'
>
> Perhaps use a dictionary? Something like:
> ```
> def get_cpumode(cpumode: int)- > str:
> modes = {
> 1: 'K',
> 2: 'U',
> 3: 'H',
> 4: 'GK',
> 5: 'GU',
> }
> return modes[cpumode] if cpumode in modes else '?'
> ```
+1
>> + print("%-45s| %7d | %7d (%6.2f%%) %7d (%6.2f%%) %7d (%6.2f%%) %7d (%6.2f%%)"
>> + " %7d %7d | %7d (%6.2f%%) | %7d (%6.2f%%) %7d (%6.2f%%) | %s" %
>> + (symbol_cpumode, d[1]['nr_samples'], d[1]['oc_miss'], oc_miss_perc,
>> + d[1]['ic_miss'], ic_miss_perc, d[1]['l2_miss'], l2_miss_perc,
>> + d[1]['l3_miss'], l3_miss_perc, pct_lat, avg_lat, d[1]['abort'],
>> + abort_perc, d[1]['l1_itlb_miss'], l1_itlb_miss_perc,
>> + d[1]['l2_itlb_miss'], l2_itlb_miss_perc, d[1]['dso']))
>
> Fwiw, I'm letting gemini convert these to f-strings. If I trust AI this becomes:
> ```
> print(f"{symbol_cpumode:<45s}| {d[1]['nr_samples']:7d} |
> {d[1]['oc_miss']:7d} ({oc_miss_perc:6.2f}%) {d[1]['ic_miss']:7d}
> ({ic_miss_perc:6.2f}%) {d[1]['l2_miss']:7d} ({l2_miss_perc:6.2f}%)
> {d[1]['l3_miss']:7d} ({l3_miss_perc:6.2f}%) {pct_lat:7d} {avg_lat:7d}
> | {d[1]['abort']:7d} ({abort_perc:6.2f}%) | {d[1]['l1_itlb_miss']:7d}
> ({l1_itlb_miss_perc:6.2f}%) {d[1]['l2_itlb_miss']:7d}
> ({l2_itlb_miss_perc:6.2f}%) | {d[1]['dso']:s}")
> ```
> But given that keeping all these prints in sync is error prone, I
> think a helper function is the way to go.
Sure. will convert it into a helper function.
>> +annotate_symbol = None
>> +annodate_dso = None
>
> annotate_dso?
Ack.
>> +def disassemble_symbol(symbol, dso):
>> + global data
>> +
>> + readelf = subprocess.Popen(["readelf", "-WsC", "--sym-base=16", dso],
>> + stdout=subprocess.PIPE, text=True)
>> + grep = subprocess.Popen(["grep", "-w", symbol], stdin=readelf.stdout,
>> + stdout=subprocess.PIPE, text=True)
>> + output, error = grep.communicate()
>
> Perhaps the pyelftools would be better here?
> https://eli.thegreenplace.net/2012/01/06/pyelftools-python-library-for-parsing-elf-and-dwarf
Right, using library instead of hardcoded shell command would be
better.
Thanks for the feedback,
Ravi
next prev parent reply other threads:[~2025-01-27 8:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 6:06 [RFC] perf script AMD/IBS: Add scripts to show function/instruction level granular profile Ravi Bangoria
2025-01-24 16:16 ` Ian Rogers
2025-01-27 8:59 ` Ravi Bangoria [this message]
2025-01-24 17:25 ` Namhyung Kim
2025-01-27 8:56 ` Ravi Bangoria
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=c8a2d737-1c27-461e-8609-99a448004ca4@amd.com \
--to=ravi.bangoria@amd.com \
--cc=Ananth.Narayan@amd.com \
--cc=Sandipan.Das@amd.com \
--cc=Santosh.Shukla@amd.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox