From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B00BEB64D8 for ; Wed, 21 Jun 2023 19:37:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbjFUTh0 (ORCPT ); Wed, 21 Jun 2023 15:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbjFUThU (ORCPT ); Wed, 21 Jun 2023 15:37:20 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD4121992; Wed, 21 Jun 2023 12:37:14 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b5465a79cdso28158575ad.3; Wed, 21 Jun 2023 12:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376234; x=1689968234; 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=wysmKxTjA5POXPuSnL3ZWdPlXIDrR3joMPak2RW+D1M=; b=S07+kLCUT/SwJ5u1DA+bkwXwy97NCQpkedZxhO8+z6Wq8+W6n5xNfqYhJNk24Dtx2J dsZxb94BkFneFYNQTcJrx8e3lpkdZnE1tJk7lz0V00qnMvjNIHqsPDTZbhqhTz6jHwvO 6zjxgjTnw/hw9pNYqi6jVBHgBPAjDkE30MLk8M06RDHtHJa4nxy0YJn5kUvO35SLeyT8 zy1l6SfvqEVmjFVNjvRL/Mr0Ot5X1KwelKNhaHVqD36RmV561WGqqqenu8/0Ran/6sRe Xlp8JlZCoyOMC3ds4twYoRWsqJkF0S9kPLKsYbVG52nnv76D7niK19XtvLp/MrLrzw6O 9m4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376234; x=1689968234; 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=wysmKxTjA5POXPuSnL3ZWdPlXIDrR3joMPak2RW+D1M=; b=Qw9zjJPq7bIfEC1mR7TQtVVIb7vCsL/kWdwCB3rhWUgEsRkQP405SMK2pIwbcwlxYi p5Kgq7pIqYUqi2K4igh6HXqFt9IXKTipAB13Q0yu9fAhsKtEiQJqAHjaPV+2pwp1gEbD wFb8ZqPxTyu0ZWOryfLlWln5GGCn9XXSndZbfOjSnS1i3uZLmOQ4TpJGt0VYFN+TipZb dfaVSQVyXUCF9/qVjX3jLawxt3rOT2C7qPRfi7huTSSfJ+Y4i1oJs5fvvitfcWUn3sN/ xlTY1iiA7ucUA93pAMpeuWFX/CyR8XVvzY5rxAYRdNBbBvqqrwgGOs54dSx1zrDVhx39 SA4w== X-Gm-Message-State: AC+VfDx9w7XVG2rEP+V6pSdeGmmLHiUd7WwVH2YRiDgnjSueYVyxE1ku XbXgjAfFiEuXSPkismqhwHs= X-Google-Smtp-Source: ACHHUZ69TGI7UgaMNHlz30M9h5OSeOZkCCWPBquKQ2Y9Gao9+QHOyGF1n9se2Rl8repP0FTskygALQ== X-Received: by 2002:a17:902:f551:b0:1b5:4f50:f1e0 with SMTP id h17-20020a170902f55100b001b54f50f1e0mr11017305plf.29.1687376234097; Wed, 21 Jun 2023 12:37:14 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id jl17-20020a170903135100b001b39f8dc06fsm3862326plb.152.2023.06.21.12.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:37:13 -0700 (PDT) Date: Thu, 22 Jun 2023 01:07:05 +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 1/9] scripts: python: Add check for correct perf script format Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The isPerfScriptFormat function, validates the format of a perf script. The function checks if the given input meets specific criteria to determine if it is a valid perf script output. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tools/perf/scripts/python/firefox-gecko-converter.py diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py new file mode 100644 index 000000000000..73a431d0c7d1 --- /dev/null +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +import re +import sys +import json +from functools import reduce + +def isPerfScriptFormat(profile): + if profile.startswith('# =3D=3D=3D=3D=3D=3D=3D=3D\n'): + return True + + if profile.startswith('{'): + return False + + firstLine =3D profile[:profile.index('\n')] + return bool(re.match(r'^\S.*?\s+(?:\d+/)?\d+\s+(?:\d+\d+\s+)?[\d.]+:',= firstLine)) --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7382EB64D8 for ; Wed, 21 Jun 2023 19:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbjFUTkM (ORCPT ); Wed, 21 Jun 2023 15:40:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjFUTkI (ORCPT ); Wed, 21 Jun 2023 15:40:08 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD761171C; Wed, 21 Jun 2023 12:40:07 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-666ecf9a0ceso3383602b3a.2; Wed, 21 Jun 2023 12:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376407; x=1689968407; 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=pZjCGZDhKpXUGSqDazPCwNKoB5sel2LSB5kjV5qg9hw=; b=hSz94Aifn14AVAIYgF5iOoW8O9wlFY3sDdn24bNFUxZ3IY3QI9JvwGSZYXI14w6sc3 YF7rY1EzXKlv5p5oEqA0h6BdxSAbJPLLx4MHOiG/sdHW7YJ83NX/jXW2C4hhGet80cNz kidZdoUCnLA9ezjdiyep3GzL0pecbQDP/nXa3+azfB1cBB65qWOGEMH1znuJO8apC/TB 9j/MVQjydoci7Tqo6h0pbMi91ckJPnuxu5zamPfKeetEsCTCPoz5MtgT7v1hCdnKxFHQ sg10NEhE04yytTis968A7OWOX0MalBCsg507wAshXChkShni3b7JZ+QUdcB1crJnWdOs lq4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376407; x=1689968407; 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=pZjCGZDhKpXUGSqDazPCwNKoB5sel2LSB5kjV5qg9hw=; b=Y+4AuBgj3rGFazQ8jx3biPQMFv7jPLz/A+aIzkTRebiTSeE5UL4vB41L5iGG+Y1ZZb hHbrn9jGF2/ZwdB4p29CUH5bENhzwFbOHZvE95xAp2AUPFdmq2a0fm/Wnh69CxCKt8Qa EqWl6L4ij+ysbIa6IuNx5Qz85esejCYz225wtRg3bkPFD2B2Sr+YWsB69u3FMiiuWeIY pDE4wC3siK69pPdZGNk+RARp1xnQS1yRg3REt4PMYoTVLHM1Pu57PP7I6/19xJCHboNb hip0gT/gArGMqqXd0BAoEoEyxAbnxxRnnBoYMgwIWvq/iGVp3wadQVoAmuO9yduGLq43 WyQA== X-Gm-Message-State: AC+VfDw+Yzgz6tJ9wu6oyalBXJtCDFizQwIL7xcRPHmNg2dHy1fKBS7i jxkxV4QezYnsRmgBwZ1Y9Ek= X-Google-Smtp-Source: ACHHUZ7iTsUHJjPKx60L97N/5zwVvocem2AFCJg82V3aKOYyAr6+WE8FgMwSi8V+EGANZnX1Vng+pA== X-Received: by 2002:a05:6a00:a94:b0:666:8403:9f4 with SMTP id b20-20020a056a000a9400b00666840309f4mr17338320pfl.16.1687376407143; Wed, 21 Jun 2023 12:40:07 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id a20-20020aa780d4000000b0064d47cd117esm3265030pfn.39.2023.06.21.12.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:40:06 -0700 (PDT) Date: Thu, 22 Jun 2023 01:09:59 +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 2/9] scripts: python: implement add sample function and return finish function Message-ID: <4ded5c271261644c472562f31994830b6a0aefe1.1687375189.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The main convertPerfScriptProfile function returns a dictionary with references to the addSample and finish functions, allowing external code to utilize them for profile conversion. This function has few more functions which will be added. The addSample function appends a new entry to the 'samples' data structure. It takes the thread name, stack array, and time as input parameters. If the thread name differs from the current name, it updates the name. The function utilizes the get_or_create_stack and get_or_create_frame methods to construct the stack structure. Finally, it adds the stack, time, and responsiveness values to the 'data' list within 'samples'. The finish function generates a dictionary containing various profile infor= mation such as 'tid', 'pid', 'name', 'markers', 'samples', 'frameTable', 'stackTab= le', 'stringTable', 'registerTime', 'unregisterTime', and 'processType'. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index 73a431d0c7d1..2817d4a96269 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -13,3 +13,36 @@ def isPerfScriptFormat(profile): =20 firstLine =3D profile[:profile.index('\n')] return bool(re.match(r'^\S.*?\s+(?:\d+/)?\d+\s+(?:\d+\d+\s+)?[\d.]+:',= firstLine)) + +def convertPerfScriptProfile(profile):=20 + + def addSample(threadName, stackArray, time): + nonlocal name + if name !=3D threadName: + name =3D threadName + # TODO:=20 + # get_or_create_stack will create a new stack if it doesn't ex= ist, or return the existing stack if it does. + # get_or_create_frame will create a new frame if it doesn't ex= ist, or return the existing frame if it does. + stack =3D reduce(lambda prefix, stackFrame: get_or_create_stac= k(get_or_create_frame(stackFrame), prefix), stackArray, None) + responsiveness =3D 0 + samples['data'].append([stack, time, responsiveness]) + + def finish(): + return { + "tid": tid, + "pid": pid, + "name": name, + "markers": markers, + "samples": samples, + "frameTable": frameTable, + "stackTable": stackTable, + "stringTable": stringTable, + "registerTime": 0, + "unregisterTime": None, + "processType": 'default' + } + + return { + "addSample": addSample, + "finish": finish + } --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B04A6EB64DC for ; Wed, 21 Jun 2023 19:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229862AbjFUTlB (ORCPT ); Wed, 21 Jun 2023 15:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbjFUTk6 (ORCPT ); Wed, 21 Jun 2023 15:40:58 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C486F10F2; Wed, 21 Jun 2023 12:40:57 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6b5853a140cso2955398a34.2; Wed, 21 Jun 2023 12:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376457; x=1689968457; 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=s6fzDc08vVPZzlFC9nTdHH7skPWJt+F7WIyjmhwelB8=; b=o9YaNWhP84f6bgxDYS3eKfvgDpWCQISxWH1ZNUz6gEJ9JTNtPNhStfAaNEkWoJAuVI VjDv1f7/7kbBkEwPgfpLslKslOnNxkoNj/qAwp4aZ7pFcxliZ8Z0WRg8IRiUZLa0dQMA f7sXdniO/by9pHXMQY1LICC2J7WRSQpYLlPf/z4lCya0ushy/zO+yBPX1Zgo2ddm+0yA oC4nUiJhrtBLA+39llzcPkS5juc4mgs+3SO3T0sq2WSsATSV6aoKHEe2ufv/7b5l/59I /wR+21Cbu6/AXi7Px4u0zq52udxHPGts+BK79XXwyUXV3Hns0v/pF3hO8xpdFaT5lW6/ q1FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376457; x=1689968457; 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=s6fzDc08vVPZzlFC9nTdHH7skPWJt+F7WIyjmhwelB8=; b=h6maqWUXqRarT9Fg5zOny8B0qRVAGoDS8hTeLcMHc6a5UNd6ob36+9mByAG/P6uO77 lT90C4BHdTzIzaUpYATAQUNvD4i1gmDss7UxTHYb4tvvHGz7iUnVN2V8KYr9Vv5BdTMO rctlsF06Lay+b9/fpWp1Zx2/utnaoIT+GOsUw6V0he0GjUK5324aXe0VVmSZ7CsbOnlP /W90rhL+mlhAGkGbDWE3C3zJOuSoviv+INmrloYHc0f7FM7BDfMRzFW2yJGdC4cP6Njf 12fFPpjm3dJ08X3ZpXHdGWOhq+4QtgT2KIzHZNVHR+4gU6dKRt6wHxcafyTi3+/IU7aG g/Tw== X-Gm-Message-State: AC+VfDyHd9MxWELjuGGTTWGGCjy8q0yapvtOV/FQpsTFlNw5Fhr+lSlJ JXuz2KqlrVmNCUIJCseTKPc= X-Google-Smtp-Source: ACHHUZ5v8fJJe/3SfN1+J65oY7NO0euJvdyFcCsON0i8S62Mc+vZy99GBz0EMzt0KE2ju7x93h+BWQ== X-Received: by 2002:a05:6830:10d6:b0:6b5:8de5:a02c with SMTP id z22-20020a05683010d600b006b58de5a02cmr6145285oto.6.1687376456926; Wed, 21 Jun 2023 12:40:56 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id c9-20020a631c49000000b0054fa8539681sm3457291pgm.34.2023.06.21.12.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:40:56 -0700 (PDT) Date: Thu, 22 Jun 2023 01:10:48 +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 3/9] scripts: python: Introduce thread sample processing in convertPerfScriptProfile Message-ID: <42ba5416982056273960f182e8a79fd998639bcd.1687375189.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The _addThreadSample function is responsible for adding a sample to a speci= fic thread. It takes the process ID (pid), thread ID (tid), thread name, timest= amp (time_stamp), and stack as parameters. It first checks if the thread exists= in the threadMap dictionary. If not, it creates a new thread using the _create= tread function and assigns it to the threadMap. Finally, it calls the 'addSample'= method of the thread, passing the thread name, stack, and timestamp. Signed-off-by: Anup Sharma --- tools/perf/scripts/python/firefox-gecko-converter.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index 2817d4a96269..0ff70c0349c8 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -46,3 +46,11 @@ def convertPerfScriptProfile(profile): "addSample": addSample, "finish": finish } + + threadMap =3D dict() + def _addThreadSample(pid, tid, threadName, time_stamp, stack): + thread =3D threadMap.get(tid) + if not thread: + thread =3D _createtread(threadName, pid, tid) + threadMap[tid] =3D thread + thread['addSample'](threadName, stack, time_stamp) --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46917EB64DD for ; Wed, 21 Jun 2023 19:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbjFUTmA (ORCPT ); Wed, 21 Jun 2023 15:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjFUTl7 (ORCPT ); Wed, 21 Jun 2023 15:41:59 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52EE81733; Wed, 21 Jun 2023 12:41:57 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b52864b701so48363325ad.3; Wed, 21 Jun 2023 12:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376517; x=1689968517; 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=8EOjusGezgUEDaoouw0ul4hE6YXmt391w2kXuFkLv/E=; b=l3fqFnRFxZnqbhQOOMFmGaKdbzianAEuvAsWRZi2xnf6kpwmW78uMK7SYQcz99HQOV G3JNbW1/SBgFXl5woRvHfbAOoxkKBBN5jtrA/w+txXRJ0eMvzTaiEFW7+56aE16nw/1G s7Qk5O8kTFut6rh5YhzhfJ9s9E3aiTfh/fqM9BzN5gUIyCyCGH/F32pCDXurmmfoZjNZ g7eEx4SgM/ddPfqtEKf52CnX2n86nq7Bkos+k66rWmigk2Mda+rspj5t+oXayTFY0fBm B4zVoG5rYTZxf4OBmuCrOXZ8Ec+PGkyUgwTECUUv/AVKz8f4jYUDhZXXp0qy3aOJbB9D 9RGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376517; x=1689968517; 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=8EOjusGezgUEDaoouw0ul4hE6YXmt391w2kXuFkLv/E=; b=RHvFTfI0oR6fyC4lg9WSgYg+xP6ysJaWsKiH5JBtNlnZy1unN9AgF22xW8FSlqP8xM CwAebp2KRg0gJ5dMTYYJHiN3SSJjBrvHFhDkqeBCQieVmmOIA6yeOd9GmLInyuFzvJDY 1DYzExnnMkDvUB5+M9lQNFnthIci9KG7JsonkUJz14+mZ73GxoCvKZ5DMG1B0ycCcoS4 xzolBFuNBZgKF7N6maVLcfboqeVHf53sNxVR64Weiku6wmtDG8c1nDmtBVs7U4ml7vJL lomsuicRmZ/rvHWvY0Ap9j7z2GD7WDlw2WhfOeX3WgOhS/U/Eb99lHAU3n3/bcbhc5sx jr9A== X-Gm-Message-State: AC+VfDwku36HeQ6y3/mzljz+X+JqJZ2ruPnTmcv7Rz75euVSie26lXcY QCSiReAK2WLEnLsKr94V68s= X-Google-Smtp-Source: ACHHUZ5lbjS2yji51QQw2AqUU4zvpeVZrjVQzZsWH7OScLOZWinv5Wiylwwt33cJWwGei7hS2UuPVQ== X-Received: by 2002:a17:902:a3c7:b0:1b5:361:cefe with SMTP id q7-20020a170902a3c700b001b50361cefemr14038204plb.52.1687376516573; Wed, 21 Jun 2023 12:41:56 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id u13-20020a170902a60d00b001ae0a4b1d3fsm3883794plq.153.2023.06.21.12.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:41:55 -0700 (PDT) Date: Thu, 22 Jun 2023 01:11:48 +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 4/9] scripts: python: Implement parsing of input data in convertPerfScriptProfile Message-ID: <3772bce9068962f2a4c57672e919ebdf30edbc5c.1687375189.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The lines variable is created by splitting the profile string into individu= al lines. It allows for iterating over each line for processing. The line is considered the start of a sample. It is matched against a regul= ar expression pattern to extract relevant information such as before_time_stam= p, time_stamp, threadNamePidAndTidMatch, threadName, pid, and tid. The stack frames of the current sample are then parsed in a nested loop. Each stackFrameLine is matched against a regular expression pattern to extract rawFunc and mod information. Also fixed few checkpatch warnings. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index 0ff70c0349c8..e5bc7a11c3e6 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 import re import sys import json @@ -14,13 +15,13 @@ def isPerfScriptFormat(profile): firstLine =3D profile[:profile.index('\n')] return bool(re.match(r'^\S.*?\s+(?:\d+/)?\d+\s+(?:\d+\d+\s+)?[\d.]+:',= firstLine)) =20 -def convertPerfScriptProfile(profile):=20 +def convertPerfScriptProfile(profile): =20 def addSample(threadName, stackArray, time): nonlocal name if name !=3D threadName: name =3D threadName - # TODO:=20 + # TODO: # get_or_create_stack will create a new stack if it doesn't ex= ist, or return the existing stack if it does. # get_or_create_frame will create a new frame if it doesn't ex= ist, or return the existing frame if it does. stack =3D reduce(lambda prefix, stackFrame: get_or_create_stac= k(get_or_create_frame(stackFrame), prefix), stackArray, None) @@ -54,3 +55,60 @@ def convertPerfScriptProfile(profile): thread =3D _createtread(threadName, pid, tid) threadMap[tid] =3D thread thread['addSample'](threadName, stack, time_stamp) + + lines =3D profile.split('\n') + + line_index =3D 0 + startTime =3D 0 + while line_index < len(lines): + line =3D lines[line_index] + line_index +=3D 1 + # perf script --header outputs header lines beginning with # + if line =3D=3D '' or line.startswith('#'): + continue + + sample_start_line =3D line + + sample_start_match =3D re.match(r'^(.*)\s+([\d.]+):', sample_start= _line) + if not sample_start_match: + print(f'Could not parse line as the start of a sample in the "= perf script" profile format: "{sample_start_line}"') + continue + + before_time_stamp =3D sample_start_match[1] + time_stamp =3D float(sample_start_match[2]) * 1000 + threadNamePidAndTidMatch =3D re.match(r'^(.*)\s+(?:(\d+)\/)?(\d+)\= b', before_time_stamp) + + if not threadNamePidAndTidMatch: + print('Could not parse line as the start of a sample in the "p= erf script" profile format: "%s"' % sampleStartLine) + continue + threadName =3D threadNamePidAndTidMatch[1].strip() + pid =3D int(threadNamePidAndTidMatch[2] or 0) + tid =3D int(threadNamePidAndTidMatch[3] or 0) + if startTime =3D=3D 0: + startTime =3D time_stamp + # Parse the stack frames of the current sample in a nested loop. + stack =3D [] + while line_index < len(lines): + stackFrameLine =3D lines[line_index] + line_index +=3D 1 + if stackFrameLine.strip() =3D=3D '': + # Sample ends. + break + stackFrameMatch =3D re.match(r'^\s*(\w+)\s*(.+) \(([^)]*)\)', = stackFrameLine) + if stackFrameMatch: + rawFunc =3D stackFrameMatch[2] + mod =3D stackFrameMatch[3] + rawFunc =3D re.sub(r'\+0x[\da-f]+$', '', rawFunc) + + if rawFunc.startswith('('): + continue # skip process names + + if mod: + # If we have a module name, provide it. + # The code processing the profile will search for + # "functionName (in libraryName)" using a regexp, + # and automatically create the library information. + rawFunc +=3D f' (in {mod})' + + stack.append(rawFunc) + --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9476EEB64DC for ; Wed, 21 Jun 2023 19:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbjFUToC (ORCPT ); Wed, 21 Jun 2023 15:44:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjFUToA (ORCPT ); Wed, 21 Jun 2023 15:44:00 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A81B01735; Wed, 21 Jun 2023 12:43:59 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-25edb50c3acso3606459a91.1; Wed, 21 Jun 2023 12:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376639; x=1689968639; 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=PIku/vKknpxMbgecYJtwrcoNOyOjrqW+/Ub58y9LPOY=; b=MDXMbwHs8SucUzVGA66AedfSlwZGbOqK4Cu9DoOxAiLj6K9y2xTdCTTkpnU5VEcjFw KfNU58CV+ulE0B89+TW7PQUCNrL3xBXDyLO8OgJW9atW/glff6+ARyo/Yt5jnjLOJ+PO xJixT3BngqBE5gOf/dsu+dwmypmCS9YUVVRnoN7i/mWON95jbPnTDLGU5zIc+YumeTQH s4iAsYKrVNFuwei51KmqN81hOlQBpySFbxQ0Fu2zquvGCdoIGiWcghhxtXmHpGFpwesT /K+sF3RgJ2k43wnwr42tOchoOMjNeLEaD75ItWd6AxWtbczUXh4ZIe9OasYbY0nkD3ZT ZWKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376639; x=1689968639; 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=PIku/vKknpxMbgecYJtwrcoNOyOjrqW+/Ub58y9LPOY=; b=YGD7zOwxYVts+UfxXebgvgWuJGiOA9ebbJRzGy4PLSgkLgMaLd3rSU69PTCbxgtvgx +ywmQm1IJ39I5yO3J8TZWp3VfWxNvbG+QTBShFO6O+uBJGmFOH/RxbG9/6mZPlSZ94U5 TeIxHVRXSlCMJOLqsqwm79KBHnBHpOZ66s7LglXio96sEm2RJByaZ9O5PqGyYZrl4CtQ DX/CAEmJe8aAA/rgFwqQpfdQGM61twrorhAZ8BkvLgKF6AlVTzUjFsANpSVLW2s/kwAG vLNwLsKYGhJOlIGzCJN500XXjlAzFb4utWaBf3J+E7Uelf4frss7uElvPHSdexQIPcFa 1SZg== X-Gm-Message-State: AC+VfDxPfW6BGyiNGHN0yuGuxTnDnkqG+ffhdaR44F3fMkHCNkGqcfRi AYIrXDEQzt8gefgrZ+9kbcA= X-Google-Smtp-Source: ACHHUZ5+vKJCMkCp0bbH1rb9wWxJ3NZVNadztHCnKN0qIzFBRRtufhorUidXiEOh2qiJa79OXgDkSg== X-Received: by 2002:a17:90b:a46:b0:25c:2a5d:e06b with SMTP id gw6-20020a17090b0a4600b0025c2a5de06bmr16639436pjb.2.1687376638905; Wed, 21 Jun 2023 12:43:58 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id d6-20020a17090ad3c600b0024749e7321bsm3561426pjw.6.2023.06.21.12.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:43:58 -0700 (PDT) Date: Thu, 22 Jun 2023 01:13:50 +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 5/9] scripts: python: implement function for thread creation Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create a thread with the specified name, process ID (pid), and thread ID (tid). The function initializes markers, samples, frameTable, and stackTable structures for the thread. The markers structure defines the schema and data for thread markers, including fields such as 'name', 'startTime', 'endTime', 'phase', 'category', and 'data'. The samples structure defines the schema and data for thread samples, including fields such as 'stack', 'time', and 'responsiveness'. The frameTable structure defines the schema and data for frame information, including fields such as 'location', 'relevantForJS', 'innerWindowID', 'implementation', 'optimizations', 'line', 'column', 'category', and 'subcategory'. The purpose of this function is to create a new thread structure with the necessary data schemas and initial data arrays. These structures provide a framework for storing and organizing information related to thread markers, samples, frame details, and stack information. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index e5bc7a11c3e6..cdd7f901c13f 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -16,6 +16,47 @@ def isPerfScriptFormat(profile): return bool(re.match(r'^\S.*?\s+(?:\d+/)?\d+\s+(?:\d+\d+\s+)?[\d.]+:',= firstLine)) =20 def convertPerfScriptProfile(profile): + def _createtread(name, pid, tid): + markers =3D { + 'schema': { + 'name': 0, + 'startTime': 1, + 'endTime': 2, + 'phase': 3, + 'category': 4, + 'data': 5, + }, + 'data': [], + } + samples =3D { + 'schema': { + 'stack': 0, + 'time': 1, + 'responsiveness': 2, + }, + 'data': [], + } + frameTable =3D { + 'schema': { + 'location': 0, + 'relevantForJS': 1, + 'innerWindowID': 2, + 'implementation': 3, + 'optimizations': 4, + 'line': 5, + 'column': 6, + 'category': 7, + 'subcategory': 8, + }, + 'data': [], + } + stackTable =3D { + 'schema': { + 'prefix': 0, + 'frame': 1, + }, + 'data': [], + } =20 def addSample(threadName, stackArray, time): nonlocal name --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D89CEB64D7 for ; Wed, 21 Jun 2023 19:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230199AbjFUTor (ORCPT ); Wed, 21 Jun 2023 15:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjFUTop (ORCPT ); Wed, 21 Jun 2023 15:44:45 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4385D1733; Wed, 21 Jun 2023 12:44:44 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-668711086f4so3026796b3a.1; Wed, 21 Jun 2023 12:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376684; x=1689968684; 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=y6toF7rBgOobZWwzNn/wkMI+lBlT1PzkeUNueCz0uLY=; b=BRxZv5YbUO3mqeq5qnYxLw9p1M3Chql2NuBJIVn7S/h37+sCdQH2hvIf9uxu3GBKex RBFJ+U6Q4mVnwKcv9qpSuYIYRmrLl88/SyjZblDY40tyEWGkbBK+3bziACwCcUhwxEi8 JEr6w09TduzhVmaQY8w4V9B2Pwjn9IfsrhGew2f0mpprnU3dYWZmDf/aSCqgvwVyG9RR VKVJSCHHMcNLtWETYPzfyEjbeiCL3nGa6j+EkHxHMGRxSFFuML266+W5rxqxaQb0uoNX 11rN7GyFC5HuHTgQnBwxaFvFOEh1eVwaTZnxeVuE6Q73eYDhKWc73czoNshq5cqsB3AH a86w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376684; x=1689968684; 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=y6toF7rBgOobZWwzNn/wkMI+lBlT1PzkeUNueCz0uLY=; b=OEtXtdV8fbkS0jrQ2jOKzJLlujNkZuiXoUB022Pe+avO1ysAMMcejJM5ymB4FS5kjg lB8wFP03WNz0Gabv9vpv/X6Zk09Leu8U8NhbHs+yBCZqw5oUHjDUAAGDRDH3ImbnDEy9 jHQ4kou8vEs/E3FUOQhu29VW9KguVjlaw9zGV/b+XrHV29IUCv8gk/AQVL7YLsXLr+MC 1PlSKM0S/KkN5uUiIQT13pMfvKJ87Y0pmjECDW1S71yrq/TnensFWOEcvHy9WsH4DMBo 6KCn17YRQkhtNiruHmwafRJ+f4UzwnCMZay/WIHA023nNKOkB18TFsq0efbT91/OQOAX jp9Q== X-Gm-Message-State: AC+VfDwgNNG74kB+fM/8OyHuHjAWWfUL0unSKef7aCtg8jWFIgoYWf3/ sWTKhl6dGK+mS5amqwlYbYI= X-Google-Smtp-Source: ACHHUZ5hAeUCMieuUlk1311Ds9jJRgR4VP52ZCM7xa99c5ayBFd8ORy0j+VV0DYo83KsU3nvqQ3cDQ== X-Received: by 2002:a05:6a00:218e:b0:667:d0ff:6a0f with SMTP id h14-20020a056a00218e00b00667d0ff6a0fmr16310098pfi.5.1687376683591; Wed, 21 Jun 2023 12:44:43 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id 17-20020aa79251000000b0063b6cccd5dfsm3257338pfp.195.2023.06.21.12.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:44:43 -0700 (PDT) Date: Thu, 22 Jun 2023 01:14:35 +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 6/9] scripts: python: implement get or create stack function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The get_or_create_stack function is responsible for retrieving or creating a stack based on the provided frame and prefix. It first generates a key using the frame and prefix values. If the stack corresponding to the key is found in the stackMap, it is returned. Otherwise, a new stack is created by appending the prefix and frame to the stackTable's 'data' array. The key and the index of the newly created stack are added to the stackMap for future reference. Signed-off-by: Anup Sharma --- tools/perf/scripts/python/firefox-gecko-converter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index cdd7f901c13f..30fc542cfdeb 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -57,6 +57,18 @@ def convertPerfScriptProfile(profile): }, 'data': [], } + =20 + stringTable =3D [] + + stackMap =3D dict() + def get_or_create_stack(frame, prefix): + key =3D f"{frame}" if prefix is None else f"{frame},{prefix}" + stack =3D stackMap.get(key) + if stack is None: + stack =3D len(stackTable['data']) + stackTable['data'].append([prefix, frame]) + stackMap[key] =3D stack + return stack =20 def addSample(threadName, stackArray, time): nonlocal name --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF4ACEB64D8 for ; Wed, 21 Jun 2023 19:45:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbjFUTpY (ORCPT ); Wed, 21 Jun 2023 15:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjFUTpV (ORCPT ); Wed, 21 Jun 2023 15:45:21 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FFB1989; Wed, 21 Jun 2023 12:45:16 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-668704a5b5bso3832656b3a.0; Wed, 21 Jun 2023 12:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376716; x=1689968716; 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=4I/DeYAvJKL2tY/fK091H/iltwlg6WcLtPnIUo8ZacE=; b=jzMG6b2UkbNfHd1BFVwT6bgFtKIc/iOLTIjeja+SpT4LBEe2uFmQNUWTrj42yzIS7R GiF9uck2YJblOcusZCslOsmL2GXCJiTynCGfcjDiiA35bqCbI1XDJPPFGDtwqmtw2tiV GPyo3gtxdcXjWf4l2Rz3cDskyUIF0SPta4ZzvvSR01Go0w3v+ERlFsc1SaBQ0AohtUmS iCGfNC1PCqDsUIFRKi9gAqTqDJjsYdLHIBXehvAFPHjioC5wQ/uP/2o0Alg1wsrT28GF EKcvshBuQorbPymsTO5+eBHCN0NVktV/s5O6D9QA4g3OwnQ8P6oTwUngwt/dYfbnyvLf ve+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376716; x=1689968716; 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=4I/DeYAvJKL2tY/fK091H/iltwlg6WcLtPnIUo8ZacE=; b=R9eHDaKiXFoMPeaK23L3d1NKAnqJJpdcIOE5qbOQs6gp7eK2xbFyKghCYgqEGe6GzE 5M3IpT7YnDRU1KiMfubGMEofwl+uGWexxzubtOWijjCp+bgbHAe6PI3bMRZqi4obwpmH cv6Wiy1SvNOaWFM19mDuIiN3Lmds24EAs6piGzUv8rv9EqKcZ6JNDTHFdGvH0JsHAzxc TMX//3JxJlcWtLle+21FwNGZjJBFRNJeViMxFssdclvMyBeG41MykU1MzrXSc1Awgk+2 2HzBA5HsSNlJNke6ez0hWsnPR4Ld09CisimQdFTB1UnVCyhj4Cg2bSiAkkXJpReMcX3P 2tMw== X-Gm-Message-State: AC+VfDysCsIGIo1gnGPmSEqJaqrabs89eLM9wYb77VgqXsVaaP5aS/8n e54k4iUVXDAKFCJxypVvCdY= X-Google-Smtp-Source: ACHHUZ5sLnOHTFrJfTOIFLkZtDxkM6DjmZPAKEOG41d2PxbrePFhaphUFbN1NOgmLdKR48CmAo0l3Q== X-Received: by 2002:a05:6a00:14c1:b0:668:8493:2552 with SMTP id w1-20020a056a0014c100b0066884932552mr10230277pfu.18.1687376716226; Wed, 21 Jun 2023 12:45:16 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id a3-20020aa78643000000b006666699be98sm3267970pfo.34.2023.06.21.12.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:45:15 -0700 (PDT) Date: Thu, 22 Jun 2023 01:15:09 +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 7/9] scripts: python: implement get or create frame function Message-ID: <4d0ac80521ebd44322a360ac331ce2443a1f0f26.1687375189.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The CATEGORIES list and the USER_CATEGORY_INDEX and KERNEL_CATEGORY_INDEX constants has been introduced. The get_or_create_frame function is responsible for retrieving or creating a frame based on the provided frameString. If the frame corresponding to the frameString is found in the frameMap, it is returned. Otherwise, a new frame is created by appending relevant information to the frameTable's 'data' array and adding the frameString to the stringTable. The index of the newly created frame is added to the frameMap. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index 30fc542cfdeb..866751e5d1ce 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -15,6 +15,13 @@ def isPerfScriptFormat(profile): firstLine =3D profile[:profile.index('\n')] return bool(re.match(r'^\S.*?\s+(?:\d+/)?\d+\s+(?:\d+\d+\s+)?[\d.]+:',= firstLine)) =20 +CATEGORIES =3D [ +{'name': 'User', 'color': 'yellow', 'subcategories': ['Other']}, +{'name': 'Kernel', 'color': 'orange', 'subcategories': ['Other']} +] +USER_CATEGORY_INDEX =3D 0 +KERNEL_CATEGORY_INDEX =3D 1 + def convertPerfScriptProfile(profile): def _createtread(name, pid, tid): markers =3D { @@ -70,6 +77,37 @@ def convertPerfScriptProfile(profile): stackMap[key] =3D stack return stack =20 + frameMap =3D dict() + def get_or_create_frame(frameString): + frame =3D frameMap.get(frameString) + if frame is None: + frame =3D len(frameTable['data']) + location =3D len(stringTable) + stringTable.append(frameString) + =20 + category =3D KERNEL_CATEGORY_INDEX if frameString.find('ka= llsyms') !=3D -1 or frameString.find('/vmlinux') !=3D -1 or frameString.end= swith('.ko)') else USER_CATEGORY_INDEX + implementation =3D None + optimizations =3D None + line =3D None + relevantForJS =3D False + subcategory =3D None + innerWindowID =3D 0 + column =3D None + + frameTable['data'].append([ + location, + relevantForJS, + innerWindowID, + implementation, + optimizations, + line, + column, + category, + subcategory, + ]) + frameMap[frameString] =3D frame + return frame + def addSample(threadName, stackArray, time): nonlocal name if name !=3D threadName: --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D774AEB64DC for ; Wed, 21 Jun 2023 19:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbjFUTqY (ORCPT ); Wed, 21 Jun 2023 15:46:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229825AbjFUTqV (ORCPT ); Wed, 21 Jun 2023 15:46:21 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB511988; Wed, 21 Jun 2023 12:46:20 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3421fb63796so26442785ab.2; Wed, 21 Jun 2023 12:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376780; x=1689968780; 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=Thtk9tiUtPYtTI2fLQD5UkCvaUPoQ9DRCNShUGEYMp0=; b=gSahabEwy5Hh3zXDXTEzS+tGvVUnr9R7Ck3AEIoX5cIb+dCnn2IE0KYinP06Fb/EMV X57O5oZJ+yzFcrOK8I3VrVNVa9taGvOSLWMdfglKt6ETHMuB21BhsCIGVvZdlVGRXjPO hJhT7zjipvI7zxZOiG8/Z1OxdOBXKZSNJa12rl5G8mKuMZ+5N/csQ1t6/0ulm+LVXpJu Gkj6JXBfPNnzshxD1dsOqFRr/meTu9Ozuow1SrZHLKSnaxqzxOxL2HyZMTGDR16oal03 /q+Wfvqu3DYGNZa9+RSvycw6akXac6RH8ZF+SSr9s7g6yOtZTi6yS7/Ysq9rygMcIDfm qS3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376780; x=1689968780; 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=Thtk9tiUtPYtTI2fLQD5UkCvaUPoQ9DRCNShUGEYMp0=; b=Dl6i+0y8DtUCshvLUvHvU21F0r/kAsN/jxf9TZZcHHmlr+X4f9bMFdnqOLNHz4w9Kv wC4dW7jIgCVEjdOO/eoj9KitaSkpCeLeDsR3f63V16ysQcPJWCfG35Tl+75BK/T1OmsT y0gW26i7lTTE+sScbENG0TvZz4zknhfs/BZEGSkxKbhjetEbc4jrAl1IDh0LaNK9IyIX U0zxObK+LqfgtD9Y8uvjfB3psNwvSdkFMDvumqjCK6DD48n9l/GVBffchgJaxCVw55Re cSzrg0Z2kFMeogU5POExGRiDjMvD/bMJMxvfiUS05OeasDk0cTxUoijYemROfGGdV1d+ A7Ng== X-Gm-Message-State: AC+VfDwiJfowQlfzswWK0ml1VeR9C8MzkzTvn6HX/rhA3BrA7YHOccSd 2XYTsnuGH+pJgxpUTuxCJryK53OwzAti1TD1 X-Google-Smtp-Source: ACHHUZ4DzJZ6oW4X5y8F1eGwtxME5iVHvNu3wvNaBGlV6HUy10Uv4T7ZSIpvlQVtyMX9TWDa9YO8YQ== X-Received: by 2002:a92:c10e:0:b0:33f:e84c:8dfd with SMTP id p14-20020a92c10e000000b0033fe84c8dfdmr14113138ile.13.1687376780236; Wed, 21 Jun 2023 12:46:20 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id t12-20020a17090ad50c00b0025e2b703adesm3512336pju.41.2023.06.21.12.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:46:19 -0700 (PDT) Date: Thu, 22 Jun 2023 01:16:12 +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 8/9] scripts: python: Finalize convertPerfScriptProfile and return profile data Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- .../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/p= erf/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': [], } - =20 + stringTable =3D [] =20 stackMap =3D dict() @@ -84,7 +84,7 @@ def convertPerfScriptProfile(profile): frame =3D len(frameTable['data']) location =3D len(stringTable) stringTable.append(frameString) - =20 + category =3D KERNEL_CATEGORY_INDEX if frameString.find('ka= llsyms') !=3D -1 or frameString.find('/vmlinux') !=3D -1 or frameString.end= swith('.ko)') else USER_CATEGORY_INDEX implementation =3D None optimizations =3D None @@ -203,3 +203,36 @@ def convertPerfScriptProfile(profile): =20 stack.append(rawFunc) =20 + if len(stack) !=3D 0: + stack.reverse() + _addThreadSample(pid, tid, threadName, time_stamp, stack) + + thread_array =3D 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 =3D thread['samples']['schema']['time'] + thread['samples']['data'].sort(key=3Dlambda 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': [] + } + --=20 2.34.1 From nobody Wed Feb 11 04:18:04 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B35EBEB64DC for ; Wed, 21 Jun 2023 19:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbjFUTrI (ORCPT ); Wed, 21 Jun 2023 15:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjFUTrG (ORCPT ); Wed, 21 Jun 2023 15:47:06 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0264FE65; Wed, 21 Jun 2023 12:47:06 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-25efb821778so2340487a91.3; Wed, 21 Jun 2023 12:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376825; x=1689968825; 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=B1YrRd+md0IIhC3jIqeqxvAewmHxT4sxnDw+1V2ULFc=; b=Jr0xlHsOkdoU24dUH2EQoSvufaYjE1yWgtUt8I2Jx0sijY8ZUrSXUVM6DsMB828nDo jgpEM1KFVJ5nKeyQInPLRlWwIC4rGSmP0IJP4ygA7G5qcbJg++ICAMit4/EqluArmWhA 0UhPD0eGYW0NXqcqrUYXifWtqjyVZgcdr1EHD7hG586+JSil7/X3SDV+YPnRutk5AYR4 Yv5n2/GGimGq7XO8gdVzxQmNvriTeUCa/PNokBHLXe4bnCqHinGthbHQoHrRgGqvp0QI lvciLdqOyBcwhauFFqkqXJ3w/exq2KtUqbQXdiOwx/+WNVxTe9FY9yrvUpQNa6bP2mJy 5pSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376825; x=1689968825; 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=B1YrRd+md0IIhC3jIqeqxvAewmHxT4sxnDw+1V2ULFc=; b=bXZIADFE3lgwcZNqKvHXwklhENI9hKpQGuJzckQr1Zysak4sxSKu4wIOYqXuEVroYO ksSApflJJTY1ukHuqiQ+PxDjhuLfDVZVwPH2Rc4aTLyOlLtBvfv3fVM90waPpukQ+v1M /YDn46uw0nnME2LCgShhzNmLu60Ffc0dbVlQaClo/Aj5QRWeBb9qVsV9ZVrI7HJwQbIr hYCQ1W2hDb/eh5JE1IkHr2GMQ3hWDU0GLZ8CLSloaGAE4StPOxXTBarhfWZ3nxjyOsD6 HyO+OqSqB12UU5Jvc6qVG7uDGD0jaXzMLbIVs7GhXHI6UsQhntBR88p/vrS+Cph1LWVN AY4Q== X-Gm-Message-State: AC+VfDzPTMw7lNkNZrKdmKTIU/tHEX5DVE1ukUWMwt1ni0rJrXfDLwFo Nf3hWlhM2KfuRwp/SmPKKwY= X-Google-Smtp-Source: ACHHUZ7A246q0F+vrrSBzrKVUZzrMoFxIbVfGCbZvsqftZZTM9zITohw5HsdzBdD1yW+NJZtvAUpEw== X-Received: by 2002:a17:90b:3cc:b0:25e:b055:220c with SMTP id go12-20020a17090b03cc00b0025eb055220cmr11655495pjb.33.1687376825323; Wed, 21 Jun 2023 12:47:05 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id iq22-20020a17090afb5600b00259b729eea9sm3558879pjb.8.2023.06.21.12.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:47:05 -0700 (PDT) Date: Thu, 22 Jun 2023 01:16:58 +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 9/9] scripts: python: Add temporary main function for testing purposes Message-ID: <796905fa13aeb7621825d8a5a370f1fc78bbf298.1687375189.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit introduces a temporary main function for ease of testing. Please note that this function is not intended to be a permanent part of the codebase. The output is serialized as JSON and printed to the standard output (stdout) with an indentation of 2 for better readability. Signed-off-by: Anup Sharma --- tools/perf/scripts/python/firefox-gecko-converter.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index 385a8b77a70a..0f133d9acee9 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -236,3 +236,14 @@ def convertPerfScriptProfile(profile): 'pausedRanges': [] } =20 +def main(): +# inputFile =3D input('Enter input file name: ') + with open('perf_data.txt') as f: + profile =3D f.read() + isPerfScript =3D isPerfScriptFormat(profile) + output =3D convertPerfScriptProfile(profile) + json.dump(output, sys.stdout, indent=3D2) +# print('isPerfScript: {}'.format(isPerfScript)) + +if __name__ =3D=3D '__main__': + main() --=20 2.34.1