[PATCH v2 4/7] scripts: python: implement get or create stack function

From: Anup Sharma
Date: Wed Jul 05 2023 - 15:48:20 EST


The get_or_create_stack function is responsible for retrieving
or creating a stack based on the provided frame and prefix.
It first generates a key using the frame and prefix values.
If the stack corresponding to the key is found in the stackMap,
it is returned. Otherwise, a new stack is created by appending
the prefix and frame to the stackTable's 'data' array. The key
and the index of the newly created stack are added to the
stackMap for future reference.

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

diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
index e56864e78dc1..6f69c083d3ff 100644
--- a/tools/perf/scripts/python/firefox-gecko-converter.py
+++ b/tools/perf/scripts/python/firefox-gecko-converter.py
@@ -65,6 +65,17 @@ def process_event(param_dict):
},
'data': [],
}
+ stringTable = []
+
+ stackMap = dict()
+ def get_or_create_stack(frame, prefix):
+ key = f"{frame}" if prefix is None else f"{frame},{prefix}"
+ stack = stackMap.get(key)
+ if stack is None:
+ stack = len(stackTable['data'])
+ stackTable['data'].append([prefix, frame])
+ stackMap[key] = stack
+ return stack

def _addThreadSample(pid, tid, threadName, time_stamp, stack):
thread = thread_map.get(tid)
--
2.34.1