[PATCH 8/9] scripts: python: Finalize convertPerfScriptProfile and return profile data

From: Anup Sharma
Date: Wed Jun 21 2023 - 15:46:26 EST


If the stack is not empty, it is reversed and then passed to
the _addThreadSample function along with other relevant information.
This adds the final sample to the thread.

The thread_array is generated by mapping the 'finish' method on each
thread in the threadMap and collecting the results.
The samples within each thread are sorted in ascending order based on
the 'time' field to ensure they are in the correct order.
This implementation finalizes the processing of the profile data in
convertPerfScriptProfile and returns a structured profile representation

I still need to get the product from the device, having little confusion
on this so will implement it on next version.

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

diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py
index 866751e5d1ce..385a8b77a70a 100644
--- a/tools/perf/scripts/python/firefox-gecko-converter.py
+++ b/tools/perf/scripts/python/firefox-gecko-converter.py
@@ -64,7 +64,7 @@ def convertPerfScriptProfile(profile):
},
'data': [],
}
-
+
stringTable = []

stackMap = dict()
@@ -84,7 +84,7 @@ def convertPerfScriptProfile(profile):
frame = len(frameTable['data'])
location = len(stringTable)
stringTable.append(frameString)
-
+
category = KERNEL_CATEGORY_INDEX if frameString.find('kallsyms') != -1 or frameString.find('/vmlinux') != -1 or frameString.endswith('.ko)') else USER_CATEGORY_INDEX
implementation = None
optimizations = None
@@ -203,3 +203,36 @@ def convertPerfScriptProfile(profile):

stack.append(rawFunc)

+ if len(stack) != 0:
+ stack.reverse()
+ _addThreadSample(pid, tid, threadName, time_stamp, stack)
+
+ thread_array = list(map(lambda thread: thread['finish'](), threadMap.values()))
+
+ for thread in thread_array:
+ # The samples are not guaranteed to be in order, sort them so that they are.
+ key = thread['samples']['schema']['time']
+ thread['samples']['data'].sort(key=lambda data : float(data[key]))
+
+ return {
+ 'meta': {
+ 'interval': 1,
+ 'processType': 0,
+ 'product': 'Linux perf', # TODO: get this from the system
+ 'stackwalk': 1,
+ 'debug': 0,
+ 'gcpoison': 0,
+ 'asyncstack': 1,
+ 'startTime': startTime,
+ 'shutdownTime': None,
+ 'version': 24,
+ 'presymbolicated': True,
+ 'categories': CATEGORIES,
+ 'markerSchema': []
+ },
+ 'libs': [],
+ 'threads': thread_array,
+ 'processes': [],
+ 'pausedRanges': []
+ }
+
--
2.34.1