diff mbox series

[V9,2/2] Adjust objdump start/end range per map pgoff parameter

Message ID 6107521c4fb1d4ba2da57a6d81c17b54f259feac.1728599785.git.scclevenger@os.amperecomputing.com (mailing list archive)
State New, archived
Headers show
Series arm-cs-trace-disasm.py/perf must accommodate non-zero DSO text offset | expand

Commit Message

Steve Clevenger Oct. 11, 2024, 5:17 p.m. UTC
Extract map_pgoff parameter from the dictionary, and adjust start/end
range passed to objdump based on the value.

A zero start_addr is filtered to prevent output of dso address range
check failures. This script repeatedly sees a zero value passed
in for
      start_addr = cpu_data[str(cpu) + 'addr']

These zero values are not a new problem. The start_addr/stop_addr warning
clutters the instruction trace output, hence this change.

Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
---
 tools/perf/scripts/python/arm-cs-trace-disasm.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Leo Yan Oct. 17, 2024, 11:01 a.m. UTC | #1
On 10/11/24 18:17, Steve Clevenger wrote:> 
> Extract map_pgoff parameter from the dictionary, and adjust start/end
> range passed to objdump based on the value.
> 
> A zero start_addr is filtered to prevent output of dso address range
> check failures. This script repeatedly sees a zero value passed
> in for
>       start_addr = cpu_data[str(cpu) + 'addr']
> 
> These zero values are not a new problem. The start_addr/stop_addr warning
> clutters the instruction trace output, hence this change.
> 
> Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
> ---
>   tools/perf/scripts/python/arm-cs-trace-disasm.py | 16 +++++++++++-----
>   1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> index 7aff02d84ffb..e29a4035723c 100755
> --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
> +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> @@ -187,6 +187,10 @@ def process_event(param_dict):
>          dso_start = get_optional(param_dict, "dso_map_start")
>          dso_end = get_optional(param_dict, "dso_map_end")
>          symbol = get_optional(param_dict, "symbol")
> +       map_pgoff = get_optional(param_dict, "map_pgoff")
> +       # check for valid map offset
> +       if (str(map_pgoff) == '[unknown]'):
> +               map_pgoff = 0

I tried to apply this patch, it reports warning:

Applying: Adjust objdump start/end range per map pgoff parameter
.git/rebase-apply/patch:16: space before tab in indent.
                 map_pgoff = 0
warning: 1 line applied after fixing whitespace errors.

This means it has unexpected spaces in above line.


When applying patches, I found the prefix is missed in the subject:

   perf scripts python cs-etm: Adjust objdump start/end range per map pgoff parameter

With above fixing:

Reviewed-by: Leo Yan <leo.yan@arm.com>

  
>          cpu = sample["cpu"]
>          ip = sample["ip"]
> @@ -243,9 +247,10 @@ def process_event(param_dict):
>          # Record for previous sample packet
>          cpu_data[str(cpu) + 'addr'] = addr
> 
> -       # Handle CS_ETM_TRACE_ON packet if start_addr=0 and stop_addr=4
> -       if (start_addr == 0 and stop_addr == 4):
> -               print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
> +       # Filter out zero start_address. Optionally identify CS_ETM_TRACE_ON packet
> +       if (start_addr == 0):
> +               if ((stop_addr == 4) and (options.verbose == True)):
> +                       print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
>                  return
> 
>          if (start_addr < int(dso_start) or start_addr > int(dso_end)):
> @@ -262,13 +267,14 @@ def process_event(param_dict):
>                  # vm_start to zero.
>                  if (dso == "[kernel.kallsyms]" or dso_start == 0x400000):
>                          dso_vm_start = 0
> +                       map_pgoff = 0
>                  else:
>                          dso_vm_start = int(dso_start)
> 
>                  dso_fname = get_dso_file_path(dso, dso_bid)
>                  if path.exists(dso_fname):
> -                       print_disam(dso_fname, dso_vm_start, start_addr, stop_addr)
> +                       print_disam(dso_fname, dso_vm_start, start_addr + map_pgoff, stop_addr + map_pgoff)
>                  else:
> -                       print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso, start_addr, stop_addr))
> +                       print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso, start_addr + map_pgoff, stop_addr + map_pgoff))
> 
>          print_srccode(comm, param_dict, sample, symbol, dso)
> --
> 2.44.0
>
Namhyung Kim Oct. 17, 2024, 6:28 p.m. UTC | #2
Hi Leo,

On Thu, Oct 17, 2024 at 12:01:28PM +0100, Leo Yan wrote:
> On 10/11/24 18:17, Steve Clevenger wrote:>
> > Extract map_pgoff parameter from the dictionary, and adjust start/end
> > range passed to objdump based on the value.
> > 
> > A zero start_addr is filtered to prevent output of dso address range
> > check failures. This script repeatedly sees a zero value passed
> > in for
> >       start_addr = cpu_data[str(cpu) + 'addr']
> > 
> > These zero values are not a new problem. The start_addr/stop_addr warning
> > clutters the instruction trace output, hence this change.
> > 
> > Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
> > ---
> >   tools/perf/scripts/python/arm-cs-trace-disasm.py | 16 +++++++++++-----
> >   1 file changed, 11 insertions(+), 5 deletions(-)
> > 
> > diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> > index 7aff02d84ffb..e29a4035723c 100755
> > --- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
> > +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
> > @@ -187,6 +187,10 @@ def process_event(param_dict):
> >          dso_start = get_optional(param_dict, "dso_map_start")
> >          dso_end = get_optional(param_dict, "dso_map_end")
> >          symbol = get_optional(param_dict, "symbol")
> > +       map_pgoff = get_optional(param_dict, "map_pgoff")
> > +       # check for valid map offset
> > +       if (str(map_pgoff) == '[unknown]'):
> > +               map_pgoff = 0
> 
> I tried to apply this patch, it reports warning:
> 
> Applying: Adjust objdump start/end range per map pgoff parameter
> .git/rebase-apply/patch:16: space before tab in indent.
>                 map_pgoff = 0
> warning: 1 line applied after fixing whitespace errors.
> 
> This means it has unexpected spaces in above line.
> 
> 
> When applying patches, I found the prefix is missed in the subject:
> 
>   perf scripts python cs-etm: Adjust objdump start/end range per map pgoff parameter

