The script takes in a sample event dictionary(param_dict) and retrieves
relevant data such as time stamp, PID, TID, thread name, and call stack
information. If available, the call stack is parsed to include function
names and the associated DSO, which are requires for creating json schema.
Also few libaries has been included which will be used in later commit.
Signed-off-by: Anup Sharma <[email protected]>
---
.../scripts/python/firefox-gecko-converter.py | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 tools/perf/scripts/python/firefox-gecko-converter.py
diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
new file mode 100644
index 000000000000..ce663840d212
--- /dev/null
+++ b/tools/perf/scripts/python/firefox-gecko-converter.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# Usage:
+#
+# perf record -a -g -F 99 sleep 1
+# perf script firefox-gecko-converter.py
+
+from __future__ import print_function
+import os
+import sys
+import json
+from functools import reduce
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+from perf_trace_context import *
+from Core import *
+
+def process_event(param_dict):
+ time_stamp = (param_dict['sample']['time'] // 1000) / 1000
+ pid = param_dict['sample']['pid']
+ tid = param_dict['sample']['tid']
+ thread_name = param_dict['comm']
+ start_time = time_stamp if not start_time else start_time
+ if param_dict['callchain']:
+ stack = []
+ for call in param_dict['callchain']:
+ if 'sym' not in call:
+ continue
+ stack.append(call['sym']['name'] + f' (in {call["dso"]})')
+ if len(stack) != 0:
+ stack = stack[::-1]
+ else:
+ mod = param_dict['symbol'] if 'symbol' in param_dict else '[unknown]'
+ dso = param_dict['dso'] if 'dso' in param_dict else '[unknown]'
--
2.34.1
Hi Anup,
On Wed, Jul 5, 2023 at 12:42 PM Anup Sharma <[email protected]> wrote:
>
> The script takes in a sample event dictionary(param_dict) and retrieves
> relevant data such as time stamp, PID, TID, thread name, and call stack
> information. If available, the call stack is parsed to include function
> names and the associated DSO, which are requires for creating json schema.
> Also few libaries has been included which will be used in later commit.
>
> Signed-off-by: Anup Sharma <[email protected]>
> ---
> .../scripts/python/firefox-gecko-converter.py | 37 +++++++++++++++++++
> 1 file changed, 37 insertions(+)
> create mode 100644 tools/perf/scripts/python/firefox-gecko-converter.py
>
> diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
> new file mode 100644
> index 000000000000..ce663840d212
> --- /dev/null
> +++ b/tools/perf/scripts/python/firefox-gecko-converter.py
> @@ -0,0 +1,37 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Usage:
> +#
> +# perf record -a -g -F 99 sleep 1
> +# perf script firefox-gecko-converter.py
> +
> +from __future__ import print_function
Is this needed for python3?
> +import os
> +import sys
> +import json
> +from functools import reduce
> +
> +sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> +
> +from perf_trace_context import *
> +from Core import *
> +
> +def process_event(param_dict):
> + time_stamp = (param_dict['sample']['time'] // 1000) / 1000
> + pid = param_dict['sample']['pid']
> + tid = param_dict['sample']['tid']
> + thread_name = param_dict['comm']
> + start_time = time_stamp if not start_time else start_time
> + if param_dict['callchain']:
> + stack = []
> + for call in param_dict['callchain']:
> + if 'sym' not in call:
> + continue
> + stack.append(call['sym']['name'] + f' (in {call["dso"]})')
> + if len(stack) != 0:
> + stack = stack[::-1]
> + else:
> + mod = param_dict['symbol'] if 'symbol' in param_dict else '[unknown]'
Why is it 'mod' instead of 'sym' or 'func'?
Thanks,
Namhyung
> + dso = param_dict['dso'] if 'dso' in param_dict else '[unknown]'
> --
> 2.34.1
>
On Wed, Jul 05, 2023 at 10:35:02PM -0700, Namhyung Kim wrote:
> Hi Anup,
>
> On Wed, Jul 5, 2023 at 12:42 PM Anup Sharma <[email protected]> wrote:
> >
> > The script takes in a sample event dictionary(param_dict) and retrieves
> > relevant data such as time stamp, PID, TID, thread name, and call stack
> > information. If available, the call stack is parsed to include function
> > names and the associated DSO, which are requires for creating json schema.
> > Also few libaries has been included which will be used in later commit.
> >
> > Signed-off-by: Anup Sharma <[email protected]>
> > ---
> > .../scripts/python/firefox-gecko-converter.py | 37 +++++++++++++++++++
> > 1 file changed, 37 insertions(+)
> > create mode 100644 tools/perf/scripts/python/firefox-gecko-converter.py
> >
> > diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
> > new file mode 100644
> > index 000000000000..ce663840d212
> > --- /dev/null
> > +++ b/tools/perf/scripts/python/firefox-gecko-converter.py
> > @@ -0,0 +1,37 @@
> > +#!/usr/bin/env python3
I believe this is not needed as we are using perf-script-python interface.
> > +# SPDX-License-Identifier: GPL-2.0
> > +#
> > +# Usage:
> > +#
> > +# perf record -a -g -F 99 sleep 1
> > +# perf script firefox-gecko-converter.py
> > +
> > +from __future__ import print_function
>
> Is this needed for python3?
No, it is not needed. I will remove it.
>
> > +import os
> > +import sys
> > +import json
> > +from functools import reduce
> > +
> > +sys.path.append(os.environ['PERF_EXEC_PATH'] + \
> > + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
> > +
> > +from perf_trace_context import *
> > +from Core import *
> > +
> > +def process_event(param_dict):
> > + time_stamp = (param_dict['sample']['time'] // 1000) / 1000
> > + pid = param_dict['sample']['pid']
> > + tid = param_dict['sample']['tid']
> > + thread_name = param_dict['comm']
> > + start_time = time_stamp if not start_time else start_time
> > + if param_dict['callchain']:
> > + stack = []
> > + for call in param_dict['callchain']:
> > + if 'sym' not in call:
> > + continue
> > + stack.append(call['sym']['name'] + f' (in {call["dso"]})')
> > + if len(stack) != 0:
> > + stack = stack[::-1]
> > + else:
> > + mod = param_dict['symbol'] if 'symbol' in param_dict else '[unknown]'
>
> Why is it 'mod' instead of 'sym' or 'func'?
I will change it to 'func'. It will be more meaningful.
>
> Thanks,
> Namhyung
>
>
> > + dso = param_dict['dso'] if 'dso' in param_dict else '[unknown]'
> > --
> > 2.34.1
> >