Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30688206rwd; Thu, 6 Jul 2023 09:16:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGWhvLnzNKK812LQEI9i1S+lkwVRfrKxTxi6RAd3brWWzHUHHuaxLWDgVircfXxgFymXd+V X-Received: by 2002:a05:6602:348:b0:785:cd78:cfa with SMTP id w8-20020a056602034800b00785cd780cfamr2969860iou.3.1688660160096; Thu, 06 Jul 2023 09:16:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688660160; cv=none; d=google.com; s=arc-20160816; b=epHMwFn6zlfvR6GW30Fe9ET8RJw1/FCbKTOjcskMMOsLCg1dl1bx/oz3ZfbZMjCr+U YWau/c5yVM0hDoxmW4o2EX8jIcenqkZgIrifQkpFfSu6JTfJe8kUNijPLWc2CV9Gg2wA qLfP/ZrewAhmzONPDxkBeSxukFoURivSZvXIckKfGorfSCXvss7V/TnXjTGsHB78mn9I C9MFINPVNwH/vlYYh9ngZvZez8gBTRfrGM5iLgSQjNPHgsxVbh+P1W/4w+XHGgrlCZza BWa1nBGHgzOjGO+ea6JAIoo+PjRaJFKApUHWwZKGCbhXVlv7FZRKVkSkkIErl3gz9CO9 Ry0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=J/q3P7CS9uJYb3EpqCqB4dU/m8Tw67KDptXeIckI6/I=; fh=MK99md1FTzoYv93XnjNqdOcNsAoG1MRaMpmjoeh62+Y=; b=OVD9YQCdAqAGtGW3tASDMRQ/Ysd0/MougocUDvk1tbp44eR6qyUV1rmFwgRhNNEq2K faWEcMlPG/Vr0Cat29pikfsNx21Fp1wFodODjfmAf1D7M6/ufqrf4Bw5ajW8Bdq3WdeW tPlcLJ8NdaxzCPbtPSz6bn92qbwqxQKli04MlTjKqOTeIr2OEZMzvuyatRdlq+Av6V9m iEG0EVI9pci7JZ0qW7Ki5sTqtbeBQjEHMg8fgkrrST81w/8T3cbK4g0JA8tSLTWlPFhw AHv5KnglFlzIV4z508XR2KezjRjRNY3iRgun8MyF0uUVnFnBqdRgLuzQmPjMXDloPTzR EVXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=qOVVnvz1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x69-20020a638648000000b0053eefa04dc0si1669968pgd.276.2023.07.06.09.15.39; Thu, 06 Jul 2023 09:16:00 -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=@google.com header.s=20221208 header.b=qOVVnvz1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233005AbjGFP6N (ORCPT + 99 others); Thu, 6 Jul 2023 11:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbjGFP6M (ORCPT ); Thu, 6 Jul 2023 11:58:12 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1672F9D for ; Thu, 6 Jul 2023 08:58:10 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-401d1d967beso362961cf.0 for ; Thu, 06 Jul 2023 08:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688659089; x=1691251089; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=J/q3P7CS9uJYb3EpqCqB4dU/m8Tw67KDptXeIckI6/I=; b=qOVVnvz1Y7U8AnM0HlDDFWVHldI36d4YXweD21ynFw1Sgrz7XkG4iz6bvnuAzbqMvU AeGPJdTQ/rcAzZfVig9JPhJiA42Hx5k6+z0lifS0Xg44ppSAYakqfsVJrBJwXRXn3Dbu kISCU8SzAS2sMhbgl43Q0zMvUhHfbbu0UcyIbEtdU0lpNjSpTvSVrn86ymR/aX8Jug9U 1/UFyAWajx7SjWeeWaSyTh8pNyVXS1VbJBGT5l3cY1gcmLaMbbiQ7G2OQrZVipgL1aP7 oHk6KqLJ63PjD0OdkP3SGn3QSW3aYbgkhupplcOmSDe4wHahgcOJt0eLQlAs0HFNjYJl xqtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688659089; x=1691251089; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J/q3P7CS9uJYb3EpqCqB4dU/m8Tw67KDptXeIckI6/I=; b=NKyb+FFkd5qNI6w3iukPULX3H/8JEPRgySqMGTKwBNz+4NMxsm5wfS8IZAWWFvkkkw oUwWQQ+hKrvtCFJv518t8WCrr0S8UxkmODRwSfNGymTyWGmm3nr6KhP3WM05y2WWstTO H1nwSFSYjJJ9l+XFTqdVkQD4W186gMxbA+qc/KcJQiWvKVx2+KQhfiuKgibAW7WJYxbT 8D+HMcB2YWH2vfD3hqIIfl8U4OD1RwxLvs4ZcUJPluQZoME2lY47t7iZ9o26ezyKxNEW NvzSHZgvQ4DrRuVTvVXa0D9lqg1ufVsxb6BbsIcJlLfe1mLm/1wAPgiCmI4DJDPR8dKY vLyQ== X-Gm-Message-State: ABy/qLYUjnTCURjwbcP06xex01EM6fvgUbhAWDR6P6QGZoiamFXpFQ9X Y5vXh4qFzlnjroZKONpwjGA49zY1b5qRnWxRopg2UQ== X-Received: by 2002:a05:622a:15ca:b0:403:58e8:2d96 with SMTP id d10-20020a05622a15ca00b0040358e82d96mr143699qty.7.1688659089064; Thu, 06 Jul 2023 08:58:09 -0700 (PDT) MIME-Version: 1.0 References: <4d0ac80521ebd44322a360ac331ce2443a1f0f26.1687375189.git.anupnewsmail@gmail.com> In-Reply-To: From: Ian Rogers Date: Thu, 6 Jul 2023 08:57:57 -0700 Message-ID: Subject: Re: [PATCH 7/9] scripts: python: implement get or create frame function To: Anup Sharma Cc: Namhyung Kim , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 5, 2023 at 1:01=E2=80=AFPM Anup Sharma = wrote: > > On Fri, Jun 23, 2023 at 05:04:56PM -0700, Namhyung Kim wrote: > > On Wed, Jun 21, 2023 at 12:45=E2=80=AFPM Anup Sharma wrote: > > > > > > 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/t= ools/perf/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)) > > > > > > +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 > > > > > > + 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) > > > + > > > + category =3D KERNEL_CATEGORY_INDEX if frameString.fi= nd('kallsyms') !=3D -1 or frameString.find('/vmlinux') !=3D -1 or frameStri= ng.endswith('.ko)') else USER_CATEGORY_INDEX > > > > This line is too long, we usually don't allow long lines > > over 100 characters. > > Thanks for your suggestion. I have taken care in latest version. > Is there any way to add such checks in editor itself ? I used checkpatch.= pl > scripts, however it didnt catch this. Unfortunately checkpatch.pl doesn't work for python code yet. I think using mypy types would be useful: https://github.com/python/mypy Also having docstring on functions would be useful. Some of the code has some fairly complex indirection and it'd be nice to understand why. Thanks, Ian > > Thanks, > > Namhyung > > > > > > > + 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: > > > -- > > > 2.34.1 > > >