[PATCH v2 6/7] scripts: python: implement add sample function and return finish

From: Anup Sharma
Date: Wed Jul 05 2023 - 15:49:28 EST


The addSample function appends a new entry to the 'samples' data structure.
It takes the thread name, stack array, and time as input parameters and
if the thread name differs from the current name, it updates the name.
The function utilizes the get_or_create_stack and get_or_create_frame
methods to construct the stack structure. Finally, it adds the stack,
time, and responsiveness values to the 'data' list within 'samples'.

The finish function generates a dictionary containing various profile
information such as 'tid', 'pid', 'name', 'markers', 'samples',
'frameTable', 'stackTable', 'stringTable', 'registerTime',
'unregisterTime', and 'processType'.

Signed-off-by: Anup Sharma <anupnewsmail@xxxxxxxxx>
---
.../scripts/python/firefox-gecko-converter.py | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)

diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
index d5b9fb16e520..910e598c743f 100644
--- a/tools/perf/scripts/python/firefox-gecko-converter.py
+++ b/tools/perf/scripts/python/firefox-gecko-converter.py
@@ -110,6 +110,35 @@ def process_event(param_dict):
frameMap[frameString] = frame
return frame

+ def addSample(threadName, stackArray, time):
+ nonlocal name
+ if name != threadName:
+ name = threadName
+ stack = reduce(lambda prefix, stackFrame: get_or_create_stack
+ (get_or_create_frame(stackFrame), prefix), stackArray, None)
+ responsiveness = 0
+ samples['data'].append([stack, time, responsiveness])
+
+ def finish():
+ return {
+ "tid": tid,
+ "pid": pid,
+ "name": name,
+ "markers": markers,
+ "samples": samples,
+ "frameTable": frameTable,
+ "stackTable": stackTable,
+ "stringTable": stringTable,
+ "registerTime": 0,
+ "unregisterTime": None,
+ "processType": 'default'
+ }
+
+ return {
+ "addSample": addSample,
+ "finish": finish
+ }
+
def _addThreadSample(pid, tid, threadName, time_stamp, stack):
thread = thread_map.get(tid)
if not thread:
--
2.34.1