xref: /linux/tools/perf/scripts/python/gecko.py (revision 0a02e44cc2fe1657af1f2740cb9a1dcd8a9338cc)
1# firefox-gecko-converter.py - Convert perf record output to Firefox's gecko profile format
2# SPDX-License-Identifier: GPL-2.0
3#
4# The script converts perf.data to Gecko Profile Format,
5# which can be read by https://profiler.firefox.com/.
6#
7# Usage:
8#
9#     perf record -a -g -F 99 sleep 60
10#     perf script report gecko > output.json
11
12import os
13import sys
14from typing import Dict
15
16# Add the Perf-Trace-Util library to the Python path
17sys.path.append(os.environ['PERF_EXEC_PATH'] + \
18	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
19
20from perf_trace_context import *
21from Core import *
22
23# start_time is intialiazed only once for the all event traces.
24start_time = None
25
26# Uses perf script python interface to parse each
27# event and store the data in the thread builder.
28def process_event(param_dict: Dict) -> None:
29	global start_time
30	global tid_to_thread
31	time_stamp = (param_dict['sample']['time'] // 1000) / 1000
32	pid = param_dict['sample']['pid']
33	tid = param_dict['sample']['tid']
34	comm = param_dict['comm']
35
36	# Start time is the time of the first sample
37	if not start_time:
38		start_time = time_stamp
39
40# Trace_end runs at the end and will be used to aggregate
41# the data into the final json object and print it out to stdout.
42def trace_end() -> None:
43	pass
44