Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36053338rwd; Mon, 10 Jul 2023 17:18:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGRvcmIh5NkB8M9kYssrNNO77NQxUebyID2YjKB+4SlgMa5D/A1iCG0Hpg1tmjx4MVk7svD X-Received: by 2002:a17:906:7e11:b0:967:e015:f542 with SMTP id e17-20020a1709067e1100b00967e015f542mr13247927ejr.44.1689034686708; Mon, 10 Jul 2023 17:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689034686; cv=none; d=google.com; s=arc-20160816; b=oEDhqeIaT4SrNgRBYzzi9bO+t73O2ISEpf8U70LZ5sz+vMCnXCLy97Vvm1afOweX8N njMXKCbQeq+rSAqzQyLPdijxliOP2unS5en7RgFjFkVYPvyORMTPAFxW48tSQtiCUlfJ KnKQ2yyKgDkTkeJRgWWtknOOt0D+TzYvo6WkLMt8H+oFXyjAA8i/l4qNUg9Iw3XCnMej 3ACHK5mmTBPytGWdm1cvAukhdcUazmqCYDGTJvNakCucnk/jyTyuLLIP74X/KVOk+39h tSMATLVBQP8SLDx1GBA8ogbjVMXdzrSKh8uoyIdtUP0oTGoY09VBJvmkn4Ze9mx3ivy8 pf0w== 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-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=PBGlQsi0NW10Pr3RCzCrk5y26OBsbX2q8LbZgkSF6bI=; fh=74JdZCcncRx9vhK0g0jCPyLh0X9SLH8kcZrk5gmejJ4=; b=I96uN63f1X37JgxpCta3p9mMx/X0TQsWhrPucZsC46IEvssiEoQmyuvJiWG5vrDaX7 rE0OmiivzMdcOBM9EGq2pW45JiYxo2306dmnI/gqYMAXutByJKgmr9VYbnkpFbUejsry dobCKkrqdIz/vAnkZI+EUw95fgvG7scJIf8zmUTHiHflf8M5WSPjvnFkLs5U7VNkXYKJ Eb4cTR9Zs0fcBGR5qLVbBgWB0OVjiK+UOXo21SGekSrV/8mmlyQvfG4AyM79/hwKrXtU qF+XVRgrttHrWGqGW0PZm6789NdRyqBNkVl7OIqF+UcT0sOoccoRZVk9nOjCuTyby+JX jwjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OXkAr0vN; 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 y15-20020a170906470f00b00973a7283de2si630046ejq.505.2023.07.10.17.17.41; Mon, 10 Jul 2023 17:18:06 -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=OXkAr0vN; 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 S230446AbjGJXNW (ORCPT + 99 others); Mon, 10 Jul 2023 19:13:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbjGJXNT (ORCPT ); Mon, 10 Jul 2023 19:13:19 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581B99E; Mon, 10 Jul 2023 16:13:18 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-666fb8b1bc8so4468817b3a.1; Mon, 10 Jul 2023 16:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689030798; x=1691622798; 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=PBGlQsi0NW10Pr3RCzCrk5y26OBsbX2q8LbZgkSF6bI=; b=OXkAr0vN5GVizLDpJNmNvYVQjQp+Qj7fP8tDpQxWGxT6s2HOgYPgsgTnfzDoYHm6dx 4RcrVFIT2gE18YGPJXQKkMiewTuvJOdY4DIM3LJwSW0ABQ2vtDI2xvaVFSE42p84ovd9 PsBXCf9wa1B+ctIubXlKq9Y9NlX4zN4ugjWFYDr0DeSVAIWhktsSkXUiHfPZt8+9VHs4 pRoboiKKOorKqUXkpYYTdoHYiizUxXILf5WugY+KXR8lDumopRYexlOlJpz3xmupdBsa 6wWcyyRSlUMxVyMZBznBLi08YqencKeP9FYkpci2StgBYOOUsD2LH3+rwiZ9s2a9MLHm crbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689030798; x=1691622798; 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=PBGlQsi0NW10Pr3RCzCrk5y26OBsbX2q8LbZgkSF6bI=; b=O3Gft5vmZNNvZYCqLUryDh9yK4R4FxnbV23TehCVS/y1VqXIA+F4hhHUKIpXJjXLzI XJ+hCcDdS4ddX22kpO1+Yr4kJ8nLb+kqtbLV6lK8zIOkeTRC3aFYV3JlRI1MGO0Mqaoj zgvPJzyb8W8JQrrrG85JDapQDjs4uReVeGTKPdio7gd9M+a9fFRirF1beO5VYC5vjmr2 FTC42LIS38rkJGdHGMUUm10uOt5JNU1TnqEumql3gJM0jJ++6OebUh9Kjp8l6HA7gSFU Lyc21CQkaOukNeIQLf8rCQUG7I2bSe9u4nQsdtHf699OhPxPnEwuovTZwHP50jIkrxaB QfGw== X-Gm-Message-State: ABy/qLZdLynFaT0wq/ARkt+5iLMALt247F+UE9uMSZxw2lRKPkdRRKVZ W09sIehSBYcAwTYvDCjuGMA= X-Received: by 2002:a05:6a20:1601:b0:10d:5430:c8d6 with SMTP id l1-20020a056a20160100b0010d5430c8d6mr18241619pzj.0.1689030797581; Mon, 10 Jul 2023 16:13:17 -0700 (PDT) Received: from yoga ([2400:1f00:13:76f2:868d:bc7d:562b:a5bb]) by smtp.gmail.com with ESMTPSA id fe23-20020a056a002f1700b0066ebaeb149dsm314797pfb.88.2023.07.10.16.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 16:13:17 -0700 (PDT) Date: Tue, 11 Jul 2023 04:43:10 +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 v3 3/6] scripts: python: thread sample processing to create thread with schemas Message-ID: <70fd94954a3872caeef5851607b245394149f4a9.1689024635.git.anupnewsmail@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 The _addThreadSample function is responsible for adding a sample to a specific thread. It first checks if the thread exists in the thread_map dictionary. The markers structure defines the schema and data for thread markers, including fields such as 'name', 'startTime', 'endTime', 'phase', 'category', and 'data'. The samples structure defines the schema and data for thread samples, including fields such as 'stack', 'time', and 'responsiveness'. The frameTable structure defines the schema and data for frame information, including fields such as 'location', 'relevantForJS', 'innerWindowID', 'implementation', 'optimizations', 'line', 'column', 'category', and 'subcategory'. The purpose of this function is to create a new thread structure These structures provide a framework for storing and organizing information related to thread markers, samples, frame details, and stack information. The call stack is parsed to include function names and the associated DSO, which are requires for creating json schema. Also few libaries has been included which will be used in later commit. Signed-off-by: Anup Sharma --- .../scripts/python/firefox-gecko-converter.py | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tools/perf/scripts/python/firefox-gecko-converter.py b/tools/perf/scripts/python/firefox-gecko-converter.py index 765f1775cee5..0b8a86bdcab1 100644 --- a/tools/perf/scripts/python/firefox-gecko-converter.py +++ b/tools/perf/scripts/python/firefox-gecko-converter.py @@ -21,6 +21,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ from perf_trace_context import * from Core import * +thread_map = {} start_time = None def trace_end(): @@ -28,6 +29,57 @@ def trace_end(): def process_event(param_dict): global start_time + global thread_map + + def _createThread(name, pid, tid): + markers = { + 'schema': { + 'name': 0, + 'startTime': 1, + 'endTime': 2, + 'phase': 3, + 'category': 4, + 'data': 5, + }, + 'data': [], + } + samples = { + 'schema': { + 'stack': 0, + 'time': 1, + 'responsiveness': 2, + }, + 'data': [], + } + frameTable = { + 'schema': { + 'location': 0, + 'relevantForJS': 1, + 'innerWindowID': 2, + 'implementation': 3, + 'optimizations': 4, + 'line': 5, + 'column': 6, + 'category': 7, + 'subcategory': 8, + }, + 'data': [], + } + stackTable = { + 'schema': { + 'prefix': 0, + 'frame': 1, + }, + 'data': [], + } + stringTable = [] + + 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 + # Extract relevant information from the event parameters. The event parameters # are in a dictionary: time_stamp = (param_dict['sample']['time'] // 1000) / 1000 @@ -37,3 +89,21 @@ def process_event(param_dict): # Assume that start time is the time of the first event. start_time = time_stamp if not start_time else start_time + + # Parse the callchain of the current sample into a stack array. + if param_dict['callchain']: + stack = [] + for call in param_dict['callchain']: + if 'sym' not in call: + continue + stack.append(call['sym']['name'] + f' (in {call["dso"]})') + if len(stack) != 0: + stack = stack[::-1] + _addThreadSample(pid, tid, thread_name, time_stamp, stack) + + # 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 = param_dict['symbol'] if 'symbol' in param_dict else '[unknown]' + dso = param_dict['dso'] if 'dso' in param_dict else '[unknown]' + _addThreadSample(pid, tid, thread_name, time_stamp, [func + f' (in {dso})']) -- 2.34.1