Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9888695rwd; Wed, 21 Jun 2023 13:14:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SAUTvA9FdO5F0Uz60AfstVYae2amSkhnkcqpHeIRFb3gi/jHYHEqYHMP7KK10CqAzxM8B X-Received: by 2002:a05:6a20:12cb:b0:123:3675:70e with SMTP id v11-20020a056a2012cb00b001233675070emr2545279pzg.42.1687378470872; Wed, 21 Jun 2023 13:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687378470; cv=none; d=google.com; s=arc-20160816; b=ho601ENnuIR0j+HXkxNcVgEu3+S5M1e0HVJ8EVUlgbTiqGx30MtFYOgKbP2zHclNNb HuqLH4l6rqu2kiJo04m5VmyRRxP6gcheTpaZEP2zTJOs+rlLavt5zo0ZQSRuZ/SSDA6q cUhZOKjP6WEHZvtfV14xJbdqdOmSYoVulQs+pM6YNe18nbkYvMAmkHaUkCgOGQygdgT/ 9ypxeBa62FjdDNHJiQbwI2gCF/pYdt0rYt+gHmDRx/wxglLQpsYMHjPzHnE8tbTbM4Mm +kIr4Ffi2gibW4S+mdrgOtkZE6KDCnTcnLiQFKYACD0fJat9nMws7xY80TduqeL13lw9 kzzw== 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=pZjCGZDhKpXUGSqDazPCwNKoB5sel2LSB5kjV5qg9hw=; b=OHQXLMc2ttnwcfDYea78C2Ra0dHUIh6l602L2gRYjj/necIhyGOP4ZDFOzHHXMZfJI Og0hv0RV1sXp29lz1AGRP2zH9lLW7+aVxgnPWgTC+Y3pVWLWCWPtUuDbFw17Z28hO0rj /xgTxUgHszLk4rWG9AvITj3xBByueXQeQ+EZ7KbCKl3AUf4N32kKvmCyb9o9+x4tE7qy HL935DJOYLvsZRf7manE5iXk1Re2Zc4r4qU8Lbqeg/SBU0q6LfIbnoeFR/G9FjV1uesw kj+fMdRmbXgYZl0r6FQSAv+z/rNRFwK5Nd6SMuD56d49z7hvm8P07P4yLM3jkynIWDoa uRNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hSz94Aif; 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 n3-20020a6546c3000000b005573a9229f0si1269292pgr.841.2023.06.21.13.14.17; Wed, 21 Jun 2023 13:14:30 -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=hSz94Aif; 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 S229645AbjFUTkL (ORCPT + 99 others); Wed, 21 Jun 2023 15:40:11 -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-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-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_NONE,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 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 information such as 'tid', 'pid', 'name', 'markers', 'samples', 'frameTable', 'stackTable', '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/perf/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): firstLine = profile[:profile.index('\n')] return bool(re.match(r'^\S.*?\s+(?:\d+/)?\d+\s+(?:\d+\d+\s+)?[\d.]+:', firstLine)) + +def convertPerfScriptProfile(profile): + + def addSample(threadName, stackArray, time): + nonlocal name + if name != threadName: + name = threadName + # TODO: + # get_or_create_stack will create a new stack if it doesn't exist, or return the existing stack if it does. + # get_or_create_frame will create a new frame if it doesn't exist, or return the existing frame if it does. + stack = reduce(lambda prefix, stackFrame: get_or_create_stack(get_or_create_frame(stackFrame), prefix), stackArray, None) + responsiveness = 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 + } -- 2.34.1