History

perf scripts python: Add trace end processing and PRODUCT and CATEGORIES information

The final output will now be presented in JSON format following the Gecko profile structure. Additionally, the inclusion of PRODUCT allows easy retrieval of header information for UI. Furthermore, CATEGORIES have been introduced to enable customization of kernel and user colors using input arguments. To facilitate this functionality, an argparse-based parser has been implemented. Note: The implementation of threads will be addressed in subsequent commits for now I have commented it out.

Anup Sharma committed 3 years ago

Commit 833daec1 parent 5aacd7f1 file · +64 −1Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/gecko.py+64−1
@@ -11,6 +11,8 @@ · 10 unmodified lines
11 11
12import os12import os
13import sys13import sys
14import json
15import argparse
14from dataclasses import dataclass, field16from dataclasses import dataclass, field
15from typing import List, Dict, Optional, NamedTuple, Set, Tuple, Any17from typing import List, Dict, Optional, NamedTuple, Set, Tuple, Any
16 18
@@ -30,6 +32,13 @@ Milliseconds = float · 13 unmodified lines
30# start_time is intialiazed only once for the all event traces.32# start_time is intialiazed only once for the all event traces.
31start_time = None33start_time = None
32 34
35# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/profile.js#L425
36# Follow Brendan Gregg's Flamegraph convention: orange for kernel and yellow for user space by default.
37CATEGORIES = None
38
39# The product name is used by the profiler UI to show the Operating system and Processor.
40PRODUCT = os.popen('uname -op').read().strip()
41
33# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L15642# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L156
34class Frame(NamedTuple):43class Frame(NamedTuple):
35 string_id: StringID44 string_id: StringID
@@ -171,4 +180,58 @@ def process_event(param_dict: Dict) -> None: · 135 unmodified lines
171# Trace_end runs at the end and will be used to aggregate180# Trace_end runs at the end and will be used to aggregate
172# the data into the final json object and print it out to stdout.181# the data into the final json object and print it out to stdout.
173def trace_end() -> None:182def trace_end() -> None:
174 pass183 # Schema: https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L305
184 gecko_profile_with_meta = {
185 "meta": {
186 "interval": 1,
187 "processType": 0,
188 "product": PRODUCT,
189 "stackwalk": 1,
190 "debug": 0,
191 "gcpoison": 0,
192 "asyncstack": 1,
193 "startTime": start_time,
194 "shutdownTime": None,
195 "version": 24,
196 "presymbolicated": True,
197 "categories": CATEGORIES,
198 "markerSchema": [],
199 },
200 "libs": [],
201 # threads will be implemented in later commits.
202 # "threads": threads,
203 "processes": [],
204 "pausedRanges": [],
205 }
206 json.dump(gecko_profile_with_meta, sys.stdout, indent=2)
207
208def main() -> None:
209 global CATEGORIES
210 parser = argparse.ArgumentParser(description="Convert perf.data to Firefox\'s Gecko Profile format")
211
212 # Add the command-line options
213 # Colors must be defined according to this:
214 # https://github.com/firefox-devtools/profiler/blob/50124adbfa488adba6e2674a8f2618cf34b59cd2/res/css/categories.css
215 parser.add_argument('--user-color', default='yellow', help='Color for the User category')
216 parser.add_argument('--kernel-color', default='orange', help='Color for the Kernel category')
217 # Parse the command-line arguments
218 args = parser.parse_args()
219 # Access the values provided by the user
220 user_color = args.user_color
221 kernel_color = args.kernel_color
222
223 CATEGORIES = [
224 {
225 "name": 'User',
226 "color": user_color,
227 "subcategories": ['Other']
228 },
229 {
230 "name": 'Kernel',
231 "color": kernel_color,
232 "subcategories": ['Other']
233 },
234 ]
235
236if __name__ == '__main__':
237 main()