From patchwork Tue Feb 27 16:35:43 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: 1905335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (4096-bit key; secure) header.d=kolabnow.com header.i=@kolabnow.com header.a=rsa-sha256 header.s=dkim20160331 header.b=xS9rFYqU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4TkjmP2bQTz1yX4 for ; Wed, 28 Feb 2024 03:36:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A58B385840F for ; Tue, 27 Feb 2024 16:36:17 +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 864253858D20 for ; Tue, 27 Feb 2024 16:35:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 864253858D20 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 864253858D20 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=1709051757; cv=none; b=NBK1qxh2Jv8k88cQV1dCB7vbM+73Quhanp9EXOfwW3cIxP9QpwxhlQ3zQg5aqF/rBiJenhtog7zJIl/MDZ0ufSqxbU1nj/mDbOTwuXoQAQ0oE1J04+ZixRtC/3Q+FLlAXVWy5NHLWgR+tfevoxncAbrgqTnX4d96TJils8VKlYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709051757; c=relaxed/simple; bh=Ugsa3QzeizdHV9Sh2RS0V4AmJXbPbaW/t22dpCundP0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=b5/esNriQmSjaCZsGTwsk4Y7WW/k40caJ/PFgmSR/41izsy1Q/lXD5kaAMGOcTndf+PkluG4b1StdAb2t3nKsJ6YlzzF/1N7jTDEfLacTI+gQMSG3GHzS+bYZ3UKlxnC0C+9y28mFYVB8MqUCMCd+ttjlIiPwR8+GRPnkJD/Ulw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 75C0C2095C3A for ; Tue, 27 Feb 2024 17:35:53 +0100 (CET) Authentication-Results: ext-mx-out011.mykolab.com (amavis); dkim=pass (4096-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:message-id:date:date :subject:subject:from:from:received:received:received; s= dkim20160331; t=1709051750; x=1710866151; bh=9WKCyPuB9T8bKOhOVkC cYDo3pljFCygLA2zTAK9THMM=; b=xS9rFYqUoE1vjF+E7XC+k0bdIWHvdgYhDT8 G3kXfMGxdzrdYFyIKSt/KeymQr5o9JxQ8+a84Sq511iGrvZywJZbNdpA0chwF7X6 HD41krVpcZoPwzu7QMdWYkN46jTXn9M6IjIARN3QvwuzWWPFxEIZth0W0e6u9N49 DNLc+8cXFOoixknDA3dAhfiOHcnuzCERY78ii11pb8M/gzSWBhHWN8FZy8M4W2Wn AjKbMZ3QmvIt6P1Q4TjpMGqBWDcB4ySg2GT+cvpC/0WZBfg3P2zKh+Q3WvpAK33t vARV+FMaMiPOSgzppPrxk/0gaf0Nxikn4IUNmjHQ/rIwUH9J33jNP9LMJv6LiLe+ MNdl6ghhgSMjDgifUfoBHRl96hkDd8iy7yUNDamyfL3vZSx6fqJBIRtWHQNdOefG wX4ocJEj3eeB0e0BZwIiaZRHKKSaoe9+YBMleHyba7R4/sTsrrQP1jyido46+gGu BC19sWn+dlCLvZq2tmblwpBUH6MUi3qOYGtXk6lVzFbhEsnh0SxB53+G9MH/6piX ea6OZSNzaM/qpscZoLmJdDFLTEO0u74efYt+kJCDdJohOPhZMxMVI6pnfZzNKFO+ ABppWoh0PbI1SOPlpQyIz9QpbS7Vl21qpiVq3ckX7Xsp8FS+ZeXmKB138dmIoLD4 LSQgWlEw= X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -0.999 X-Spam-Level: X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 qeTeNnQr939U for ; Tue, 27 Feb 2024 17:35:50 +0100 (CET) Received: from int-mx011.mykolab.com (unknown [10.9.13.11]) by mx.kolabnow.com (Postfix) with ESMTPS id 915DE2095C1B for ; Tue, 27 Feb 2024 17:35:50 +0100 (CET) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx011.mykolab.com (Postfix) with ESMTPS id EC32530BBC31 for ; Tue, 27 Feb 2024 17:35:49 +0100 (CET) From: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?J=C3=B8rgen_Kvalsvik?= Subject: [PATCH] Output branches and calls in gcov function summaries Date: Tue, 27 Feb 2024 17:35:43 +0100 Message-Id: <20240227163543.2101976-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. Simply adds the branch- and call information to the function-summaries output. $ gcc --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 gcc/ChangeLog: * gcov.cc (generate_results): Count branches. (function_summary): Output branch count. --- gcc/gcov.cc | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) --- I am unsure if it is intentional for the function-summaries to be line only, but I did find it a bit odd, so I submit this patch for feedback. If this is ok we could also look into refactoring the summaries slightly, to bring together the printing function- and file summaries. --- diff --git a/gcc/gcov.cc b/gcc/gcov.cc index 2fad6aa7ede..4b9aafa543c 100644 --- a/gcc/gcov.cc +++ b/gcc/gcov.cc @@ -1530,11 +1530,18 @@ 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) + + if (!flag_function_summary) + continue; + + for (const block_info& block : fn->blocks) { - function_summary (&coverage); - fnotice (stdout, "\n"); + for (arc_info *arc = block.succ; arc; arc = arc->succ_next) + add_branch_counts (&coverage, arc); } + + function_summary (&coverage); + fnotice (stdout, "\n"); } name_map needle; @@ -2528,6 +2535,25 @@ 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"); } /* Output summary info for a file. */