Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Signed-off-by: Anup Sharma <anupnewsmail@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/fa6d027e4134c48e8a2ea45dd8f6b21e6a3418e4.1689961706.git.anupnewsmail@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Anup Sharma and committed by
Arnaldo Carvalho de Melo
833daec7 5aacd7f0

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