Lines Matching +full:convert +full:- +full:sample +full:- +full:format
1 # gecko.py - Convert perf record output to Firefox's gecko profile format
2 # SPDX-License-Identifier: GPL-2.0
4 # The script converts perf.data to Gecko Profile Format,
9 # perf record -a -g -F 99 sleep 60
14 # perf script gecko -F 99 -a sleep 60
32 # Add the Perf-Trace-Util library to the Python path
34 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
48 # https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/ty…
53 PRODUCT = os.popen('uname -op').read().strip()
68 # https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/ty…
80 # https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/ty…
85 # https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/ty…
86 class Sample(NamedTuple): class
96 comm: Thread command-line (name).
100 frameTable: interned stack frame ID -> stack frame.
101 stringTable: interned string ID -> string.
102 stringMap: interned string -> string ID.
103 stackTable: interned stack ID -> stack.
104 stackMap: (stack prefix ID, leaf stack frame ID) -> interned Stack ID.
105 frameMap: Stack Frame string -> interned Frame ID.
109 samples: List[Sample] = field(default_factory=list)
120 samples: List[Sample] = field(default_factory=list)
128 def _intern_stack(self, frame_id: int, prefix_id: Optional[int]) -> int:
140 def _intern_string(self, string: str) -> int:
150 def _intern_frame(self, frame_str: str) -> int:
159 symbol_name_to_category = KERNEL_CATEGORY_INDEX if frame_str.find('kallsyms') != -1 \
160 or frame_str.find('/vmlinux') != -1 \
177 def _add_sample(self, comm: str, stack: List[str], time_ms: Milliseconds) -> None:
178 """Add a timestamped stack trace sample to the thread builder.
180 comm: command-line (name) of the thread at this sample
182 time_ms: timestamp of sample in milliseconds.
192 self.samples.append(Sample(stack_id=prefix_stack_id,
196 def _to_json_dict(self) -> Dict:
197 """Converts current Thread to GeckoThread JSON format."""
198 # Gecko profile format is row-oriented data as List[List],
201 # https://github.com/firefox-devtools/profiler/blob/main/docs-developer/gecko-profile-format.md
202 …# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/t…
207 …# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/t…
220 …# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/t…
230 …# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/t…
246 …# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/t…
262 def process_event(param_dict: Dict) -> None:
265 time_stamp = (param_dict['sample']['time'] // 1000) / 1000
266 pid = param_dict['sample']['pid']
267 tid = param_dict['sample']['tid']
270 # Start time is the time of the first sample
274 # Parse and append the callchain of the current sample into a stack.
283 stack = stack[::-1]
285 # During perf record if -g is not used, the callchain is not available.
292 # Add sample to the specific thread.
299 def trace_begin() -> None:
310 def trace_end() -> None:
314 …# Schema: https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e27…
336 # launch the profiler on local host if not specified --save-only args, otherwise print to file
349 # Used to enable Cross-Origin Resource Sharing (CORS) for requests coming from 'https://profiler.fi…
352 self.send_header('Access-Control-Allow-Origin', 'https://profiler.firefox.com')
358 url = 'https://profiler.firefox.com/from-url/' + safe_string
361 def main() -> None:
364 …parser = argparse.ArgumentParser(description="Convert perf.data to Firefox\'s Gecko Profile format…
366 # Add the command-line options
368 …# https://github.com/firefox-devtools/profiler/blob/50124adbfa488adba6e2674a8f2618cf34b59cd2/res/c…
369 …parser.add_argument('--user-color', default='yellow', help='Color for the User category', choices=…
370 …parser.add_argument('--kernel-color', default='orange', help='Color for the Kernel category', choi…
371 …# If --save-only is specified, the output will be saved to a file instead of opening Firefox's pro…
372 …parser.add_argument('--save-only', help='Save the output to a file instead of opening Firefox\'s p…
374 # Parse the command-line arguments