diff mbox series

[V4,3/4] Add map pgoff to python dictionary based on MAPPING_TYPE

Message ID 04a8a735c1a3794c64f1687fc8963d5713807b95.1724820993.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 Aug. 28, 2024, 5:09 a.m. UTC
Add map_pgoff parameter to python dictionary so it can be seen by the
python script, arm-cs-trace-disasm.py. map_pgoff is forced to zero in
the dictionary if file type is MAPPING_TYPE__IDENTITY. Otherwise, the
map_pgoff value is directly added to the dictionary.

Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
---
 .../util/scripting-engines/trace-event-python.c     | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Leo Yan Aug. 28, 2024, 8:44 a.m. UTC | #1
On 8/28/2024 6:09 AM, Steve Clevenger wrote:
> 
> Add map_pgoff parameter to python dictionary so it can be seen by the
> python script, arm-cs-trace-disasm.py. map_pgoff is forced to zero in
> the dictionary if file type is MAPPING_TYPE__IDENTITY. Otherwise, the
> map_pgoff value is directly added to the dictionary.
> 
> Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
> ---
>  .../util/scripting-engines/trace-event-python.c     | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index 6971dd6c231f..b8da0ea5e55c 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -798,7 +798,8 @@ static int set_regs_in_dict(PyObject *dict,
>  static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
>                             const char *dso_field, const char *dso_bid_field,
>                             const char *dso_map_start, const char *dso_map_end,
> -                           const char *sym_field, const char *symoff_field)
> +                           const char *sym_field, const char *symoff_field,
> +                           const char *map_pgoff)
>  {
>         char sbuild_id[SBUILD_ID_SIZE];
> 
> @@ -814,6 +815,12 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
>                         PyLong_FromUnsignedLong(map__start(al->map)));
>                 pydict_set_item_string_decref(dict, dso_map_end,
>                         PyLong_FromUnsignedLong(map__end(al->map)));
> +               if (al->map->mapping_type == MAPPING_TYPE__DSO)
> +                       pydict_set_item_string_decref(dict, map_pgoff,
> +                                       PyLong_FromUnsignedLongLong(al->map->pgoff));
> +               else
> +                       pydict_set_item_string_decref(dict, map_pgoff,
> +                               PyLong_FromUnsignedLongLong(0));

Indention is inconsistent. Please keep the same format.

>         }
>         if (al->sym) {
>                 pydict_set_item_string_decref(dict, sym_field,
> @@ -900,7 +907,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
>         pydict_set_item_string_decref(dict, "comm",
>                         _PyUnicode_FromString(thread__comm_str(al->thread)));
>         set_sym_in_dict(dict, al, "dso", "dso_bid", "dso_map_start", "dso_map_end",
> -                       "symbol", "symoff");
> +                       "symbol", "symoff", "map_pgoff");
> 
>         pydict_set_item_string_decref(dict, "callchain", callchain);
> 
> @@ -925,7 +932,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
>                         PyBool_FromLong(1));
>                 set_sym_in_dict(dict_sample, addr_al, "addr_dso", "addr_dso_bid",
>                                 "addr_dso_map_start", "addr_dso_map_end",
> -                               "addr_symbol", "addr_symoff");
> +                               "addr_symbol", "addr_symoff", "map_pgoff");

This dict variable is for data address parsing. For alignment the naming, here
can change it as "addr_map_pgoff"?

Please note, from my understanding, this renaming will not impact the
sequential change as the python script should only use the dso dict. Please
confirm at your side.

With above changes:

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

>         }
> 
>         if (sample->flags)
> --
> 2.25.1
>
Steve Clevenger Aug. 28, 2024, 9:26 p.m. UTC | #2
On 8/28/2024 1:44 AM, Leo Yan wrote:
> On 8/28/2024 6:09 AM, Steve Clevenger wrote:
>>
>> Add map_pgoff parameter to python dictionary so it can be seen by the
>> python script, arm-cs-trace-disasm.py. map_pgoff is forced to zero in
>> the dictionary if file type is MAPPING_TYPE__IDENTITY. Otherwise, the
>> map_pgoff value is directly added to the dictionary.
>>
>> Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
>> ---
>>  .../util/scripting-engines/trace-event-python.c     | 13 ++++++++++---
>>  1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
>> index 6971dd6c231f..b8da0ea5e55c 100644
>> --- a/tools/perf/util/scripting-engines/trace-event-python.c
>> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
>> @@ -798,7 +798,8 @@ static int set_regs_in_dict(PyObject *dict,
>>  static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
>>                             const char *dso_field, const char *dso_bid_field,
>>                             const char *dso_map_start, const char *dso_map_end,
>> -                           const char *sym_field, const char *symoff_field)
>> +                           const char *sym_field, const char *symoff_field,
>> +                           const char *map_pgoff)
>>  {
>>         char sbuild_id[SBUILD_ID_SIZE];
>>
>> @@ -814,6 +815,12 @@ static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
>>                         PyLong_FromUnsignedLong(map__start(al->map)));
>>                 pydict_set_item_string_decref(dict, dso_map_end,
>>                         PyLong_FromUnsignedLong(map__end(al->map)));
>> +               if (al->map->mapping_type == MAPPING_TYPE__DSO)
>> +                       pydict_set_item_string_decref(dict, map_pgoff,
>> +                                       PyLong_FromUnsignedLongLong(al->map->pgoff));
>> +               else
>> +                       pydict_set_item_string_decref(dict, map_pgoff,
>> +                               PyLong_FromUnsignedLongLong(0));
> 
> Indention is inconsistent. Please keep the same format.

