From nobody Fri May 3 01:09:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1593012825; cv=none; d=zohomail.com; s=zohoarc; b=Dt/78RHq8ugJyx1E49Lb7XXIa1NWzs4TdLpT/AW+ttTXClclvolwtdBfXAV0olLKKeIc0iA8A/Qzc3NTNA8h4jcC1q9L5oQrQlOEF9MrJBfKJuw6IA/ub9FGo65RdhhfLGvZ+q4uh3k2APY+0VcWIo/x8CG60lbKTAD/RUCkobY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593012825; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=TArnMat3Ju35uYmx6r3OwOxR+VLxrI0NAkcmv5YaMzE=; b=LTBdAA9D6f4ndyO+JKRvAx24m7TiVarmj6nDx7b2xqm8aevUeIDi3tgHcw9QI6YRNvIyFmUSgDZ0z+WQ/6IEzpP3tyey0hubiI0TG9JBmSPDJJSLVJcCg59BAPML2hiEcxQbDb59bhohu6Ado8suSWkN34quQepVyFGRkHh/QwA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159301282558172.43680936333897; Wed, 24 Jun 2020 08:33:45 -0700 (PDT) Received: from localhost ([::1]:49846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo7PD-00060S-Uj for importer@patchew.org; Wed, 24 Jun 2020 11:33:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo7Nd-0004op-Ml for qemu-devel@nongnu.org; Wed, 24 Jun 2020 11:32:05 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:43886) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo7Nb-0000H7-Le for qemu-devel@nongnu.org; Wed, 24 Jun 2020 11:32:05 -0400 Received: by mail-wr1-x444.google.com with SMTP id j4so239403wrp.10 for ; Wed, 24 Jun 2020 08:32:03 -0700 (PDT) Received: from AK-L.domain.name ([197.58.65.131]) by smtp.gmail.com with ESMTPSA id b184sm2011299wmc.20.2020.06.24.08.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 08:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TArnMat3Ju35uYmx6r3OwOxR+VLxrI0NAkcmv5YaMzE=; b=SLUDmarGXnbBCS5mX/u5Pac8ZP0idNHHapGfx9wZ8CcvYYqqPLaV743ZR2G5tHgGnW jCj6IulBfrLgO7ZLu/fadR+LE6bQUI+/kwRI+mZ7T5Bo8Av67/mkhct6NfFsqCtgvoEf 33uU0Gl8bL7h9bvOpyhOdIvyCVN0sFzjVHPnH3YoDL+t88svrBAnXd0BRweIau1H/ydq 39m2adjuWZXLBjHDZXyfbb/ElE1lO379jhDPqNUfjdNHHOen0fqJk5+uYH6GT+k1xPoa 8nDm+5mEzvQuCPRkwBB8D8S5YTA5u3AiRxRc1K3ArzpTOA6eq7NJQ1bC5BMh61vcfMHm DVYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TArnMat3Ju35uYmx6r3OwOxR+VLxrI0NAkcmv5YaMzE=; b=ZDqpToJPrZqMXf6BjSWRBMiFC+8oNtbm0z+k5O31DppGwzqzVHHCYm+xT+PT0BYlJC fcibktGHPmGFFgO3sGfvd15tl2aU2Gp0vMk6qMkc1LVnzcJr9L9zM4A8qf6a9Wx5G/Ew MvOac/VGJMcja4ikzdE6F4X6g7/A07wIJLkCFZmFsYpWEcT+8RQE3XqPK1VQw3VGtZCE AJtUQlwn9AtlfSOIyF+GMFjWUmpq8s512VqtOoeGi5nzvzNSRnG0wmp4rfgN0+6+b2v/ 9PKqkXJ34NKnS8S2NI7ruvGPrgng70UsDMGjLAsLdx4u4eqxHQUb1UE3EvlYKEtibVju McdA== X-Gm-Message-State: AOAM531Kg8ij3G7vUGA2kISz9mSz69fItlMd0oReuxt9kdWwB0V5P2pE OnnReQJcAnQdrN3SEYe0AoJqGAsV X-Google-Smtp-Source: ABdhPJxwk81LN1LOetlGly/C/bZr5jEBCxCzuvXBfdjLJc4UAuSfaT3ESPX/qx28wu4bGx/B0w/Rbw== X-Received: by 2002:a5d:6150:: with SMTP id y16mr33949474wrt.219.1593012722020; Wed, 24 Jun 2020 08:32:02 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, eblake@redhat.com, rth@twiddle.net, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH v3 1/3] scripts/performance: Add topN_perf.py script Date: Wed, 24 Jun 2020 17:31:40 +0200 Message-Id: <20200624153142.13247-2-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624153142.13247-1-ahmedkhaledkaraman@gmail.com> References: <20200624153142.13247-1-ahmedkhaledkaraman@gmail.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_OTHER_BAD_TLD=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ahmed Karaman Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Syntax: topN_perf.py [-h] [-n] -- \ [] \ [] [-h] - Print the script arguments help message. [-n] - Specify the number of top functions to print. - If this flag is not specified, the tool defaults to 25. Example of usage: topN_perf.py -n 20 -- qemu-arm coulomb_double-arm Example Output: No. Percentage Name Caller ---- ---------- ------------------------- ------------------------- 1 16.25% float64_mul qemu-x86_64 2 12.01% float64_sub qemu-x86_64 3 11.99% float64_add qemu-x86_64 4 5.69% helper_mulsd qemu-x86_64 5 4.68% helper_addsd qemu-x86_64 6 4.43% helper_lookup_tb_ptr qemu-x86_64 7 4.28% helper_subsd qemu-x86_64 8 2.71% f64_compare qemu-x86_64 9 2.71% helper_ucomisd qemu-x86_64 10 1.04% helper_pand_xmm qemu-x86_64 11 0.71% float64_div qemu-x86_64 12 0.63% helper_pxor_xmm qemu-x86_64 13 0.50% 0x00007f7b7004ef95 [JIT] tid 491 14 0.50% 0x00007f7b70044e83 [JIT] tid 491 15 0.36% helper_por_xmm qemu-x86_64 16 0.32% helper_cc_compute_all qemu-x86_64 17 0.30% 0x00007f7b700433f0 [JIT] tid 491 18 0.30% float64_compare_quiet qemu-x86_64 19 0.27% soft_f64_addsub qemu-x86_64 20 0.26% round_to_int qemu-x86_64 Signed-off-by: Ahmed Karaman --- scripts/performance/topN_perf.py | 142 +++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 scripts/performance/topN_perf.py diff --git a/scripts/performance/topN_perf.py b/scripts/performance/topN_pe= rf.py new file mode 100755 index 0000000000..d2b939c375 --- /dev/null +++ b/scripts/performance/topN_perf.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 + +# Print the top N most executed functions in QEMU using perf. +# Syntax: +# topN_perf.py [-h] [-n] -- \ +# [] \ +# [] +# +# [-h] - Print the script arguments help message. +# [-n] - Specify the number of top functions to print. +# - If this flag is not specified, the tool defaults to 25. +# +# Example of usage: +# topN_perf.py -n 20 -- qemu-arm coulomb_double-arm +# +# This file is a part of the project "TCG Continuous Benchmarking". +# +# Copyright (C) 2020 Ahmed Karaman +# Copyright (C) 2020 Aleksandar Markovic +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import argparse +import os +import subprocess +import sys + + +# Parse the command line arguments +parser =3D argparse.ArgumentParser( + usage=3D'topN_perf.py [-h] [-n] = -- ' + ' [] ' + ' []') + +parser.add_argument('-n', dest=3D'top', type=3Dint, default=3D25, + help=3D'Specify the number of top functions to print.') + +parser.add_argument('command', type=3Dstr, nargs=3D'+', help=3Dargparse.SU= PPRESS) + +args =3D parser.parse_args() + +# Extract the needed variables from the args +command =3D args.command +top =3D args.top + +# Insure that perf is installed +check_perf =3D subprocess.run(["which", "perf"], stdout=3Dsubprocess.DEVNU= LL) +if check_perf.returncode: + sys.exit("Please install perf before running the script!") + +# Insure user has previllage to run perf +check_perf_executability =3D subprocess.run(["perf", "stat", "ls", "/"], + stdout=3Dsubprocess.DEVNULL, stderr=3Dsubproces= s.DEVNULL) +if check_perf_executability.returncode: + sys.exit( +""" +Error: +You may not have permission to collect stats. + +Consider tweaking /proc/sys/kernel/perf_event_paranoid, +which controls use of the performance events system by +unprivileged users (without CAP_SYS_ADMIN). + + -1: Allow use of (almost) all events by all users + Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK + 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN + Disallow raw tracepoint access by users without CAP_SYS_ADMIN + 1: Disallow CPU event access by users without CAP_SYS_ADMIN + 2: Disallow kernel profiling by users without CAP_SYS_ADMIN + +To make this setting permanent, edit /etc/sysctl.conf too, e.g.: + kernel.perf_event_paranoid =3D -1 +""" +) + +# Run perf record +perf_record =3D subprocess.run((["perf", "record"] + command), + stdout=3Dsubprocess.DEVNULL, stderr=3Dsubproc= ess.PIPE) +if perf_record.returncode: + os.unlink('perf.data') + sys.exit(perf_record.stderr.decode("utf-8")) + +# Save perf report output to perf_report.out +with open("perf_report.out", "w") as output: + perf_report =3D subprocess.run( + ["perf", "report", "--stdio"], stdout=3Doutput, stderr=3Dsubproces= s.PIPE) + if perf_report.returncode: + os.unlink('perf.data') + output.close() + os.unlink('perf_report.out') + sys.exit(perf_report.stderr.decode("utf-8")) + +# Read the reported data to functions[] +functions =3D [] +with open("perf_report.out", "r") as data: + # Only read lines that are not comments (comments start with #) + # Only read lines that are not empty + functions =3D [line for line in data.readlines() if line and line[0] + !=3D '#' and line[0] !=3D "\n"] + +# Limit the number of top functions to "top" +number_of_top_functions =3D top if len(functions) > top else len(functions) + +# Store the data of the top functions in top_functions[] +top_functions =3D functions[:number_of_top_functions] + +# Print table header +print('{:>4} {:>10} {:<30} {}\n{} {} {} {}'.format('No.', + 'Percentage', + 'Name', + 'Caller', + '-' * 4, + '-' * 10, + '-' * 30, + '-' * 25)) + + +# Print top N functions +for (index, function) in enumerate(top_functions, start=3D1): + function_data =3D function.split() + function_percentage =3D function_data[0] + function_name =3D function_data[-1] + function_caller =3D ' '.join(function_data[2:-2]) + print('{:>4} {:>10} {:<30} {}'.format(index, + function_percentage, + function_name, + function_caller)) + +# Remove intermediate files +os.unlink('perf.data') +os.unlink('perf_report.out') --=20 2.17.1 From nobody Fri May 3 01:09:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1593012947; cv=none; d=zohomail.com; s=zohoarc; b=UwZS5mr/ZLLLMhofDibUJ9Y6XnaA3/61eXe4P6D3Bxo+VC/Vw4/SkAiuvSf0zzryc0u/ZiZRbOZRGy93wPJo3XXpJAb0zzDouYBHYjGljILWmBZtKYYDj/trdRpiKu0VLQ5Kz0w6AhsPuB1GYDmDgqGuE+w2jm4oe5aua/PrpnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593012947; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mPG18irFu/hv7Gy+qAN1EmbPjrPP5QFZJpMHb7Uj9tU=; b=Tr8IWWF8ZvOVlY//qN6UB4ppa0DfjQFf3UzKEletvyxUh6ZGVP3vNW8DQVz1BDGtmzYTWLPK+CDi90WcsMuPrlkaCYhnUzvdihbKl5SeL6WQKTBtr60Cr42HK6UV+58uO6gPxQmWYN8GEakRrNotCkiSVpO8I/tv+yrPHzZwrs8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593012947476957.2896836779146; Wed, 24 Jun 2020 08:35:47 -0700 (PDT) Received: from localhost ([::1]:55908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo7RB-0001Hm-VH for importer@patchew.org; Wed, 24 Jun 2020 11:35:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo7Ng-0004tD-AR for qemu-devel@nongnu.org; Wed, 24 Jun 2020 11:32:08 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo7Ne-0000Iq-74 for qemu-devel@nongnu.org; Wed, 24 Jun 2020 11:32:07 -0400 Received: by mail-wr1-x441.google.com with SMTP id k6so2741915wrn.3 for ; Wed, 24 Jun 2020 08:32:05 -0700 (PDT) Received: from AK-L.domain.name ([197.58.65.131]) by smtp.gmail.com with ESMTPSA id b184sm2011299wmc.20.2020.06.24.08.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 08:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mPG18irFu/hv7Gy+qAN1EmbPjrPP5QFZJpMHb7Uj9tU=; b=Ri7z1hdRHdUBfV6m2aFBDojmj9VUMA2BlUPxMvrNXdS4asWRN4RJQ3xxUreIblvKTw 5nLeDD1w67ZYYGCFNBYtpSfOxj1zY2YBf9LfHE9r0oVI/Jtz5OSxI8C4x9A08jmj/Bur F+jZbR4Vu3vSEfl8gF3CSY/j7cBXQa/vH6HN0ph76QhFJJN09tbu9yWEZKzV6c7QaIcj zynILNmFAnaNhS0V6xGKYwlQS2eCpcdDyszUZsVK1N35K/yoxWTa8KCzG1BmFKBM9TXk 50UKchR8ZScrPjtX9zZFT1JZX/rhketkwENN/CRg3NRYbwKVyEWYCXEu5fAFUzc3VyE5 SPwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mPG18irFu/hv7Gy+qAN1EmbPjrPP5QFZJpMHb7Uj9tU=; b=EEtLf4S2FMRgKqikuypBIZvjEHtgQTGVjyV2lRC5aANFudZOR/irodJF5wRcUhSZJd AuWTfkZP04YgtYs9krHrKDPn+KpWswjvsoVdIUHOiJo1MiigOCcON8HYbiqYTBTTwKvq XiN0L3Z28dLQCThtZVGNK6mlZ3xjVGJKw5zgwvzx8fUjn2ue/iIAJz6HXA5ZE7wKgBSs ScViPhPFzIVMDZNxWTwPhJU6EH2zv0pv54pVFqD8wi2vdMNrKXBXO+rrQleqixhLcUHL oDHJ2Wj65URll1WfoYSPbYq8nB49j358Sk6BpkadZnMu/6MqMpumL4L6wg8SMhXfRSZB chog== X-Gm-Message-State: AOAM531mu5VBVVESqnzvaLtARoUlSmamFz51Wcaxf7MswSAitI08tc+k o7apP9jGyo6KyzPHKB2xmaxMv0af X-Google-Smtp-Source: ABdhPJyiXbR6pyebvUpNhgkeu5rdgadJRsLAcs5vnaRgikHBarNjIMQO/KwxVNh7n7WGeP5dmTg6zg== X-Received: by 2002:adf:efc6:: with SMTP id i6mr29662683wrp.303.1593012724494; Wed, 24 Jun 2020 08:32:04 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, eblake@redhat.com, rth@twiddle.net, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH v3 2/3] scripts/performance: Add topN_callgrind.py script Date: Wed, 24 Jun 2020 17:31:41 +0200 Message-Id: <20200624153142.13247-3-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624153142.13247-1-ahmedkhaledkaraman@gmail.com> References: <20200624153142.13247-1-ahmedkhaledkaraman@gmail.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_OTHER_BAD_TLD=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ahmed Karaman Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Python script that prints the top N most executed functions in QEMU using callgrind. Syntax: topN_callgrind.py [-h] [-n] -- \ [] \ [] [-h] - Print the script arguments help message. [-n] - Specify the number of top functions to print. - If this flag is not specified, the tool defaults to 25. Example of usage: topN_callgrind.py -n 20 -- qemu-arm coulomb_double-arm Example Output: No. Percentage Name Source File ---- --------- ------------------ ------------------------------ 1 24.577% 0x00000000082db000 ??? 2 20.467% float64_mul /fpu/softfloat.c 3 14.720% float64_sub /fpu/softfloat.c 4 13.864% float64_add /fpu/softfloat.c 5 4.876% helper_mulsd /target/i386/ops_sse.h 6 3.767% helper_subsd /target/i386/ops_sse.h 7 3.549% helper_addsd /target/i386/ops_sse.h 8 2.185% helper_ucomisd /target/i386/ops_sse.h 9 1.667% helper_lookup_tb_ptr /include/exec/tb-lookup.h 10 1.662% f64_compare /fpu/softfloat.c 11 1.509% helper_lookup_tb_ptr /accel/tcg/tcg-runtime.c 12 0.635% helper_lookup_tb_ptr /include/exec/exec-all.h 13 0.616% float64_div /fpu/softfloat.c 14 0.502% helper_pand_xmm /target/i386/ops_sse.h 15 0.502% float64_mul /include/fpu/softfloat.h 16 0.476% helper_lookup_tb_ptr /target/i386/cpu.h 17 0.437% float64_compare_quiet /fpu/softfloat.c 18 0.414% helper_pxor_xmm /target/i386/ops_sse.h 19 0.353% round_to_int /fpu/softfloat.c 20 0.347% helper_cc_compute_all /target/i386/cc_helper.c Signed-off-by: Ahmed Karaman --- scripts/performance/topN_callgrind.py | 139 ++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100755 scripts/performance/topN_callgrind.py diff --git a/scripts/performance/topN_callgrind.py b/scripts/performance/to= pN_callgrind.py new file mode 100755 index 0000000000..6136f72a74 --- /dev/null +++ b/scripts/performance/topN_callgrind.py @@ -0,0 +1,139 @@ +#!/usr/bin/env python3 + +# Print the top N most executed functions in QEMU using callgrind. +# Syntax: +# topN_callgrind.py [-h] [-n] -- \ +# [] \ +# [] +# +# [-h] - Print the script arguments help message. +# [-n] - Specify the number of top functions to print. +# - If this flag is not specified, the tool defaults to 25. +# +# Example of usage: +# topN_callgrind.py -n 20 -- qemu-arm coulomb_double-arm +# +# This file is a part of the project "TCG Continuous Benchmarking". +# +# Copyright (C) 2020 Ahmed Karaman +# Copyright (C) 2020 Aleksandar Markovic +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import argparse +import os +import subprocess +import sys + + +# Parse the command line arguments +parser =3D argparse.ArgumentParser( + usage=3D'topN_callgrind.py [-h] [-n] -- ' + ' [] ' + ' []') + +parser.add_argument('-n', dest=3D'top', type=3Dint, default=3D25, + help=3D'Specify the number of top functions to print.') + +parser.add_argument('command', type=3Dstr, nargs=3D'+', help=3Dargparse.SU= PPRESS) + +args =3D parser.parse_args() + +# Extract the needed variables from the args +command =3D args.command +top =3D args.top + +# Insure that valgrind is installed +check_valgrind =3D subprocess.run( + ["which", "valgrind"], stdout=3Dsubprocess.DEVNULL) +if check_valgrind.returncode: + sys.exit("Please install valgrind before running the script!") + +# Run callgrind +callgrind =3D subprocess.run((["valgrind", "--tool=3Dcallgrind", + "--callgrind-out-file=3Dcallgrind.data"] + co= mmand), + stdout=3Dsubprocess.DEVNULL, stderr=3Dsubproces= s.PIPE) +if callgrind.returncode: + sys.exit(callgrind.stderr.decode("utf-8")) + +# Save callgrind_annotate output to callgrind_annotate.out +with open("callgrind_annotate.out", "w") as output: + callgrind_annotate =3D subprocess.run( + ["callgrind_annotate", "callgrind.data"], + stdout=3Doutput, + stderr=3Dsubprocess.PIPE) + if callgrind_annotate.returncode: + os.unlink('callgrind.data') + output.close() + os.unlink('callgrind_annotate.out') + sys.exit(callgrind_annotate.stderr.decode("utf-8")) + + +# Read the callgrind_annotate output to callgrind_data[] +callgrind_data =3D [] +with open('callgrind_annotate.out', 'r') as data: + callgrind_data =3D data.readlines() + +# Line number with the total number of instructions +total_instructions_line_number =3D 20 + +# Get the total number of instructions +total_instructions_line_data =3D callgrind_data[total_instructions_line_nu= mber] +total_number_of_instructions =3D total_instructions_line_data.split(' ')[0] +total_number_of_instructions =3D int( + total_number_of_instructions.replace(',', '')) + +# Line number with the top function +first_func_line =3D 25 + +# Number of functions recorded by callgrind, last two lines are always emp= ty +number_of_functions =3D len(callgrind_data) - first_func_line - 2 + +# Limit the number of top functions to "top" +number_of_top_functions =3D (top if number_of_functions > + top else number_of_functions) + +# Store the data of the top functions in top_functions[] +top_functions =3D callgrind_data[first_func_line: + first_func_line + number_of_top_functions] + +# Print table header +print('{:>4} {:>10} {:<30} {}\n{} {} {} {}'.format('No.', + 'Percentage', + 'Name', + 'Source File', + '-' * 4, + '-' * 10, + '-' * 30, + '-' * 30, + )) + +# Print top N functions +for (index, function) in enumerate(top_functions, start=3D1): + function_data =3D function.split() + # Calculate function percentage + function_instructions =3D float(function_data[0].replace(',', '')) + function_percentage =3D (function_instructions / + total_number_of_instructions)*100 + # Get function name and source files path + function_source_path, function_name =3D function_data[1].split(':') + # Print extracted data + print('{:>4} {:>9.3f}% {:<30} {}'.format(index, + round(function_percentage,= 3), + function_name, + function_source_path)) + +# Remove intermediate files +os.unlink('callgrind.data') +os.unlink('callgrind_annotate.out') --=20 2.17.1 From nobody Fri May 3 01:09:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1593012946; cv=none; d=zohomail.com; s=zohoarc; b=k6paSAkE3m+HUEQI/PQcC0nOPAaw063o8euY4k9a6ZrFpM2JZc4L2zjyJ3BgjG/muLv7dqXgOOt9QV8/Dh7LKMx/Dn7EiVp4gKve/gb8f02dWSYW54JT9mekgq2Lfn5RayFE7lDsqrA1ZRBHuMi+12IaFQXVw/qzGNWwrsrpi+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593012946; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fbv3/jSdw1PhrwDJKSxYWcMIUCkmRMAgXUZr/+9Jw3g=; b=VEvPImViRCUtl/ABslAyMBXQkaajP+OGGOwiK5YCAcezZjZL45sSH9M0R/OKrKUkBASYHFQYoLaDHCUC2cHWhQmtzabdg97UPQvWfXsqCQqzblvPzrXbLcuVbWLGsrM4kET7DAKohI8KYTNcTaTL+nCx0jPjiKBF/w4QS2JKFyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593012946909836.9884552789566; Wed, 24 Jun 2020 08:35:46 -0700 (PDT) Received: from localhost ([::1]:55824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jo7RB-0001F7-LD for importer@patchew.org; Wed, 24 Jun 2020 11:35:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jo7Ni-0004xc-Uf for qemu-devel@nongnu.org; Wed, 24 Jun 2020 11:32:10 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jo7Ng-0000JD-I7 for qemu-devel@nongnu.org; Wed, 24 Jun 2020 11:32:10 -0400 Received: by mail-wr1-x442.google.com with SMTP id h5so2721073wrc.7 for ; Wed, 24 Jun 2020 08:32:08 -0700 (PDT) Received: from AK-L.domain.name ([197.58.65.131]) by smtp.gmail.com with ESMTPSA id b184sm2011299wmc.20.2020.06.24.08.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 08:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fbv3/jSdw1PhrwDJKSxYWcMIUCkmRMAgXUZr/+9Jw3g=; b=LNnWDVCDIAt/hP0hdi1ZiGOKjeS6R1hZkrcfQ2WqxF3rqatQkLTpUC/V4LYV0Kw7MN IC6XpWEjU4ZT6Oiqg+oqB7+5mJ3ylFjr2a2glOc5Eol1gYeiX7f7fgqSk8Y8kvaI3FIm 4xvdzgcuuv1meoJx998CZ+uxn3T7d7Q0W6fe2eUQ1Qs7R4/qOTw/ZEiw66H6aldjBn8Y 7XuxzLHV1fFMUYYGq6qAcUMeJUbMIJW1R+Bwbi76OAP+HnJ2b1ksqbPzgonWybACswPD gb1mPm88DyS3F5QSHY7slvelsXjtR2Z77F9SA3BahwbFiFCCURP1urFwMBqT0pr4qjG9 QbjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fbv3/jSdw1PhrwDJKSxYWcMIUCkmRMAgXUZr/+9Jw3g=; b=nPwnagN/NdIH2nvQdso1S9bL/6yLZWvv6gDSrzOY4hEcLJqtjfUGxhvojtoGrmtSsI /8C5qOLzuSd1VWj6r6lmbKRnWx9GFWJlUb+1MZBGNf1YJQODWlr/B9OhjgJh+ok9Wm32 hecISs8xPN6aSfsLwrEKI8E0CZB/0wCfn2joB4Nz26Kn2wHgg/TfmuvltycNXfWv0LNy /aQ+vpdmEK7ndLv1HF9HyA9L5O108c2r8BHu8uGn+f1BJFrFOaXtCnTCzsQUv01BisEx KDskPbgpybTEGsC+9+kveV1kzGhyrDiXhoT6aaR4EoWLGthIgoY9GCkoGli8sffaAZks kzsA== X-Gm-Message-State: AOAM530feJOQ8wJMwSuErVKqOxIavoISEWMt1iB21ytwBZTQvGP/AKcL Bod5dhHt143KAGNLdVfYnowejVcg X-Google-Smtp-Source: ABdhPJwEydeNNpyIuCuy/mERv9CkXStfqEDfzVfBw0CYOCg5QGXU2/HZqn16QhhHtkI96L6L+z3ZIg== X-Received: by 2002:a05:6000:128c:: with SMTP id f12mr20132274wrx.67.1593012726942; Wed, 24 Jun 2020 08:32:06 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, eblake@redhat.com, rth@twiddle.net, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH v3 3/3] MAINTAINERS: Add 'Performance Tools and Tests' subsection Date: Wed, 24 Jun 2020 17:31:42 +0200 Message-Id: <20200624153142.13247-4-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624153142.13247-1-ahmedkhaledkaraman@gmail.com> References: <20200624153142.13247-1-ahmedkhaledkaraman@gmail.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ahmed Karaman Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit creates a new 'Miscellaneous' section which hosts a new 'Performance Tools and Tests' subsection. The subsection will contain the the performance scripts and benchmarks written as a part of the 'TCG Continuous Benchmarking' project. Signed-off-by: Ahmed Karaman --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 955cc8dd5c..ee4bfc5fb1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2974,3 +2974,10 @@ M: Peter Maydell S: Maintained F: docs/conf.py F: docs/*/conf.py + +Miscellaneous +------------- +Performance Tools and Tests +M: Ahmed Karaman +S: Maintained +F: scripts/performance/ --=20 2.17.1