[0/1] tools: perf: Expose sample ID / stream ID to python scripts

Message ID 20240123103137.1890779-1-ben.gainey@arm.com
Headers
Series tools: perf: Expose sample ID / stream ID to python scripts |

Message

Ben Gainey Jan. 23, 2024, 10:31 a.m. UTC
  This patch modifies the perf python scripting engine so that the ID and
STREAM_ID are exposed as part of the sample so that they may be
correlated to the corresponding throttle/unthrottle event (for example).

NB: For scripts where perf_db_export_mode = True, this may be a breaking
change depending on how the script is constructed. Each field is passed
to `sample_table` as an argument so any script that is written as:

    def sample_table(db_id, evsel_id, machine_id, ..., cyc_cnt, flags)

will now fail due to the changed number of arguments with:

    TypeError: sample_table() takes 25 positional arguments but 27 were given

Scripts that use:

    def sample_table(*args)

or some variation thereof will not be affected.

When `perf_db_export_mode = False`, the script should be unaffected as
all the arguments are inserted into a dictionary.

The export-to-xxx.py scripts use the (..., *x) form so are not affected.


Ben Gainey (1):
  tools: perf: Expose sample ID / stream ID to python scripts

 tools/perf/Documentation/perf-script-python.txt        | 4 ++--
 tools/perf/util/scripting-engines/trace-event-python.c | 8 +++++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
  

Comments

Adrian Hunter Jan. 23, 2024, 11:32 a.m. UTC | #1
On 23/01/24 12:31, Ben Gainey wrote:
> This patch modifies the perf python scripting engine so that the ID and
> STREAM_ID are exposed as part of the sample so that they may be
> correlated to the corresponding throttle/unthrottle event (for example).
> 
> NB: For scripts where perf_db_export_mode = True, this may be a breaking
> change depending on how the script is constructed. Each field is passed
> to `sample_table` as an argument so any script that is written as:
> 
>     def sample_table(db_id, evsel_id, machine_id, ..., cyc_cnt, flags)
> 
> will now fail due to the changed number of arguments with:
> 
>     TypeError: sample_table() takes 25 positional arguments but 27 were given
> 
> Scripts that use:
> 
>     def sample_table(*args)
> 
> or some variation thereof will not be affected.

That is documented in tools/perf/Documentation/db-export.txt.  It was
anticipated that more arguments could be added, so that should be OK.

> 
> When `perf_db_export_mode = False`, the script should be unaffected as
> all the arguments are inserted into a dictionary.
> 
> The export-to-xxx.py scripts use the (..., *x) form so are not affected.
> 
> 
> Ben Gainey (1):
>   tools: perf: Expose sample ID / stream ID to python scripts
> 
>  tools/perf/Documentation/perf-script-python.txt        | 4 ++--
>  tools/perf/util/scripting-engines/trace-event-python.c | 8 +++++++-
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
  
Namhyung Kim Feb. 3, 2024, 1:54 a.m. UTC | #2
Hello,

On Tue, Jan 23, 2024 at 2:32 AM Ben Gainey <ben.gainey@arm.com> wrote:
>
> This patch modifies the perf python scripting engine so that the ID and
> STREAM_ID are exposed as part of the sample so that they may be
> correlated to the corresponding throttle/unthrottle event (for example).
>
> NB: For scripts where perf_db_export_mode = True, this may be a breaking
> change depending on how the script is constructed. Each field is passed
> to `sample_table` as an argument so any script that is written as:
>
>     def sample_table(db_id, evsel_id, machine_id, ..., cyc_cnt, flags)
>
> will now fail due to the changed number of arguments with:
>
>     TypeError: sample_table() takes 25 positional arguments but 27 were given
>
> Scripts that use:
>
>     def sample_table(*args)
>
> or some variation thereof will not be affected.
>
> When `perf_db_export_mode = False`, the script should be unaffected as
> all the arguments are inserted into a dictionary.
>
> The export-to-xxx.py scripts use the (..., *x) form so are not affected.

As long as all in-tree users are fine, I think it's ok.

Thanks,
Namhyung

>
>
> Ben Gainey (1):
>   tools: perf: Expose sample ID / stream ID to python scripts
>
>  tools/perf/Documentation/perf-script-python.txt        | 4 ++--
>  tools/perf/util/scripting-engines/trace-event-python.c | 8 +++++++-
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> --
> 2.43.0
>
  
Namhyung Kim Feb. 6, 2024, 12:19 a.m. UTC | #3
On Tue, 23 Jan 2024 10:31:36 +0000, Ben Gainey wrote:
> This patch modifies the perf python scripting engine so that the ID and
> STREAM_ID are exposed as part of the sample so that they may be
> correlated to the corresponding throttle/unthrottle event (for example).
> 
> NB: For scripts where perf_db_export_mode = True, this may be a breaking
> change depending on how the script is constructed. Each field is passed
> to `sample_table` as an argument so any script that is written as:
> 
> [...]

Applied to perf-tools-next, thanks!

Best regards,