From nobody Sun Feb 8 21:48:33 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 B9763EB64DD for ; Tue, 18 Jul 2023 22:53:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231384AbjGRWwv (ORCPT ); Tue, 18 Jul 2023 18:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjGRWws (ORCPT ); Tue, 18 Jul 2023 18:52:48 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F6FFEE; Tue, 18 Jul 2023 15:52:22 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-666ed230c81so6299866b3a.0; Tue, 18 Jul 2023 15:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689720741; x=1692312741; 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=AESNSKu76AwBKDmM6LgRhommsrTxqaO6oADrlXIeM64=; b=gvtye7OYtvyAywIXMhCIK07kjzJzgri2LsA/WZAVczuZuJQjAeR6DmBeDGBw5TGPqw r7RmWVBvLhlinXTGJeSmoyJN9i0604XOOq8vGBK2L8ddyOQ3rkkO8TenTR74Q8I4rWmq 1R1GZzHyuQFQKGeH1ff5EERFFnXn0Hyvnw1x+J6Y+O7BZjwhcmYi+tTyjA5+UY2vtLfC zCKfkdCqrV6vtp9BX7rxe97zAXlbXiUI6oixBEV6EguOEB9Mg7ooV4bw+XUHmittbOCT xExiD/x5gxaPx4/zl20oBsKEQhz+YgWwyrL+MpUUeshIbvST1JFNKXU5WWu28ibEqx3N AxGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689720741; x=1692312741; 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=AESNSKu76AwBKDmM6LgRhommsrTxqaO6oADrlXIeM64=; b=hHEcnZ0WR5/GE5oFMp5Y5BUwpTrmDTKDp2gIgNKzuoGMg1N9GI0s8a/BRMndrQ0TZU A8bPag2BjNM7coF3x+hIe+nPhJ15q4LCG0C1CCEcpAgqKbrPeDfImeCkKJzYDjt0yLKW gvxjEZj2xJD/VtVZZKwGK24R7dY5lLzpyKDKSFwPWkWgCdyPoacrE6dPQMuK/sE17cTo tQkx4JBoOOgSHJWZmSqVEhWDzSqpaG7CPUVDcnnRn9iw9O7HDiFvNhfaACNtqUEY9N2g UHs+YiwG/sb3jHSzvWaNtzFz0A4w0DZ48KJon1rLNVoFKp8Efnby/N2orz4SELZ7awF8 JiEw== X-Gm-Message-State: ABy/qLb0BFu9AcSVJiMYhp7GoAB09UsgfJnAEgtVSYXLc3UWHuHNt4fn TJgEVt920CKN9UcwxEAoiG8= X-Google-Smtp-Source: APBJJlFv1a/dZKM9JVmWRbsLvfc2IoXCwZIL/wLdapRaYK1KM4xxmWOn/IR3cQz9bWwJ7Hq0+pK0Pw== X-Received: by 2002:a05:6a20:12c9:b0:12e:c481:7072 with SMTP id v9-20020a056a2012c900b0012ec4817072mr914193pzg.37.1689720741264; Tue, 18 Jul 2023 15:52:21 -0700 (PDT) Received: from yoga ([2400:1f00:13:be68:c61a:77e0:3624:e4f6]) by smtp.gmail.com with ESMTPSA id a11-20020a637f0b000000b005633941a547sm1943769pgd.27.2023.07.18.15.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 15:52:20 -0700 (PDT) Date: Wed, 19 Jul 2023 04:22:13 +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 v4 6/6] perf scripts python: Implement add sample function and thread processing Message-ID: <6771dcadf7507ad8916ba2398d22f873579b0505.1689718662.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 stack has been created for storing func and dso from the callchain. The sample has been added to a specific thread. It first checks if the thread exists in the Thread class. Then it call _add_sample function which is responsible for appending a new entry to the samples list. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index ae69c0a4af13..9c4393787daa 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -156,6 +156,25 @@ class Thread: )) return frame_id =20 + def _add_sample(self, comm: str, stack: List[str], time_ms: Milliseconds)= -> None: + """Add a timestamped stack trace sample to the thread builder. + Args: + comm: command-line (name) of the thread at this sample + stack: sampled stack frames. Root first, leaf last. + time_ms: timestamp of sample in milliseconds. + """ + # Ihreads may not set their names right after they are created. + # Instead, they might do it later. In such situations, to use the latest= name they have set. + if self.comm !=3D comm: + self.comm =3D comm + + prefix_stack_id =3D reduce(lambda prefix_id, frame: self._intern_stack + (self._intern_frame(frame), prefix_id), stack, None) + if prefix_stack_id is not None: + self.samples.append(Sample(stack_id=3Dprefix_stack_id, + time_ms=3Dtime_ms, + responsiveness=3D0)) + def _to_json_dict(self) -> Dict: """Converts current Thread to GeckoThread JSON format.""" # Gecko profile format is row-oriented data as List[List], @@ -234,9 +253,36 @@ def process_event(param_dict: Dict) -> None: if not start_time: start_time =3D time_stamp =20 + # Parse and append the callchain of the current sample into a stack. + stack =3D [] + if param_dict['callchain']: + for call in param_dict['callchain']: + if 'sym' not in call: + continue + stack.append(f'{call["sym"]["name"]} (in {call["dso"]})') + if len(stack) !=3D 0: + # Reverse the stack, as root come first and the leaf at the end. + stack =3D stack[::-1] + + # During perf record if -g is not used, the callchain is not available. + # In that case, the symbol and dso are available in the event parameters. + else: + func =3D param_dict['symbol'] if 'symbol' in param_dict else '[unknown]' + dso =3D param_dict['dso'] if 'dso' in param_dict else '[unknown]' + stack.append(f'{func} (in {dso})') + + # Add sample to the specific thread. + thread =3D tid_to_thread.get(tid) + if thread is None: + thread =3D Thread(comm=3Dcomm, pid=3Dpid, tid=3Dtid) + tid_to_thread[tid] =3D thread + thread._add_sample(comm=3Dcomm, stack=3Dstack, time_ms=3Dtime_stamp) + # Trace_end runs at the end and will be used to aggregate # the data into the final json object and print it out to stdout. def trace_end() -> None: + threads =3D [thread._to_json_dict() for thread in tid_to_thread.values()] + # Schema: https://github.com/firefox-devtools/profiler/blob/53970305b51b9= b472e26d7457fee1d66cd4e2737/src/types/gecko-profile.js#L305 gecko_profile_with_meta =3D { "meta": { --=20 2.34.1