It could simply be "perf script cs-etm:" but it's up to you. :)

> 
> With above fixing:
> 
> Reviewed-by: Leo Yan <leo.yan@arm.com>

Thanks for your review!

Steve, can you please send v10 with the fixes?

Thanks,
Namhyung

> 
> >          cpu = sample["cpu"]
> >          ip = sample["ip"]
> > @@ -243,9 +247,10 @@ def process_event(param_dict):
> >          # Record for previous sample packet
> >          cpu_data[str(cpu) + 'addr'] = addr
> > 
> > -       # Handle CS_ETM_TRACE_ON packet if start_addr=0 and stop_addr=4
> > -       if (start_addr == 0 and stop_addr == 4):
> > -               print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
> > +       # Filter out zero start_address. Optionally identify CS_ETM_TRACE_ON packet
> > +       if (start_addr == 0):
> > +               if ((stop_addr == 4) and (options.verbose == True)):
> > +                       print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
> >                  return
> > 
> >          if (start_addr < int(dso_start) or start_addr > int(dso_end)):
> > @@ -262,13 +267,14 @@ def process_event(param_dict):
> >                  # vm_start to zero.
> >                  if (dso == "[kernel.kallsyms]" or dso_start == 0x400000):
> >                          dso_vm_start = 0
> > +                       map_pgoff = 0
> >                  else:
> >                          dso_vm_start = int(dso_start)
> > 
> >                  dso_fname = get_dso_file_path(dso, dso_bid)
> >                  if path.exists(dso_fname):
> > -                       print_disam(dso_fname, dso_vm_start, start_addr, stop_addr)
> > +                       print_disam(dso_fname, dso_vm_start, start_addr + map_pgoff, stop_addr + map_pgoff)
> >                  else:
> > -                       print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso, start_addr, stop_addr))
> > +                       print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso, start_addr + map_pgoff, stop_addr + map_pgoff))
> > 
> >          print_srccode(comm, param_dict, sample, symbol, dso)
> > --
> > 2.44.0
> >
Leo Yan Oct. 17, 2024, 9:56 p.m. UTC | #3
On Thu, Oct 17, 2024 at 11:28:06AM -0700, Namhyung Kim wrote:

[...]

> > When applying patches, I found the prefix is missed in the subject:
> >
> >   perf scripts python cs-etm: Adjust objdump start/end range per map pgoff parameter
> 
> It could simply be "perf script cs-etm:" but it's up to you. :)

Yeah, this is fine for me.

Thanks,
Leo
diff mbox series

Patch

diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py
index 7aff02d84ffb..e29a4035723c 100755
--- a/tools/perf/scripts/python/arm-cs-trace-disasm.py
+++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py
@@ -187,6 +187,10 @@  def process_event(param_dict):
 	dso_start = get_optional(param_dict, "dso_map_start")
 	dso_end = get_optional(param_dict, "dso_map_end")
 	symbol = get_optional(param_dict, "symbol")
+	map_pgoff = get_optional(param_dict, "map_pgoff")
+	# check for valid map offset
+	if (str(map_pgoff) == '[unknown]'):
+	 	map_pgoff = 0
 
 	cpu = sample["cpu"]
 	ip = sample["ip"]
@@ -243,9 +247,10 @@  def process_event(param_dict):
 	# Record for previous sample packet
 	cpu_data[str(cpu) + 'addr'] = addr
 
-	# Handle CS_ETM_TRACE_ON packet if start_addr=0 and stop_addr=4
-	if (start_addr == 0 and stop_addr == 4):
-		print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
+	# Filter out zero start_address. Optionally identify CS_ETM_TRACE_ON packet
+	if (start_addr == 0):
+		if ((stop_addr == 4) and (options.verbose == True)):
+			print("CPU%d: CS_ETM_TRACE_ON packet is inserted" % cpu)
 		return
 
 	if (start_addr < int(dso_start) or start_addr > int(dso_end)):
@@ -262,13 +267,14 @@  def process_event(param_dict):
 		# vm_start to zero.
 		if (dso == "[kernel.kallsyms]" or dso_start == 0x400000):
 			dso_vm_start = 0
+			map_pgoff = 0
 		else:
 			dso_vm_start = int(dso_start)
 
 		dso_fname = get_dso_file_path(dso, dso_bid)
 		if path.exists(dso_fname):
-			print_disam(dso_fname, dso_vm_start, start_addr, stop_addr)
+			print_disam(dso_fname, dso_vm_start, start_addr + map_pgoff, stop_addr + map_pgoff)
 		else:
-			print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso, start_addr, stop_addr))
+			print("Failed to find dso %s for address range [ 0x%x .. 0x%x ]" % (dso, start_addr + map_pgoff, stop_addr + map_pgoff))
 
 	print_srccode(comm, param_dict, sample, symbol, dso)