From patchwork Thu Aug 8 09:16:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= X-Patchwork-Id: 1970465 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=kolabnow.com header.i=@kolabnow.com header.a=rsa-sha256 header.s=dkim20240523 header.b=MbVv0lH6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WfhJK2KG0z1ydk for ; Thu, 8 Aug 2024 19:17:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66E2C3858294 for ; Thu, 8 Aug 2024 09:17:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.155]) by sourceware.org (Postfix) with ESMTPS id 9D0863858D34 for ; Thu, 8 Aug 2024 09:16:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D0863858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lambda.is Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lambda.is ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9D0863858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.103.80.155 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723108588; cv=none; b=syp0426lx9+tAu5B2RuRb7uHykjX3UjQSoRYfwFU88JfyJgPDPWbIF9BQy6fRv+PF1wnZhSmcWRdM6Fm2HowNcGek/UbKCMScFdK2EZ/0yDXfv5jO1DM1v9/8vOmIK9MjgREyHpMUZiBvgNyLyuxEiKy4NkwRaSsJ1+8E+UKBtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723108588; c=relaxed/simple; bh=xUWqI+BmnWcwd2ZnAc0GXgDbPBy8XtAuvudsan/DNbk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=NCJZhYPhEFVoJNMZJ7Yp6BaS73vJCjSh7c2nQ/LdE+6LQYe+Szyu0+yDqRXzI8Z7XMpaoXachTDJNlbPB5Ah23yS1lPmijyIkpIpDkrtWH08x6pk9cFIuRt8Qzt9S6jc7UT568h/EcLuFwnQpe7Ibj8C2S+MVOEYT0kpOU/HR3M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id A4D7D234228A; Thu, 8 Aug 2024 11:16:24 +0200 (CEST) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:date:subject:subject:from:from:received :received:received; s=dkim20240523; t=1723108580; x=1724922981; bh=hnVTGuMHVd+ZoRptjHM3YnUAovA0Ui4vvqoDj60f1R8=; b=MbVv0lH61Gpy hRaOsXPiUoXlq+QvOrbRSNLpDZrjGWTQ5GatRur4fBKIkfYa65eYu2LcXZAdiZ7j rQI2oenS+eaDJ1Yd53iyX2pY1Phh5G/C53Wu1bc9CQ/Tc05DpBDmGlBNlLE0TfwU VFkU4lnbN3FpXQ7/N0RYasgpVZXcFPUc7Rp6EeeS0lMOi/+i7OgmmWA+n2BxwNYy 5dtIevz72QfyN7zUvzNSFTGd0OmrEUGLSl+SaaHXk/2Me7SohCdmiI9pk7IQNUMc 6JdAk2VPZwP+yH/KXXmlXtBCYmltFVOTsvAwerguiHoQM8SZse8WGnCS4FZEuFIG wxJsUnktAg== X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out011.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id vUOVJtysdy0U; Thu, 8 Aug 2024 11:16:20 +0200 (CEST) Received: from int-mx011.mykolab.com (unknown [10.9.13.11]) by mx.kolabnow.com (Postfix) with ESMTPS id 0CCBF2342289; Thu, 8 Aug 2024 11:16:19 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx011.mykolab.com (Postfix) with ESMTPS id CA88C311F502; Thu, 8 Aug 2024 11:16:19 +0200 (CEST) From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: hubicka@ucw.cz, =?utf-8?q?J=C3=B8rgen_Kvalsvik?= Subject: [PATCH 2/3] gcov: branch, conds, calls in function summaries Date: Thu, 8 Aug 2024 11:16:05 +0200 Message-Id: <20240808091606.3371196-4-j@lambda.is> In-Reply-To: <20240808091606.3371196-1-j@lambda.is> References: <20240808091606.3371196-1-j@lambda.is> MIME-Version: 1.0 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The gcov function summaries only output the covered lines, not the branches and calls. Since the function summaries is an opt-in it probably makes sense to also include branch coverage, calls, and condition coverage. $ gcc --coverage -fpath-coverage hello.c -o hello $ ./hello Before: $ gcov -f hello Function 'main' Lines executed:100.00% of 4 Function 'fn' Lines executed:100.00% of 7 File 'hello.c' Lines executed:100.00% of 11 Creating 'hello.c.gcov' After: $ gcov -f hello Function 'main' Lines executed:100.00% of 3 No branches Calls executed:100.00% of 1 Function 'fn' Lines executed:100.00% of 7 Branches executed:100.00% of 4 Taken at least once:50.00% of 4 No calls File 'hello.c' Lines executed:100.00% of 10 Creating 'hello.c.gcov' Lines executed:100.00% of 10 With conditions: $ gcov -fg hello Function 'main' Lines executed:100.00% of 3 No branches Calls executed:100.00% of 1 No conditions Function 'fn' Lines executed:100.00% of 7 Branches executed:100.00% of 4 Taken at least once:50.00% of 4 Condition outcomes covered:100.00% of 8 No calls File 'hello.c' Lines executed:100.00% of 10 Creating 'hello.c.gcov' Lines executed:100.00% of 10 gcc/ChangeLog: * gcov.cc (generate_results): Count branches, conditions. (function_summary): Output branch, calls, condition count. --- gcc/gcov.cc | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) --- gcc/gcov.cc | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/gcc/gcov.cc b/gcc/gcov.cc index 19019f404ee..7215a00c702 100644 --- a/gcc/gcov.cc +++ b/gcc/gcov.cc @@ -1687,11 +1687,19 @@ generate_results (const char *file_name) memset (&coverage, 0, sizeof (coverage)); coverage.name = fn->get_name (); add_line_counts (flag_function_summary ? &coverage : NULL, fn); - if (flag_function_summary) - { - function_summary (&coverage); - fnotice (stdout, "\n"); - } + + if (!flag_function_summary) + continue; + + for (const block_info& block : fn->blocks) + for (arc_info *arc = block.succ; arc; arc = arc->succ_next) + add_branch_counts (&coverage, arc); + + for (const block_info& block : fn->blocks) + add_condition_counts (&coverage, &block); + + function_summary (&coverage); + fnotice (stdout, "\n"); } name_map needle; @@ -2764,6 +2772,36 @@ function_summary (const coverage_info *coverage) { fnotice (stdout, "%s '%s'\n", "Function", coverage->name); executed_summary (coverage->lines, coverage->lines_executed); + + if (coverage->branches) + { + fnotice (stdout, "Branches executed:%s of %d\n", + format_gcov (coverage->branches_executed, coverage->branches, 2), + coverage->branches); + fnotice (stdout, "Taken at least once:%s of %d\n", + format_gcov (coverage->branches_taken, coverage->branches, 2), + coverage->branches); + } + else + fnotice (stdout, "No branches\n"); + + if (coverage->calls) + fnotice (stdout, "Calls executed:%s of %d\n", + format_gcov (coverage->calls_executed, coverage->calls, 2), + coverage->calls); + else + fnotice (stdout, "No calls\n"); + + if (flag_conditions) + { + if (coverage->conditions) + fnotice (stdout, "Condition outcomes covered:%s of %d\n", + format_gcov (coverage->conditions_covered, + coverage->conditions, 2), + coverage->conditions); + else + fnotice (stdout, "No conditions\n"); + } } /* Output summary info for a file. */