Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5818241rwp; Mon, 17 Jul 2023 09:53:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlH8+X3lua/b5Phk9/wF/oNJ0QyMSco7AafyInXAl5ev3lpwCCgcXvP+Aiz43Cj3ODMNnpyC X-Received: by 2002:a05:6a20:12d0:b0:134:c859:5eef with SMTP id v16-20020a056a2012d000b00134c8595eefmr3673985pzg.33.1689612807020; Mon, 17 Jul 2023 09:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689612807; cv=none; d=google.com; s=arc-20160816; b=Bl44eTaVpp1leNB8p0KnqV73NTAaHIEkBy7Bvz7yzZ+3/qR7mfB+4j5stVBjsmz/QM OsEV/1Onbs3IY9d4cquZqL8VOvhGkscmnT0yqwov7xVRP43wbNB5TylCvv2SHVmUHfD6 McRA8zNxxaHfhvyz578rCOm+muIQXFMExV7iKE4P/8cEZPPriIqOfDwiZIeHQvmHAjGY A2CXYVQrP+TXmXjL46JwtfWyyQQrvDOT5w7OdAWTtXAPsQfS7MeJ7qpDxJkc/49xZfSP GxubH2Mfeh1mVA6YHgu6HpIJkbdcQQiqOta5UA63cR0GUkXA4kmgsKxGxFb6XmrtnETJ 4gwA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=UvHbtMz36nAYwOqM6y1BD7XGn+T3QzVrtohh3Auo9x0=; fh=3KWi32CiXbScBSCQreKUVojR5Z/YN0MoVKCBZxriAXI=; b=Mm313zfSwuFug2X6JD6OzYImlNORUnL9chL5h6RVWeEl2tYcp/gWJmZsC+qmuJ71Gz ko8Q22SOjPrkZz4QRdGY7+4sYcIqtN8OJuOrNVF9vqVhZPIFLox+MdqIDUygpaOrgRqU ebl3TXZfKCxwb+q7n01dztOB8f5mf393jGY8hHsU2iibvZKtDv915s+kn3pWqRGwm8uD 8MpGW+Gxom7vZRx6Mt+PQImFHszKVAFZCmL/vRMzbHnljvdQZ3FRgVuzivrCyYTi0Izd rGWrr/FJf0r9MEiot5GKkzF4rbRUOBULvJMMnMQoEPZSuqcUftiO1baFQ9y0Fr8OIWAv GohQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=AqylJkL0; 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 v24-20020a63f218000000b0055fdd303745si43506pgh.421.2023.07.17.09.53.01; Mon, 17 Jul 2023 09:53:26 -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=AqylJkL0; 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 S231633AbjGQP7T (ORCPT + 99 others); Mon, 17 Jul 2023 11:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjGQP7R (ORCPT ); Mon, 17 Jul 2023 11:59:17 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D978DD8; Mon, 17 Jul 2023 08:59:16 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-263374f2f17so2446423a91.0; Mon, 17 Jul 2023 08:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689609556; x=1692201556; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=UvHbtMz36nAYwOqM6y1BD7XGn+T3QzVrtohh3Auo9x0=; b=AqylJkL03+2isSpBoKjJFPjXHrvY3UnQ+NrdyeGbO9Z+RIjgH/UsOoHyn9QEjuGtlF Vqht2ZB4fMOwaxyudNPQConB7bg5tD7K1LS8o663X9w0VnN0SpgKq47jeNMsrx9aqmwM kOXSucuBoRct17bUd4VS4wndJmbmMM8zkZxlTla6xMcs6WSS38Dqgr0qmwkJzxYYi0uf dbSmeY1gNX9Po5p5hRGvzWnhXb+I+X1cJEhPdjh9aab1I5AU/3RRMcmq9Nd2VjRarjj2 SIIvs3cegsF3e0zcuKTQHSDi+0FB7WKGpqsSP+9IhYElDiWHLT6jqjk7OIz8bHqZTpoW /J2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689609556; x=1692201556; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UvHbtMz36nAYwOqM6y1BD7XGn+T3QzVrtohh3Auo9x0=; b=dXXcVWMJ+yyE0h8USoPAndwsiHJvJXB5RjdgjLYRH079ymeTnY3HWcziNkzBJChna1 jQZzQKjNddWvEMybFMAoon5E6jhVmK8fGCUdFsetnzalcVAE7r38lcgPvYLx+P4ju1GH rVIXsExMrR26IoPiJ6RpM+5QAeTpKfKUlsHfaTsvrwyoJ0M8kaRUhnTl8zP7mfC8q8p/ H22E/PGSmWiguS9/duUTzJXs8cj3sFLsS0d8/UjPt5s0IW/clm9kDBIvtp0FMAo1/Tow +vishimx4fKeA0EgxQ92hsFFr5dDSUwGjK1ACvRYvZwr07rxqHj/TNXeNXzUjVYOUrmQ o2Mw== X-Gm-Message-State: ABy/qLa/15+QZ8J1uvsAcKJsZih3xZqolIqDNLlY6isk40XaZd2fQk4D AvkWp8Q2bZ9tx7aKLfGnPK8= X-Received: by 2002:a17:90a:38e1:b0:262:e6c6:c2ec with SMTP id x88-20020a17090a38e100b00262e6c6c2ecmr9521732pjb.33.1689609555677; Mon, 17 Jul 2023 08:59:15 -0700 (PDT) Received: from yoga ([2400:1f00:13:50e2:5893:783e:fde0:1bce]) by smtp.gmail.com with ESMTPSA id j6-20020a17090a840600b002641a9faa01sm5056939pjn.52.2023.07.17.08.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 08:59:15 -0700 (PDT) From: Anup Sharma X-Google-Original-From: Anup Sharma Date: Mon, 17 Jul 2023 21:29:07 +0530 To: Ian Rogers Cc: Anup Sharma , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 5/6] scripts: python: Implement add sample function and return finish Message-ID: References: <8b80f803ffbed4c84c0c63b3e1dae155a66ac1f2.1689024635.git.anupnewsmail@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 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 On Wed, Jul 12, 2023 at 10:35:16AM -0700, Ian Rogers wrote: > On Mon, Jul 10, 2023 at 4:14 PM Anup Sharma wrote: > > > > The addSample function appends a new entry to the 'samples' data structure. > > > > 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 | 25 +++++++++++++++++++ > > 1 file changed, 25 insertions(+) > > > > diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py > > index 39818a603265..6c934de1f608 100644 > > --- a/tools/perf/scripts/python/firefox-gecko-converter.py > > +++ b/tools/perf/scripts/python/firefox-gecko-converter.py > > @@ -106,11 +106,36 @@ def process_event(param_dict): > > } > > stringTable = [] > > > > + def addSample(threadName, stackArray, time): > > I think these aren't following general naming conventions: > https://peps.python.org/pep-0008/#function-and-variable-names > So use thread_name, stack_array. Noted. Will fix in v4. > > + 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 > > + } > > I think the use of a dictionary here isn't idiomatic. Rather than use > a dictionary I think you can make a class Thread, then have functions > passed self called addSample and finish. So: agreed. > class Thread: > def addSample(self, thread_name: str, stack_array: list[...], time: int): > responsiveness = 0 > self.samples['data'] ... > ... > thread.addSample(threadName, stack, time_stamp) > > Should samples be its own class here? I have changed the code to use object oriented approach by taking reference from simpleperf. I will make class Thread and Sample. > Thanks, > Ian > > > + > > def _addThreadSample(pid, tid, threadName, time_stamp, stack): > > thread = thread_map.get(tid) > > if not thread: > > thread = _createThread(threadName, pid, tid) > > thread_map[tid] = thread > > + thread['addSample'](threadName, stack, time_stamp) > > > > # Extract relevant information from the event parameters. The event parameters > > # are in a dictionary: > > -- > > 2.34.1 > >