From nobody Sun May 5 00:45:31 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=1593190914; cv=none; d=zohomail.com; s=zohoarc; b=NcauN9zIy5yrt7/lroeF8TLhgtVp2v68YdH83DbGcp6yL9XHcHddTM0CSrbM9+KWc7X2aSbMi4LA1u9IzQfE0+MqP+gv7fH4Z/Qk/5EKDQJgt1Mq7MW4mh+tvAv3x5IOnjSITXGkLSzFZz4jFuF0H1ZuYQ3VLiwEsBPpUzxvhv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593190914; 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=FOm8YrybOtDDejE60XwrFoPvrKYk5DnDAfmjdi7H7yU=; b=AiH/3giDLSCuuWpCFJK8TZq03ZniUVmXciVOom++RpmHHrysNm9oKbY0p73R/PLJvi6oPJs9bpnOKTO6zsv0ApO1UlDJ/YES0gS0Zg75kQQHOYbitgftLnIhSZc6pYDV5YEJEJlMw50NGj7ypGfh6cCOO6fxOpRNnMMS1cVlRSE= 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 1593190913462308.003951306451; Fri, 26 Jun 2020 10:01:53 -0700 (PDT) Received: from localhost ([::1]:39388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorjY-0003Nc-8G for importer@patchew.org; Fri, 26 Jun 2020 13:01:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorUe-0003Xz-RR for qemu-devel@nongnu.org; Fri, 26 Jun 2020 12:46:24 -0400 Received: from mail-ej1-x641.google.com ([2a00:1450:4864:20::641]:38566) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorUc-0007vc-1f for qemu-devel@nongnu.org; Fri, 26 Jun 2020 12:46:23 -0400 Received: by mail-ej1-x641.google.com with SMTP id w16so10015043ejj.5 for ; Fri, 26 Jun 2020 09:46:21 -0700 (PDT) Received: from AK-L.domain.name ([197.58.224.183]) by smtp.gmail.com with ESMTPSA id rv16sm10894889ejb.60.2020.06.26.09.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:46:19 -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=FOm8YrybOtDDejE60XwrFoPvrKYk5DnDAfmjdi7H7yU=; b=oKsNACpTyj1RUkdHDpDIjv0gvsVfxbsddHKKp7KmYiFyS8AxGdGRFSU7JYkxj4V74x mVGWFBbnS2mG7gOdumdJ1X83qwb4YZJZHzaV1UYXzsI7yXXZm1RuPX1ZtQkQiDxF942s 5N1/JYdfAMa8s7wOP5hU7wXCMODjJ0snS1pzWii7eihl1HeLBp6F4IjHQnOipm4qw5Za iYZK0QYZFAI/V1fjLy6Kfke8AUqdHnTi4mJhT3yrVzi7oe6TfCr/XckUXJTJm3in3qr6 YHX625f5hLhFfi5l5RqQgeehnD+YGWmel8rv3eUbGOAtWlQrhFg3hpULOWE0QW/fF30H uqwg== 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=FOm8YrybOtDDejE60XwrFoPvrKYk5DnDAfmjdi7H7yU=; b=o8PHkLxe3y0zDHwF17pmBbb03QcTM/74ZvFkRhP+FaqK8/yxk1iZ7rjhR3lKBq5KvQ XjJVd7+qiULq3xToP9ispjnLwwSaEEzhut8YQH97XAkPAvzDte5h0PYEEk5jq4yUA95T HDtZz+PzMi/3iLfW2KleMwPxOlPocXWcs6fZOewAE+w780xhzoiWYGrrtEUK4K3/jWDm 2UO85aiqegPxIzSw+ZRpIdDDDjivLOG64aG9aWBqFYEal11u+bplBVkta/g801kPZ0MP Dlug0on5dLrrBDODWITfsbyLLQ8VIuWIEsz/oA+srAwu3Xm+VxrggI6geH35wvpQq1GZ SRCA== X-Gm-Message-State: AOAM531D4w2tvx/lyy/49tAQxSQLZaT42Eji8i9dP3Kmn1olCBvSnoL3 HhVB0cE8WluwqIA3+9ukbL0vsaWx X-Google-Smtp-Source: ABdhPJwpNMogwrKPvBm1yDzQy0llG1gAFdablzCNVgkV5T6wglhRxsqZosaoFozrC9E3ToVsJwDv7w== X-Received: by 2002:a17:906:2287:: with SMTP id p7mr3415128eja.537.1593189980257; Fri, 26 Jun 2020 09:46:20 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, rth@twiddle.net, eblake@redhat.com, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH v4 1/3] scripts/performance: Add topN_perf.py script Date: Fri, 26 Jun 2020 18:45:44 +0200 Message-Id: <20200626164546.22102-2-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626164546.22102-1-ahmedkhaledkaraman@gmail.com> References: <20200626164546.22102-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::641; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-ej1-x641.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 Invoked by Reviewed-by: Aleksandar Markovic ---- ---------- ------------------------- ------------------------- 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 | 149 +++++++++++++++++++++++++++++++ 1 file changed, 149 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..07be195fc8 --- /dev/null +++ b/scripts/performance/topN_perf.py @@ -0,0 +1,149 @@ +#!/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_presence =3D subprocess.run(["which", "perf"], + stdout=3Dsubprocess.DEVNULL) +if check_perf_presence.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=3Dsubprocess.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 + +* Alternatively, you can run this script under sudo privileges. +""" +) + +# Run perf record +perf_record =3D subprocess.run((["perf", "record", "--output=3D/tmp/perf.d= ata"] + + command), + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.PIPE) +if perf_record.returncode: + os.unlink('/tmp/perf.data') + sys.exit(perf_record.stderr.decode("utf-8")) + +# Save perf report output to /tmp/perf_report.out +with open("/tmp/perf_report.out", "w") as output: + perf_report =3D subprocess.run( + ["perf", "report", "--input=3D/tmp/perf.data", "--stdio"], + stdout=3Doutput, + stderr=3Dsubprocess.PIPE) + if perf_report.returncode: + os.unlink('/tmp/perf.data') + output.close() + os.unlink('/tmp/perf_report.out') + sys.exit(perf_report.stderr.decode("utf-8")) + +# Read the reported data to functions[] +functions =3D [] +with open("/tmp/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', + 'Invoked by', + '-' * 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_invoker =3D ' '.join(function_data[2:-2]) + print('{:>4} {:>10} {:<30} {}'.format(index, + function_percentage, + function_name, + function_invoker)) + +# Remove intermediate files +os.unlink('/tmp/perf.data') +os.unlink('/tmp/perf_report.out') --=20 2.17.1 From nobody Sun May 5 00:45:31 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=1593190816; cv=none; d=zohomail.com; s=zohoarc; b=n6ES3i3dUXqljedf5C3eIvOR1DKVTqJzUs0A5TQzThwMmUR5yWPjPYMVRifndchS4ZgKAQZqNI/1xQBN1zYOZNXZXrORhwqF2ZfBgGRggCpgrhngTt8EeW/tC8n7XTzUd66F91cQiXtkR0ftoCX6BQY1C9xgLOPHe5UxvglGMrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593190816; 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=PbfzS0czgvrzfNYUDwbovVaLiZXJYJoWggoXPaTM6Ew=; b=iaByeuBYVXYp1NRpH04Gd/xaY8ze36YWTZwEbyYEsNUc7Bd4zxKfY743VtoY26oP4n1WI7mLzoodT98OM3zDYJ3+gsI8Rip4V7YLa9JYRDHebB2VF66MF07M9V6H2qIJzhXwZir5vjzwG9foR0LjF5OUnT4Daa/nhHdVkq5/59A= 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 1593190816429391.06184716658197; Fri, 26 Jun 2020 10:00:16 -0700 (PDT) Received: from localhost ([::1]:35168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorht-0001VY-Lg for importer@patchew.org; Fri, 26 Jun 2020 13:00:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorUh-0003Zo-Gc for qemu-devel@nongnu.org; Fri, 26 Jun 2020 12:46:27 -0400 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]:37650) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorUf-0007x8-NN for qemu-devel@nongnu.org; Fri, 26 Jun 2020 12:46:27 -0400 Received: by mail-ej1-x642.google.com with SMTP id mb16so10019050ejb.4 for ; Fri, 26 Jun 2020 09:46:25 -0700 (PDT) Received: from AK-L.domain.name ([197.58.224.183]) by smtp.gmail.com with ESMTPSA id rv16sm10894889ejb.60.2020.06.26.09.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:46:23 -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=PbfzS0czgvrzfNYUDwbovVaLiZXJYJoWggoXPaTM6Ew=; b=pCn193/CdT40jI8dX5Mn65yWUxQKrXiKShFayRxn4TcRXETbAMVWN0bIJnMSa0D3xY GFIeQSlhObthaWqDYNGmfAcPjkDUi/L2WWXKSqz5DZbpvvhKq9/E1EynR2f2dSR59quH lg10jszU2Oj+5qr1j+7Pa52vgHUKN7OhltCM0XNUOwGarJGqvKVkFbHCW23096oP9GPV K4inVN7twM8IwMHDmj8cl38g1MfHCoZ0Pw2Y96wDy3rxg6N6GdXHRL3nGN5YQwKKFP7j DjeZWA2hwcNUIHKtPFQ2BSh4N0JNDuTD82ODqejQwLZLOMdflvcFQyHYT1sMCa9UMU1s g+Cw== 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=PbfzS0czgvrzfNYUDwbovVaLiZXJYJoWggoXPaTM6Ew=; b=rr1C4tNImqr2CkgoojjD4FCyETZjtKKG/euLfPgPXjWvkrcWbIaM16Hmxk9YaKL1RJ 6CMkmPgg8Ui27S2FesP0kiFADyMZCHKBLhgrBbScWYJXaR33EPD1rizAHOLwH/qJ7eQC WhoGDBlRYtXh2wS2odeAj5bk9POj+EFDasLCWHl2y/P64c2H8IgSOXout3hYRLxiLG5f XWTkFBcnqIP9/5Ld2plrdvvsDBeRnOLwhHX4rv99mrmLqw58JmvefEk54USyMJxkcUaS 2chaKrSoPAjBvt5Kise3xjjhMLuA5jabI1lLcyqKOok/JulBKpoS9Yqsym76u5nfsiIb MbFw== X-Gm-Message-State: AOAM531BE2kJABLFCdRV8x9wyKRZaSsQH5Kifp06dH6BogXsqgxsoUoK 3gjCmG0WlWf5XL8wjAJQLW5PXiTR X-Google-Smtp-Source: ABdhPJxWHVT5CnZD+/wo7Ka1b0YNWiPtDnSAIW/6lnAe4bf21umD40B4w+AK5PuubzMDKXGvwLesqQ== X-Received: by 2002:a17:906:c451:: with SMTP id ck17mr3497900ejb.80.1593189983947; Fri, 26 Jun 2020 09:46:23 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, rth@twiddle.net, eblake@redhat.com, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH v4 2/3] scripts/performance: Add topN_callgrind.py script Date: Fri, 26 Jun 2020 18:45:45 +0200 Message-Id: <20200626164546.22102-3-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626164546.22102-1-ahmedkhaledkaraman@gmail.com> References: <20200626164546.22102-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::642; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-ej1-x642.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 Function Name Source File Reviewed-by: Aleksandar Markovic ---- --------- ------------------ ------------------------------ 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 | 140 ++++++++++++++++++++++++++ 1 file changed, 140 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..67c59197af --- /dev/null +++ b/scripts/performance/topN_callgrind.py @@ -0,0 +1,140 @@ +#!/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_presence =3D subprocess.run(["which", "valgrind"], + stdout=3Dsubprocess.DEVNULL) +if check_valgrind_presence.returncode: + sys.exit("Please install valgrind before running the script!") + +# Run callgrind +callgrind =3D subprocess.run(( + ["valgrind", "--tool=3Dcallgrind", "--callgrind-out-file=3D/tmp/callgr= ind.data"] + + command), + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.PIPE) +if callgrind.returncode: + sys.exit(callgrind.stderr.decode("utf-8")) + +# Save callgrind_annotate output to /tmp/callgrind_annotate.out +with open("/tmp/callgrind_annotate.out", "w") as output: + callgrind_annotate =3D subprocess.run(["callgrind_annotate", + "/tmp/callgrind.data"], + stdout=3Doutput, + stderr=3Dsubprocess.PIPE) + if callgrind_annotate.returncode: + os.unlink('/tmp/callgrind.data') + output.close() + os.unlink('/tmp/callgrind_annotate.out') + sys.exit(callgrind_annotate.stderr.decode("utf-8")) + +# Read the callgrind_annotate output to callgrind_data[] +callgrind_data =3D [] +with open('/tmp/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', + 'Function 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_file, 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_file)) + +# Remove intermediate files +os.unlink('/tmp/callgrind.data') +os.unlink('/tmp/callgrind_annotate.out') --=20 2.17.1 From nobody Sun May 5 00:45:31 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=1593190984; cv=none; d=zohomail.com; s=zohoarc; b=hBGorp7wMM7m6aCl/QHiLXuh4EI0zWrAXpwXGW658svn4l0mENnO68vxdvVy+LBpS/R/MjrXdvJXWgLwj/AKzmdMq0RIGq8/q4PnqcNxFbPXOAhEHC6NB69Eh6A7Tp8NrKPigYdsRG06d/PjSP41N49e0s86pUGwxAwNY0D+TSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593190984; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/aUEanK9DpNRcSmbtWEsbfQi2wy0eJYb7dBT3TVKbyg=; b=j9b+aJJgBHajZciGtQGkfo4IRfWuLo0+GeIscE8rqI6HWAqcO6d6r6uLVnu1RJQn3zmD/pjSmsM7HaZ3Nh2RL5MEdi4A+TnzM1TrHvKTlRpF3+2bgV/OEz7R4llbP9nwZV5UPa3Tj+NB+/vSCSJ8eo0B02lqdmuAujTCKUPj5ZY= 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 1593190984701675.2591790519506; Fri, 26 Jun 2020 10:03:04 -0700 (PDT) Received: from localhost ([::1]:44084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jorkl-0005M0-Gv for importer@patchew.org; Fri, 26 Jun 2020 13:03:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorUn-0003fm-MT for qemu-devel@nongnu.org; Fri, 26 Jun 2020 12:46:34 -0400 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]:39557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorUj-0007yM-QK for qemu-devel@nongnu.org; Fri, 26 Jun 2020 12:46:33 -0400 Received: by mail-ej1-x643.google.com with SMTP id w6so10014708ejq.6 for ; Fri, 26 Jun 2020 09:46:29 -0700 (PDT) Received: from AK-L.domain.name ([197.58.224.183]) by smtp.gmail.com with ESMTPSA id rv16sm10894889ejb.60.2020.06.26.09.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 09:46:27 -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 :mime-version:content-transfer-encoding; bh=/aUEanK9DpNRcSmbtWEsbfQi2wy0eJYb7dBT3TVKbyg=; b=kD3cX9rjTSfQl5qK+WNBuQC87FVHK8YdlL1Re68Ym/ISz9A4qfyFkcyBg90I9Iu5G3 VAX1EtsLOxiUU4xEIma0sYxNlkOyQYy1JoaJSJfc0GpWPRp4nObC1yP/UzowuCoE/ZXx o/uELLZIm0Y6F19NQmIYM17JGqVAb126tdsDxKFscXHlwDI6z+vEGyxOW7JAF248Ymvc tfLWyw1K5LVp5AneqNbOSXYhFeAA0xA2X0+XjWXdyBe/QuQXN2cpkIQXtaKOlmZ7zcdq 8vJzRWYgCsNDtv9g7Gf8CWWYDfVVLY3TDb+3odOGk60/UAp8s0MxqQ+3liETSs7iCkie tb9A== 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:mime-version:content-transfer-encoding; bh=/aUEanK9DpNRcSmbtWEsbfQi2wy0eJYb7dBT3TVKbyg=; b=TtuxTQ8E1uiSo1BGOx6KWykIk3WZhUzSAxBFms7dItuimlxH6/usNePWwfmKXLebfM lEn029cueDJoHRejNYH+4JcVOHsZTBykK1wx3B6GdKnC/nMHUCDlq2WCcTCOi53+mPyI jjvEKM7QyuZaCE7lsp9msR1kG8jwRsLdNunMl+lfU2WPVVnp8vpSIZo7VTB6fGnOLCwf cLkM896sjBl0wkkpfOKeoCG+yZDxBKILKhzkhBDE+84envQoC6Kjr5SjHhpbROAegOvf ttyArhBTEm9s84GWc7Dz6OAz5HCN3lzqqORxatr9rVXIhLg0rUnhnGBaMVH1WqLp7Bjg P3UA== X-Gm-Message-State: AOAM5300S3C4dvs/R/IGlA0qq1M0Eio62yWQ10yflInLtoTZLV1QtYMc 7TDdPKp2fsRsatEi5ylLExBOEGJo X-Google-Smtp-Source: ABdhPJxZXDyWJ5NF2wDS2iqfoyRte4Yjwf2deye+gfI/Dn14KuK1CVv/qYm1gluUWu6BozwqE94ALA== X-Received: by 2002:a17:906:fb99:: with SMTP id lr25mr3311871ejb.49.1593189988260; Fri, 26 Jun 2020 09:46:28 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, rth@twiddle.net, eblake@redhat.com, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH v4 3/3] MAINTAINERS: Add 'Performance Tools and Tests'subsection Date: Fri, 26 Jun 2020 18:45:46 +0200 Message-Id: <20200626164546.22102-4-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626164546.22102-1-ahmedkhaledkaraman@gmail.com> References: <20200626164546.22102-1-ahmedkhaledkaraman@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::643; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-ej1-x643.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) 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 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Aleksandar Markovic --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 1b40446c73..c510c942ac 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3019,3 +3019,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