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@gmail.com>
---
.../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 *
+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
--
2.34.1
On Mon, Jul 10, 2023 at 4:10 PM Anup Sharma <anupnewsmail@gmail.com> 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@gmail.com> > --- > .../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 >
On Wed, Jul 12, 2023 at 10:01 AM Ian Rogers <irogers@google.com> wrote: > > On Mon, Jul 10, 2023 at 4:10 PM Anup Sharma <anupnewsmail@gmail.com> 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@gmail.com> > > --- > > .../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 I believe the events are guaranteed time ordered in perf script. The ordered_event logic handles this, but I likely haven't got a full grasp on all the corners of it. You can always assert the behavior (comments with guarantees :-) ): assert start_time <= time_stamp, "Events aren't time ordered" Thanks, Ian > Thanks, > Ian > > > -- > > 2.34.1 > >
On Wed, Jul 12, 2023 at 10:03:57AM -0700, Ian Rogers wrote: > On Wed, Jul 12, 2023 at 10:01 AM Ian Rogers <irogers@google.com> wrote: > > > > On Mon, Jul 10, 2023 at 4:10 PM Anup Sharma <anupnewsmail@gmail.com> 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@gmail.com> > > > --- > > > .../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. > > Sure. I will add it. > > > +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 Sure. I will change it. > I believe the events are guaranteed time ordered in perf script. The > ordered_event logic handles this, but I likely haven't got a full > grasp on all the corners of it. You can always assert the behavior > (comments with guarantees :-) ): > > assert start_time <= time_stamp, "Events aren't time ordered" I dont think assert is usefull here as start_time will be initialized and assigned only once for all the process event triggers. So, the significance of assert is not clear to me. > Thanks, > Ian > > > Thanks, > > Ian > > > > > -- > > > 2.34.1 > > >
© 2016 - 2025 Red Hat, Inc.