From nobody Wed Feb 11 05:41:50 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 46917EB64DD for ; Wed, 21 Jun 2023 19:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbjFUTmA (ORCPT ); Wed, 21 Jun 2023 15:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjFUTl7 (ORCPT ); Wed, 21 Jun 2023 15:41:59 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52EE81733; Wed, 21 Jun 2023 12:41:57 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b52864b701so48363325ad.3; Wed, 21 Jun 2023 12:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687376517; x=1689968517; 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=8EOjusGezgUEDaoouw0ul4hE6YXmt391w2kXuFkLv/E=; b=l3fqFnRFxZnqbhQOOMFmGaKdbzianAEuvAsWRZi2xnf6kpwmW78uMK7SYQcz99HQOV G3JNbW1/SBgFXl5woRvHfbAOoxkKBBN5jtrA/w+txXRJ0eMvzTaiEFW7+56aE16nw/1G s7Qk5O8kTFut6rh5YhzhfJ9s9E3aiTfh/fqM9BzN5gUIyCyCGH/F32pCDXurmmfoZjNZ g7eEx4SgM/ddPfqtEKf52CnX2n86nq7Bkos+k66rWmigk2Mda+rspj5t+oXayTFY0fBm B4zVoG5rYTZxf4OBmuCrOXZ8Ec+PGkyUgwTECUUv/AVKz8f4jYUDhZXXp0qy3aOJbB9D 9RGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687376517; x=1689968517; 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=8EOjusGezgUEDaoouw0ul4hE6YXmt391w2kXuFkLv/E=; b=RHvFTfI0oR6fyC4lg9WSgYg+xP6ysJaWsKiH5JBtNlnZy1unN9AgF22xW8FSlqP8xM CwAebp2KRg0gJ5dMTYYJHiN3SSJjBrvHFhDkqeBCQieVmmOIA6yeOd9GmLInyuFzvJDY 1DYzExnnMkDvUB5+M9lQNFnthIci9KG7JsonkUJz14+mZ73GxoCvKZ5DMG1B0ycCcoS4 xzolBFuNBZgKF7N6maVLcfboqeVHf53sNxVR64Weiku6wmtDG8c1nDmtBVs7U4ml7vJL lomsuicRmZ/rvHWvY0Ap9j7z2GD7WDlw2WhfOeX3WgOhS/U/Eb99lHAU3n3/bcbhc5sx jr9A== X-Gm-Message-State: AC+VfDwku36HeQ6y3/mzljz+X+JqJZ2ruPnTmcv7Rz75euVSie26lXcY QCSiReAK2WLEnLsKr94V68s= X-Google-Smtp-Source: ACHHUZ5lbjS2yji51QQw2AqUU4zvpeVZrjVQzZsWH7OScLOZWinv5Wiylwwt33cJWwGei7hS2UuPVQ== X-Received: by 2002:a17:902:a3c7:b0:1b5:361:cefe with SMTP id q7-20020a170902a3c700b001b50361cefemr14038204plb.52.1687376516573; Wed, 21 Jun 2023 12:41:56 -0700 (PDT) Received: from yoga ([2400:1f00:13:6258:556c:aad7:2240:7612]) by smtp.gmail.com with ESMTPSA id u13-20020a170902a60d00b001ae0a4b1d3fsm3883794plq.153.2023.06.21.12.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 12:41:55 -0700 (PDT) Date: Thu, 22 Jun 2023 01:11:48 +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 4/9] scripts: python: Implement parsing of input data in convertPerfScriptProfile Message-ID: <3772bce9068962f2a4c57672e919ebdf30edbc5c.1687375189.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 lines variable is created by splitting the profile string into individu= al lines. It allows for iterating over each line for processing. The line is considered the start of a sample. It is matched against a regul= ar expression pattern to extract relevant information such as before_time_stam= p, time_stamp, threadNamePidAndTidMatch, threadName, pid, and tid. The stack frames of the current sample are then parsed in a nested loop. Each stackFrameLine is matched against a regular expression pattern to extract rawFunc and mod information. Also fixed few checkpatch warnings. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/p= erf/scripts/python/firefox-gecko-converter.py index 0ff70c0349c8..e5bc7a11c3e6 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 import re import sys import json @@ -14,13 +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)) =20 -def convertPerfScriptProfile(profile):=20 +def convertPerfScriptProfile(profile): =20 def addSample(threadName, stackArray, time): nonlocal name if name !=3D threadName: name =3D threadName - # TODO:=20 + # TODO: # get_or_create_stack will create a new stack if it doesn't ex= ist, or return the existing stack if it does. # get_or_create_frame will create a new frame if it doesn't ex= ist, or return the existing frame if it does. stack =3D reduce(lambda prefix, stackFrame: get_or_create_stac= k(get_or_create_frame(stackFrame), prefix), stackArray, None) @@ -54,3 +55,60 @@ def convertPerfScriptProfile(profile): thread =3D _createtread(threadName, pid, tid) threadMap[tid] =3D thread thread['addSample'](threadName, stack, time_stamp) + + lines =3D profile.split('\n') + + line_index =3D 0 + startTime =3D 0 + while line_index < len(lines): + line =3D lines[line_index] + line_index +=3D 1 + # perf script --header outputs header lines beginning with # + if line =3D=3D '' or line.startswith('#'): + continue + + sample_start_line =3D line + + sample_start_match =3D re.match(r'^(.*)\s+([\d.]+):', sample_start= _line) + if not sample_start_match: + print(f'Could not parse line as the start of a sample in the "= perf script" profile format: "{sample_start_line}"') + continue + + before_time_stamp =3D sample_start_match[1] + time_stamp =3D float(sample_start_match[2]) * 1000 + threadNamePidAndTidMatch =3D re.match(r'^(.*)\s+(?:(\d+)\/)?(\d+)\= b', before_time_stamp) + + if not threadNamePidAndTidMatch: + print('Could not parse line as the start of a sample in the "p= erf script" profile format: "%s"' % sampleStartLine) + continue + threadName =3D threadNamePidAndTidMatch[1].strip() + pid =3D int(threadNamePidAndTidMatch[2] or 0) + tid =3D int(threadNamePidAndTidMatch[3] or 0) + if startTime =3D=3D 0: + startTime =3D time_stamp + # Parse the stack frames of the current sample in a nested loop. + stack =3D [] + while line_index < len(lines): + stackFrameLine =3D lines[line_index] + line_index +=3D 1 + if stackFrameLine.strip() =3D=3D '': + # Sample ends. + break + stackFrameMatch =3D re.match(r'^\s*(\w+)\s*(.+) \(([^)]*)\)', = stackFrameLine) + if stackFrameMatch: + rawFunc =3D stackFrameMatch[2] + mod =3D stackFrameMatch[3] + rawFunc =3D re.sub(r'\+0x[\da-f]+$', '', rawFunc) + + if rawFunc.startswith('('): + continue # skip process names + + if mod: + # If we have a module name, provide it. + # The code processing the profile will search for + # "functionName (in libraryName)" using a regexp, + # and automatically create the library information. + rawFunc +=3D f' (in {mod})' + + stack.append(rawFunc) + --=20 2.34.1