linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nageswara Sastry <rnsastry@linux.ibm.com>
To: Kajol Jain <kjain@linux.ibm.com>, acme@kernel.org
Cc: maddy@linux.vnet.ibm.com, atrajeev@linux.vnet.ibm.com,
	pc@us.ibm.com, linux-kernel@vger.kernel.org, jolsa@redhat.com,
	ravi.bangoria@linux.ibm.com, linux-perf-users@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] perf script python: Fix buffer size to report iregs in perf script
Date: Mon, 28 Jun 2021 12:45:36 +0530	[thread overview]
Message-ID: <46ddcac9-e115-6b96-11ec-6208bcd1c98a@linux.ibm.com> (raw)
In-Reply-To: <20210628062341.155839-1-kjain@linux.ibm.com>

Tested by creating perf-script.py using perf script
and priting the iregs. Seen more values with this patch.


Tested-by: Nageswara R Sastry <rnsastry@linux.ibm.com>

On 28/06/21 11:53 am, Kajol Jain wrote:
> Commit 48a1f565261d ("perf script python: Add more PMU fields
> to event handler dict") added functionality to report fields like
> weight, iregs, uregs etc via perf report.
> That commit predefined buffer size to 512 bytes to print those fields.
> 
> But incase of powerpc, since we added extended regs support
> in commits:
> 
> Commit 068aeea3773a ("perf powerpc: Support exposing Performance Monitor
> Counter SPRs as part of extended regs")
> Commit d735599a069f ("powerpc/perf: Add extended regs support for
> power10 platform")
> 
> Now iregs can carry more bytes of data and this predefined buffer size
> can result to data loss in perf script output.
> 
> Patch resolve this issue by making buffer size dynamic based on number
> of registers needed to print. It also changed return type for function
> "regs_map" from int to void, as the return value is not being used by
> the caller function "set_regs_in_dict".
> 
> Fixes: 068aeea3773a ("perf powerpc: Support exposing Performance Monitor
> Counter SPRs as part of extended regs")
> Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
> ---
>   .../util/scripting-engines/trace-event-python.c | 17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index 4e4aa4c97ac5..c8c9706b4643 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -687,7 +687,7 @@ static void set_sample_datasrc_in_dict(PyObject *dict,
>   			_PyUnicode_FromString(decode));
>   }
>   
> -static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
> +static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
>   {
>   	unsigned int i = 0, r;
>   	int printed = 0;
> @@ -695,7 +695,7 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
>   	bf[0] = 0;
>   
>   	if (!regs || !regs->regs)
> -		return 0;
> +		return;
>   
>   	for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
>   		u64 val = regs->regs[i++];
> @@ -704,8 +704,6 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size)
>   				     "%5s:0x%" PRIx64 " ",
>   				     perf_reg_name(r), val);
>   	}
> -
> -	return printed;
>   }
>   
>   static void set_regs_in_dict(PyObject *dict,
> @@ -713,7 +711,16 @@ static void set_regs_in_dict(PyObject *dict,
>   			     struct evsel *evsel)
>   {
>   	struct perf_event_attr *attr = &evsel->core.attr;
> -	char bf[512];
> +
> +	/*
> +	 * Here value 28 is a constant size which can be used to print
> +	 * one register value and its corresponds to:
> +	 * 16 chars is to specify 64 bit register in hexadecimal.
> +	 * 2 chars is for appending "0x" to the hexadecimal value and
> +	 * 10 chars is for register name.
> +	 */
> +	int size = __sw_hweight64(attr->sample_regs_intr) * 28;
> +	char bf[size];
>   
>   	regs_map(&sample->intr_regs, attr->sample_regs_intr, bf, sizeof(bf));
>   
> 

-- 
Thanks and Regards
R.Nageswara Sastry

  reply	other threads:[~2021-06-28  7:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  6:23 [PATCH] perf script python: Fix buffer size to report iregs in perf script Kajol Jain
2021-06-28  7:15 ` Nageswara Sastry [this message]
2021-06-28 14:49 ` Paul A. Clarke
2021-06-29  7:09   ` kajoljain
2021-07-06 11:56     ` kajoljain
2021-07-06 19:15       ` Arnaldo Carvalho de Melo
2021-07-07  5:46         ` kajoljain
2021-07-07 14:04           ` Arnaldo Carvalho de Melo

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=46ddcac9-e115-6b96-11ec-6208bcd1c98a@linux.ibm.com \
    --to=rnsastry@linux.ibm.com \
    --cc=acme@kernel.org \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=jolsa@redhat.com \
    --cc=kjain@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=pc@us.ibm.com \
    --cc=ravi.bangoria@linux.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).