From nobody Mon Feb 9 04:31:03 2026 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=1592349267; cv=none; d=zohomail.com; s=zohoarc; b=RLJ3szDGmHjXfg1PgTqp3HYyRWFmCiJrLypxl4JW10AbG9AEvgeflACkXMbdHK108tocVmMl5JDO1v4hL8MD2PzXZft2y9+08KuKr9zCPOtn05QQVaf9iKl0vh1r56suZv21inqrb4UyO0AYhNA/JPT2xbGhm6ky3Pg/SEsCoaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592349267; 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=ClO0YbMLxFK4IoNk8Xcwu72VrPPnrLf9XqnoMALXakg=; b=WMoCnBkUWrUm4rTycI0KAfKRtiDhUwQfEk4rsaN439s57EqoQef8QzH6z7gIl4NVnaCIvfRHUKPBivANzvo5ihSWsBUWtpM93EpCDvsc8GCveZHQhTgUsBGeZf6DhNcgcXvE/1B2TRdExzynRQBMsCXZ4d+OpcYBl0H2Z/yt0a0= 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 1592349267380104.71469565650068; Tue, 16 Jun 2020 16:14:27 -0700 (PDT) Received: from localhost ([::1]:46330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlKmg-0004ga-2U for importer@patchew.org; Tue, 16 Jun 2020 19:14:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlKlV-0002uA-Fo for qemu-devel@nongnu.org; Tue, 16 Jun 2020 19:13:13 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:41277) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jlKlT-0006vB-In for qemu-devel@nongnu.org; Tue, 16 Jun 2020 19:13:13 -0400 Received: by mail-wr1-x42f.google.com with SMTP id j10so341533wrw.8 for ; Tue, 16 Jun 2020 16:13:11 -0700 (PDT) Received: from AK-L.domain.name ([197.58.89.86]) by smtp.gmail.com with ESMTPSA id o9sm2384226wrs.1.2020.06.16.16.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 16:13:09 -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=ClO0YbMLxFK4IoNk8Xcwu72VrPPnrLf9XqnoMALXakg=; b=FcTBWhbiAuTS3aQck2Rv1xN71br3x/y5lDhn4fbGPXEORqgMmS1ap1uN/S5ORNJqcM OS4qYTxbb/bbBO+wzMJgZU8B48Q17ilULwaSRsyimXzOO3um+Vs7kk7WrdzTxtkuObwo dwhk2GkXuUbH13mfbp5EpUR0pIygR5l272BHCxXbtmO5WYno1lme5V7blaP/yq7c3in3 COPKmusuWOUN1vz+KxsdfdW9aDoV5+CqlTtvV4+AkERBT6Lz+p8KLKMMeWGQ3a1SrNdi m+TpzdF5b//B93hSyqnaOr/JVuDt4/+GSw5EOoQFlA79KcKyNcmmeuWSAkzKs2UHw0D2 OnTQ== 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=ClO0YbMLxFK4IoNk8Xcwu72VrPPnrLf9XqnoMALXakg=; b=kV233tpgXDnWvv0IW36LH2fhEaJJ7vX8gZhV9fqMzDtDoVRWaC/IXJXCfDnMsKwc18 hhzhaAhf+DgDxB4ciub9MIfVrl6DzuEvUnBs2wXxQv8LK2QlnGiqC5UZt5nIvoWX9UNl FVcTqQouDbLofyW5hqwO81OyM6MeVYv6hNStW9S73OTP9kamVOKjV5AKnblB/GNc0QWN 140+L4biyhujI5jq5MZoCeFs38c/CL7ycdyhTaKKVLk36umiMZTmT6ehDhOZ/WcJubw7 oEJkSjTFYOETcvF1U4ufufClugzNRVjKymlIvrC0ybyLuvyZqZSfXEWZK5dY9ZElR/eE l7Mw== X-Gm-Message-State: AOAM533hhxFH+q30YLkRZ0K47zoESGCcMqfOBAAu5sxa7JTx0nL4q5ve SNaEMoUfjSRgLaqE9N+G+qkNiI1YmzI= X-Google-Smtp-Source: ABdhPJx9UNcwQD+tNZkvtiw+L/LLheQd0grcNIZ+SaN65caeEM43IjtSAQQcmG75WBtGmeKdvKMuKA== X-Received: by 2002:a5d:468d:: with SMTP id u13mr5659423wrq.73.1592349189716; Tue, 16 Jun 2020 16:13:09 -0700 (PDT) From: Ahmed Karaman To: qemu-devel@nongnu.org, rth@twiddle.net, aleksandar.qemu.devel@gmail.com, alex.bennee@linaro.org, eblake@redhat.com, ldoktor@redhat.com, ehabkost@redhat.com, crosa@redhat.com Subject: [PATCH 2/3] scripts/performance: Add callgrind_top_25.py script Date: Wed, 17 Jun 2020 01:12:03 +0200 Message-Id: <20200616231204.8850-3-ahmedkhaledkaraman@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200616231204.8850-1-ahmedkhaledkaraman@gmail.com> References: <20200616231204.8850-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::42f; envelope-from=ahmedkhaledkaraman@gmail.com; helo=mail-wr1-x42f.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" Python script that prints the top 25 most executed functions in QEMU using callgrind. Signed-off-by: Ahmed Karaman --- scripts/performance/callgrind_top_25.py | 95 +++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 scripts/performance/callgrind_top_25.py diff --git a/scripts/performance/callgrind_top_25.py b/scripts/performance/= callgrind_top_25.py new file mode 100644 index 0000000000..03b089a96d --- /dev/null +++ b/scripts/performance/callgrind_top_25.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 + +# Print the top 25 most executed functions in QEMU using callgrind. +# Example Usage: +# callgrind_top_25.py /x86_64-linux-user/qemu-x86_64 executab= le +# +# 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 os +import sys + +# Ensure sufficient arguments +if len(sys.argv) < 3: + print('Insufficient Script Arguments!') + sys.exit(1) + +# Get the qemu path and the executable + its arguments +(qemu, executable) =3D (sys.argv[1], ' '.join(sys.argv[2:])) + +# Run callgrind and callgrind_annotate +os.system('valgrind --tool=3Dcallgrind --callgrind-out-file=3Dcallgrind.da= ta {} {} \ + 2 > / dev / null & & callgrind_annotate callgrind.data \ + > tmp.callgrind.data'. + format(qemu, executable)) + +# Line number with the total number of instructions +number_of_instructions_line =3D 20 + +# Line number with the top function +first_func_line =3D 25 + +# callgrind_annotate output +callgrind_data =3D [] + +# Open callgrind_annotate output and store it in callgrind_data +with open('tmp.callgrind.data', 'r') as data: + callgrind_data =3D data.readlines() + +# Get the total number of instructions +total_number_of_instructions =3D int( + callgrind_data[number_of_instructions_line].split(' ')[0].replace(',',= '')) + +# Number of functions recorded by callgrind +number_of_functions =3D len(callgrind_data) - first_func_line + +# Limit the number of top functions to 25 +number_of_top_functions =3D (25 if number_of_functions > + 25 else number_of_instructions_line) + +# 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 information headers +print('{:>4} {:>10} {:<25} {}\n{} {} {} {}'.format('No.', + 'Percentage', + 'Name', + 'Source File', + '-' * 4, + '-' * 10, + '-' * 25, + '-' * 30, + )) + +# Print top 25 functions +for (index, function) in enumerate(top_functions, start=3D1): + function_data =3D function.split() + # Calculate function percentage + percentage =3D (float(function_data[0].replace( + ',', '')) / total_number_of_instructions) * 100 + # Get function source path and name + path, name =3D function_data[1].split(':') + # Print extracted data + print('{:>4} {:>9.3f}% {:<25} {}'.format(index, + round(percentage, 3), + name, + path)) + +# Remove intermediate files +os.system('rm callgrind.data tmp.callgrind.data') --=20 2.17.1