Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5786564rwp; Mon, 17 Jul 2023 09:22:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlFoGLGArQpL6VrKaEzxx+/HMsXqqFsw4HnG17kplcmPZnNXnTbKwHZqTdaucBlnvz7MO2/G X-Received: by 2002:a17:902:788d:b0:1a9:40d5:b0ae with SMTP id q13-20020a170902788d00b001a940d5b0aemr10368263pll.12.1689610973769; Mon, 17 Jul 2023 09:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689610973; cv=none; d=google.com; s=arc-20160816; b=sjMeYe/uuRLqr4GgB6cpI/QYxQGGaNEkbyTa/RKNFh0A8vq9L1GCy3yOvU3/43aCoC W8Hb85szFkycksTbayLuW+eVOUTopfMk4KmJyYtpg4bRrQNNIwZJvt45c80PeSm7d/fy EoUXaMPLie7iqO3nfn44WoS5krlnbGJ31VzEYaAoobr4/Hfnk5ojKuzFvU8ISVNLoTvB dNa6FW5kNn322BCAEa4YKvsXGfkpYtPVF9TrgfXeug46aMFoSVq5vDwur192/SWzJZhd BlS+qvTfwINaWXgoPoTX8XasJMmfEXK9stOuo9tiro41aLze4obCgC06s8bbOwhrBGRq U0Ww== 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=KqQaPv4Fn3MjQuoSouIRvNL/VfuKWqsAXCUL+WpnOZ0=; fh=3KWi32CiXbScBSCQreKUVojR5Z/YN0MoVKCBZxriAXI=; b=RMEbZdxGRlkQPPLhqIEtpzfPIz3l4iDh+a8yC/jMS464LE1Ig5ydlg6aO4gfusS22+ x/4t8/c873DxUtlN2gOspbirJrgFGfE2wIhvcC10hngIXCbzcTN/3vFdBfomnvIKnJPZ kq//2/+aDwDuDLlBfINtSIGCNtlSjm0Up5zQgNxVvYrk8wqekhdG6fc6+N0fNDTjo8hm NbGvumYZ+UzGFPLjZYqoSNm7GxQJAYlj1uBaxfjO1VQBY9Kpq+UnzRGqdvNjL/jrQSvK RItXFB9jbqWkBAJN7co63FeXT+X3gv7ZkyY/UPlVitR6nnjMEWtXP9BkGDUVvTtP5uLb yMbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Ji7e2PjD; 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 d14-20020a170902654e00b001b8a8f7af21si52385pln.557.2023.07.17.09.22.40; Mon, 17 Jul 2023 09:22:53 -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=Ji7e2PjD; 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 S231636AbjGQQNA (ORCPT + 99 others); Mon, 17 Jul 2023 12:13:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232043AbjGQQMn (ORCPT ); Mon, 17 Jul 2023 12:12:43 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 704B3FC; Mon, 17 Jul 2023 09:12:41 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b8b2b60731so25096855ad.2; Mon, 17 Jul 2023 09:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689610361; x=1692202361; 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=KqQaPv4Fn3MjQuoSouIRvNL/VfuKWqsAXCUL+WpnOZ0=; b=Ji7e2PjDkY0KhMv59NQvxUS4U3A78b5Zmb55N6a/DLaQp8lg+uwHECUlX4u0u77pvI +M3yBW4FOhvuJUrjG9BT99Jh1CGh6U+4OtmovQc7U/rKde4XzMJrXmRZAhxaYN0bqV6S gTTgqJKzm/RBfIDX4v8ZKkf9wFANeZBer02oCmQeiRJasoXzceh+1WtITodPlhYbaoTV OhOKaKLQGTgmTwZyuQcBVYy4l8XXmB5VbRcG8eIlWih0e3oxnuPXUUaVoDUmPBEosZc7 pWpjl5LpHiUKam7RJAYX/t2m/n8bhjZ5cuD8q/dNjKXx/dw8U+FHfVfz+Vj7A/bhVHOg HkWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689610361; x=1692202361; 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=KqQaPv4Fn3MjQuoSouIRvNL/VfuKWqsAXCUL+WpnOZ0=; b=Nsdw6i7VkpsNgzK0mc9rfnbwRXye62kwruHwmZ/LifLAAI5mm/IJaCvSV/Bz35AHQO 5snKtB9hmKD4FyAjKm1gE01ASI9H/YM/eS+QyWEdhbKGMh4v4wyovfWdZpMQLfL70ttC 0dIJgbpsrdvhN9IjPdPWgfO9KzGwZl8bRcD3YOEQ+5ldR34hZXXb8cy9hemM2LFSacEu KaxIstUTvzRGcTASrcdzzHtssb3SFB5tz/j/fpyIkYQ62FlJG8m6qfSW8HUqe4JtUYvT zXVIrxTXuRQHH8U9rHM/xYxzOzlKDRPFsrRygwIBxIeLi83y7W2CloXen/y6N5br/N9j leeA== X-Gm-Message-State: ABy/qLZ1CaVSTcSf+wQfsK4l3yPns9cwoR9hP7OIBddflEQDss3M9+P7 sobzFc0RykH/s4b3Om8VuaM= X-Received: by 2002:a17:902:e743:b0:1b8:b4d5:4c3d with SMTP id p3-20020a170902e74300b001b8b4d54c3dmr13943395plf.51.1689610360457; Mon, 17 Jul 2023 09:12:40 -0700 (PDT) Received: from yoga ([2400:1f00:13:50e2:5893:783e:fde0:1bce]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001b86f1b5797sm53058plg.302.2023.07.17.09.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 09:12:40 -0700 (PDT) From: Anup Sharma X-Google-Original-From: Anup Sharma Date: Mon, 17 Jul 2023 21:42:32 +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 6/6] scripts: python: implement get or create frame and stack function Message-ID: References: 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_NONE,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:44:21AM -0700, Ian Rogers wrote: > On Mon, Jul 10, 2023 at 4:15 PM Anup Sharma wrote: > > > > Complete addSample function, it takes the thread name, stack array, > > and time as input parameters and 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 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. > > > > 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. > > > > Signed-off-by: Anup Sharma > > --- > > .../scripts/python/firefox-gecko-converter.py | 57 ++++++++++++++++++- > > 1 file changed, 56 insertions(+), 1 deletion(-) > > > > diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py > > index 6c934de1f608..97fbe562ee2b 100644 > > --- a/tools/perf/scripts/python/firefox-gecko-converter.py > > +++ b/tools/perf/scripts/python/firefox-gecko-converter.py > > @@ -21,6 +21,8 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ > > from perf_trace_context import * > > from Core import * > > > > +USER_CATEGORY_INDEX = 0 > > +KERNEL_CATEGORY_INDEX = 1 > > thread_map = {} > > start_time = None > > > > @@ -34,7 +36,12 @@ CATEGORIES = [ > > PRODUCT = os.popen('uname -op').read().strip() > > > > def trace_end(): > > - thread_array = thread_map.values())) > > + thread_array = list(map(lambda thread: thread['finish'](), thread_map.values())) > > With a class this will be a more intuitive: > > thread.finish() I have made the changes. Thanks for the suggestion. > > + > > +# Parse the callchain of the current sample into a stack array. > > + for thread in thread_array: > > + key = thread['samples']['schema']['time'] > > I'm not sure what 'schema' is here. Worth a comment. Thanks, I am planning to add hyper-link as a the comment. Like this: # https://github.com/firefox-devtools/profiler/blob/53970305b51b9b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L216 However it is going to exceed 100 characters limit. If I wrap it around, it will look ugly. Any suggestions? > > > + thread['samples']['data'].sort(key=lambda data : float(data[key])) > > Perhaps there is a more intention revealing name than "data". Noted. I will change it. > > > > result = { > > 'meta': { > > @@ -106,7 +113,55 @@ def process_event(param_dict): > > } > > stringTable = [] > > > > + stackMap = dict() > > + def get_or_create_stack(frame, prefix): > > Can you comment what frame and prefix are with examples, otherwise > understanding this function is hard. I am using more descriptive names now. I have also added a comment like this to the function: """Gets a matching stack, or saves the new stack. Returns a Stack ID.""" Will be reflected in v4. > > + key = f"{frame}" if prefix is None else f"{frame},{prefix}" > > + stack = stackMap.get(key) > > + if stack is None: > > + stack = len(stackTable['data']) > > + stackTable['data'].append([prefix, frame]) > > + stackMap[key] = stack > > + return stack > > + > > + frameMap = dict() > > + def get_or_create_frame(frameString): > > s/frameMap/frame_map/ > s/frameString/frame_string/ > > These variable names aren't going a long way to helping understand the > code. They mention frame and then the type, which should really be > type information like ": Dict[...]". Can you improve the names as > otherwise we effectively have 3 local variables all called "frame". I have made the changes. Thanks for the suggestion. > > + frame = frameMap.get(frameString) > > + if frame is None: > > + frame = len(frameTable['data']) > > + location = len(stringTable) > > + stringTable.append(frameString) > > + category = KERNEL_CATEGORY_INDEX if frameString.find('kallsyms') != -1 \ > > + or frameString.find('/vmlinux') != -1 \ > > + or frameString.endswith('.ko)') \ > > + else USER_CATEGORY_INDEX > > Perhaps make this a helper function, symbol_name_to_category_index. I am trying to find if I can use cpu_mode instead of this as suggested by Namhyung. If not, I will add a helper function in the later version. > > + implementation = None > > + optimizations = None > > + line = None > > + relevantForJS = False > > Some comments on these variables would be useful, perhaps just use > named arguments below. Okay, this variable comes from Gecko format, now adding link might make it understandable. > > + subcategory = None > > + innerWindowID = 0 > > + column = None > > + > > + frameTable['data'].append([ > > + location, > > + relevantForJS, > > + innerWindowID, > > + implementation, > > + optimizations, > > + line, > > + column, > > + category, > > + subcategory, > > + ]) > > + frameMap[frameString] = frame > > + return frame > > + > > def addSample(threadName, stackArray, time): > > + nonlocal name > > + if name != threadName: > > + name = threadName > > A comment/example would be useful here. Noted. > > > + stack = reduce(lambda prefix, stackFrame: get_or_create_stack > > + (get_or_create_frame(stackFrame), prefix), stackArray, None) > > Thanks, > Ian > > > responsiveness = 0 > > samples['data'].append([stack, time, responsiveness]) > > > > -- > > 2.34.1 > >