Re: [PATCH v3 2/6] scripts: python: Extact necessary information from process event

From: Ian Rogers
Date: Wed Jul 12 2023 - 13:01:27 EST


On Mon, Jul 10, 2023 at 4:10 PM Anup Sharma <anupnewsmail@xxxxxxxxx> wrote:
>
> The script takes in a sample event dictionary(param_dict) and retrieves
> relevant data such as time stamp, PID, TID, thread name. Also start time
> is defined.
>
> Signed-off-by: Anup Sharma <anupnewsmail@xxxxxxxxx>
> ---
> .../perf/scripts/python/firefox-gecko-converter.py | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
> index 5b342641925c..765f1775cee5 100644
> --- a/tools/perf/scripts/python/firefox-gecko-converter.py
> +++ b/tools/perf/scripts/python/firefox-gecko-converter.py
> @@ -21,8 +21,19 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> from perf_trace_context import *
> from Core import *
>

It'd be nice to have a comment here, perhaps:
# The time stamp from the first of the time ordered events.

> +start_time = None
> +
> def trace_end():
> pass
>
> def process_event(param_dict):
> - pass
> + global start_time
> + # Extract relevant information from the event parameters. The event parameters
> + # are in a dictionary:
> + time_stamp = (param_dict['sample']['time'] // 1000) / 1000
> + pid = param_dict['sample']['pid']
> + tid = param_dict['sample']['tid']
> + thread_name = param_dict['comm']
> +
> + # Assume that start time is the time of the first event.
> + start_time = time_stamp if not start_time else start_time

I appreciate that this is one line, but it takes some getting your
head around that start_time is being assigned to itself in the common
case. I think this would be more readable as:

if not start_time:
start_time = time_stamp

Thanks,
Ian

> --
> 2.34.1
>