From patchwork Wed Feb 12 15:30:01 2025 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: 106381 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0AE68385828E for ; Wed, 12 Feb 2025 15:36:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AE68385828E 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 1B3E7385840E for ; Wed, 12 Feb 2025 15:30:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B3E7385840E 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 1B3E7385840E 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=1739374221; cv=none; b=oWYJggp81tSBmtm0UBLOuS/SGGO8rabFpUMJU96dfOQH2JGDFUB7NurCEvJmbpATxxaWTwtIYek+Rfaj3clApAVbH44qDb9qpkjr8OIVN1ikAfU7DqvxpYfXOWfUMffZQrqbX0oFF17UzdKqBw4QA6+gv2mOCsEwgAP7yZIOWu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739374221; c=relaxed/simple; bh=nFbJ1IzZnAGOVscR6FoFZJjnd9auLuyR/+UA8PyN6KU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=F9w+TPzxd15EF1hZYerrUHeNH+w2jjelbhBY9uGyASPDN3N8Yv/xtqeL3XGLF2eA1aEOwezajWv8RyMl/ckMhdWIp1XylYdGKCZwsFczRYSMW9Hgt30SD6bIixn2Yq7rn2Vp1jr++XeH2ibuTcWnBMmRCx7Vfw9am95uURg5RGw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B3E7385840E Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 2557E20B277E; Wed, 12 Feb 2025 16:30:19 +0100 (CET) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass reason="pass (just generated, assumed good)" header.d=lambda.is DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lambda.is; h= content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:date:subject:subject:from:from:received :received:received; s=dkim2; t=1739374218; x=1741188619; bh=I5wb QkcGDZYGCbkc8j51qpQlh37jaqEPykp55QrM/kk=; b=pPQDL1rQkvFllr23uUto OwDKDA0+jVlRK+kqdNpS8QKzFwjG349/JmaTQtpz/aPhAlv8hBSxlSVrhN/Z8fr2 LMAEa6KU3MptmXfysGx1USsgmik8edeq+1l2I++E5biE/EJqi6IqYQv1MtQwXtLu wr0uowzdv3Mu58CI4RlNTZgQDmNhiud4f1jGrNmB21+j1QxpxIzbc0a1a/tecvua AWGW0ABL/NIn5LIi69lpOIx8nQb+oXUzQ/zUevzahAhkapz8U1Ym7tahfSyjYyGH r5Pzc/s3FtSaItJJxoJgLYhTr+c3myNPIqxzLstsoM3ZATT1ThU6cM+DrYE63aux MA== X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, 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 rPGpF8xi54OL; Wed, 12 Feb 2025 16:30:18 +0100 (CET) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 56F2A20B2744; Wed, 12 Feb 2025 16:30:18 +0100 (CET) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 2540C20AA550; Wed, 12 Feb 2025 16:30:18 +0100 (CET) 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 1/2] gcov: branch, conds, calls in function summaries Date: Wed, 12 Feb 2025 16:30:01 +0100 Message-Id: <20250212153002.3607542-2-j@lambda.is> In-Reply-To: <20250212153002.3607542-1-j@lambda.is> References: <20250212153002.3607542-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~patchwork=sourceware.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 | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/gcc/gcov.cc b/gcc/gcov.cc index 89f3c536bfb..026f130db87 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. */