Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7461520rwp; Tue, 18 Jul 2023 16:07:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGVrirQDAQGmGfrZN6hPfVhWXw/lP4Ig9+2ldN8162cOFHK/ywv+MToPu7VcI4AerPANdI X-Received: by 2002:a17:906:189:b0:994:54e9:692c with SMTP id 9-20020a170906018900b0099454e9692cmr1075942ejb.1.1689721629401; Tue, 18 Jul 2023 16:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689721629; cv=none; d=google.com; s=arc-20160816; b=ESpFedsJG+yHxO3JrCVHw5KNEM8YbHqd4cQoghe5h2nHiFZ/mj3BSBG6qOucvJltRj nEuA0tCQlsz6vAm23guyNzhftMtRgXZekt5Bm1HPJg9ezCZDSoTpyPwsGxZBdNP+qx3x V3DGhlYdt+KSveTIisWNr+PdVfrZ0TErAbPYHcje6ZWKo+hc4mPIHhbHDNfhtBrImhRQ zN3Uhdp+d4XmOK645pgQHkK/t/UJNmJX3hypriIQ3YmejXx2jMVVroFWMdxCYzRzZ9Co 92OVuJd/FXQcLgToRu+UJbE0XFaHYQVSGlt1SvpYaSztmep1w+mGpJxnUitzJkwrk288 R28Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=80aRBWvaVaWLuW8nDpBJWXcRLl3VPc3POw1KKbLSEx4=; fh=74JdZCcncRx9vhK0g0jCPyLh0X9SLH8kcZrk5gmejJ4=; b=bNkeu+OT4SZJnsncYQHenmkE6oRkdbbwklujPCHoA84JAFeZlX5zv+YGrlT0pElZz9 F/qcQ4ar+Ghi8Tdzop9qqj9zooPs3d65HvF6aAbQcisrKZgm01W93Sz6Uoan6WdMl/8i Xo5wMPDsdvvZEh0BoppOy2N5Ntlyrzyf39L39yV7IoQllQtjKYJv7qBa4FyUi2xUPilW 5izJ7k0rip4GuBEef9+ed2AssTPaR7+KuD9pG2+qeAFldyyKM8TYiliyjsyREsiCTrCx JiqsgzLGDEBTakw5nNWhX1WfxKX0sDqFdsZq+ysg8VmE4mf5L+61xmZKlMlNt8zS0lXi wTew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=B2t7ntea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id op6-20020a170906bce600b009925f1a32f8si1991539ejb.400.2023.07.18.16.06.43; Tue, 18 Jul 2023 16:07:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=B2t7ntea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231300AbjGRWur (ORCPT + 99 others); Tue, 18 Jul 2023 18:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231164AbjGRWup (ORCPT ); Tue, 18 Jul 2023 18:50:45 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DF7110A; Tue, 18 Jul 2023 15:50:16 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b8ad907ba4so37168925ad.0; Tue, 18 Jul 2023 15:50:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689720616; x=1692312616; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=80aRBWvaVaWLuW8nDpBJWXcRLl3VPc3POw1KKbLSEx4=; b=B2t7nteaMvgwOtKhySgmdV3tsVDETsWZoJAbzd16487TXUVnftXjvzq/BadVWL4cjB emH8NGSmC2fBAidHjs7T9I19ohQXTNEfPxvM6fQSFNTqRuHDJ0clV9fBeAiV0eTdb4ff o1g6zg1z4VEndA5Ko8G3os6TgzzhP5482DI/cQebTX+kQPDFToS9MIRm4pSNwbWDpPTe qsfQD/U20QVnlJUxYE0i/2l5UutIzilga1uKBFwitrmYJ1NZtwmL0OfFlcS9Cuuf2DQc c+NFZ8diSixknyzgOAC9f1qK5n6NxQk7hCXcGALt2mLTKpDSrFI5FBmxiOrixyBKNfm0 r6hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689720616; x=1692312616; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=80aRBWvaVaWLuW8nDpBJWXcRLl3VPc3POw1KKbLSEx4=; b=kJSRP/nzIhKS9DXeVmVpWh6yVu2hh6mwyyFbvhBU6bYNUV+rFsp531rHqfYLhzrumg ZQWOZPZen6KoQU9xOixqrNed9hQmiQRWjuek04iiiUM9XEzk5/pe3G5PfXAg43FOQGBB ZUxrm1hbnb1Ch3LvvwVa3V76cf0nBSTylEgw1wNKjfRw88A6TK9HNscimf2Vu0vzPHCZ fL8XgZkhlOxZC24+4eyW3R76Gm2Hc8dxCH4XSyg6uakUXNB5bskrhmzorYONfgthdqpl OwV+9Rday6ualcI/uj3C5CfmO27DdPjBPjlGmcvK3J+zAnhpxNG8zVnGLYtSr8LiTBsL eYAQ== X-Gm-Message-State: ABy/qLYGgSkj4d6TeNOi5aXYmlyY0dNcqv3o6l/wi/avn2EcbLlZMdnf jlesq3QPXm/puTwajd1FEss= X-Received: by 2002:a17:902:e744:b0:1b6:7f96:42ca with SMTP id p4-20020a170902e74400b001b67f9642camr15791921plf.66.1689720615804; Tue, 18 Jul 2023 15:50:15 -0700 (PDT) Received: from yoga ([2400:1f00:13:be68:c61a:77e0:3624:e4f6]) by smtp.gmail.com with ESMTPSA id p8-20020a170902b08800b001b9ff5aa2e7sm2372950plr.239.2023.07.18.15.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 15:50:15 -0700 (PDT) Date: Wed, 19 Jul 2023 04:20:08 +0530 From: Anup Sharma To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Anup Sharma , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/6] perf scripts python: Add trace end processing and PRODUCT and CATEGORIES information Message-ID: <662239f70618982ef659362ae5729422f318db66.1689718662.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 that the implementation of threads will be addressed in subsequent commits." Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py index d9b1ec18997a..a0218e2245f2 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -11,6 +11,8 @@ import os import sys +import json +import argparse from dataclasses import dataclass, field from typing import List, Dict, Optional, NamedTuple, Set, Tuple, Any @@ -30,6 +32,13 @@ Milliseconds = float # start_time is intialiazed only once for the all event traces. start_time = None +# https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/profile.js#L425 +# Follow Brendan Gregg's Flamegraph convention: orange for kernel and yellow for user space by default. +CATEGORIES = None + +# The product name is used by the profiler UI to show the Operating system and Processor. +PRODUCT = os.popen('uname -op').read().strip() + # https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L156 class Frame(NamedTuple): string_id: StringID @@ -172,4 +181,57 @@ def process_event(param_dict: Dict) -> None: # Trace_end runs at the end and will be used to aggregate # the data into the final json object and print it out to stdout. def trace_end() -> None: - pass + # Schema: https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L305 + gecko_profile_with_meta = { + "meta": { + "interval": 1, + "processType": 0, + "product": PRODUCT, + "stackwalk": 1, + "debug": 0, + "gcpoison": 0, + "asyncstack": 1, + "startTime": start_time, + "shutdownTime": None, + "version": 24, + "presymbolicated": True, + "categories": CATEGORIES, + "markerSchema": [], + }, + "libs": [], + "threads": threads, + "processes": [], + "pausedRanges": [], + } + json.dump(gecko_profile_with_meta, sys.stdout, indent=2) + +def main() -> None: + global CATEGORIES + parser = argparse.ArgumentParser(description="Convert perf.data to Firefox\'s Gecko Profile format") + + # Add the command-line options + # Colors must be defined according to this: + # https://github.com/firefox-devtools/profiler/blob/50124adbfa488adba6e2674a8f2618cf34b59cd2/res/css/categories.css + parser.add_argument('--user-color', default='yellow', help='Color for the User category') + parser.add_argument('--kernel-color', default='orange', help='Color for the Kernel category') + # Parse the command-line arguments + args = parser.parse_args() + # Access the values provided by the user + user_color = args.user_color + kernel_color = args.kernel_color + + CATEGORIES = [ + { + "name": 'User', + "color": user_color, + "subcategories": ['Other'] + }, + { + "name": 'Kernel', + "color": kernel_color, + "subcategories": ['Other'] + }, + ] + +if __name__ == '__main__': + main() -- 2.34.1