Corrected.

> 
>>         }
>>         if (al->sym) {
>>                 pydict_set_item_string_decref(dict, sym_field,
>> @@ -900,7 +907,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
>>         pydict_set_item_string_decref(dict, "comm",
>>                         _PyUnicode_FromString(thread__comm_str(al->thread)));
>>         set_sym_in_dict(dict, al, "dso", "dso_bid", "dso_map_start", "dso_map_end",
>> -                       "symbol", "symoff");
>> +                       "symbol", "symoff", "map_pgoff");
>>
>>         pydict_set_item_string_decref(dict, "callchain", callchain);
>>
>> @@ -925,7 +932,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
>>                         PyBool_FromLong(1));
>>                 set_sym_in_dict(dict_sample, addr_al, "addr_dso", "addr_dso_bid",
>>                                 "addr_dso_map_start", "addr_dso_map_end",
>> -                               "addr_symbol", "addr_symoff");
>> +                               "addr_symbol", "addr_symoff", "map_pgoff");
> 
> This dict variable is for data address parsing. For alignment the naming, here
> can change it as "addr_map_pgoff"?
> 
> Please note, from my understanding, this renaming will not impact the
> sequential change as the python script should only use the dso dict. Please
> confirm at your side.

Renamed as "addr_map_pgoff" to match local call convention. The dso
dictionary is not affected. See V5 patch series.

> 
> With above changes:
> 
> Reviewed-by: Leo Yan <leo.yan@arm.com>
> 
>>         }
>>
>>         if (sample->flags)
>> --
>> 2.25.1
>>
diff mbox series

Patch

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 6971dd6c231f..b8da0ea5e55c 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -798,7 +798,8 @@  static int set_regs_in_dict(PyObject *dict,
 static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
 			    const char *dso_field, const char *dso_bid_field,
 			    const char *dso_map_start, const char *dso_map_end,
-			    const char *sym_field, const char *symoff_field)
+			    const char *sym_field, const char *symoff_field,
+			    const char *map_pgoff)
 {
 	char sbuild_id[SBUILD_ID_SIZE];
 
@@ -814,6 +815,12 @@  static void set_sym_in_dict(PyObject *dict, struct addr_location *al,
 			PyLong_FromUnsignedLong(map__start(al->map)));
 		pydict_set_item_string_decref(dict, dso_map_end,
 			PyLong_FromUnsignedLong(map__end(al->map)));
+		if (al->map->mapping_type == MAPPING_TYPE__DSO)
+			pydict_set_item_string_decref(dict, map_pgoff,
+					PyLong_FromUnsignedLongLong(al->map->pgoff));
+		else
+			pydict_set_item_string_decref(dict, map_pgoff,
+				PyLong_FromUnsignedLongLong(0));
 	}
 	if (al->sym) {
 		pydict_set_item_string_decref(dict, sym_field,
@@ -900,7 +907,7 @@  static PyObject *get_perf_sample_dict(struct perf_sample *sample,
 	pydict_set_item_string_decref(dict, "comm",
 			_PyUnicode_FromString(thread__comm_str(al->thread)));
 	set_sym_in_dict(dict, al, "dso", "dso_bid", "dso_map_start", "dso_map_end",
-			"symbol", "symoff");
+			"symbol", "symoff", "map_pgoff");
 
 	pydict_set_item_string_decref(dict, "callchain", callchain);
 
@@ -925,7 +932,7 @@  static PyObject *get_perf_sample_dict(struct perf_sample *sample,
 			PyBool_FromLong(1));
 		set_sym_in_dict(dict_sample, addr_al, "addr_dso", "addr_dso_bid",
 				"addr_dso_map_start", "addr_dso_map_end",
-				"addr_symbol", "addr_symoff");
+				"addr_symbol", "addr_symoff", "map_pgoff");
 	}
 
 	if (sample->flags)