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: 207308 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2815468dyb; Tue, 27 Feb 2024 08:36:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXopmqhp1NqgBAw1gkRrXyegfArU+8h6ifZb1dlYMxCh1orlEs250vMX6YKkzqUcmddB+/2u7kfucOthpK7uBjj3xVSxQ== X-Google-Smtp-Source: AGHT+IGhpVREUAPpamesQk9mlnfbwHUtnar3WveYAv5T4381VyY2UJhpdpV4DOSMTp6r25EFf4mE X-Received: by 2002:a05:6808:1416:b0:3c1:35de:bdb6 with SMTP id w22-20020a056808141600b003c135debdb6mr2944681oiv.6.1709051800547; Tue, 27 Feb 2024 08:36:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709051800; cv=pass; d=google.com; s=arc-20160816; b=WIxYYgXpgNEFUNqg2liMdhGIIEQX240tA4gHOhmn8RezplAQTsk8n9pPbC2qX3696e 1QcJd9Ey0vCK9eKrzwzoHzs1zT33234dCXtNqg3U9vfoaTkd/v7hl+KYogGFro8LnWtD 0bNT6+DFubDNY17gX16NcjGrS2WYuaDzh+Onr/mNPoCcqT4jcriUJ/8xjtkFyBt7V+Yj 9KVZFIBbKZstzCUlJPQNOwe+/BY4+Dp0bS4W7DHgzCc6cIo5uiM0JRnwlCae2pN9IhbD NmU9mET/eGtyHmDX18BiUwgRMNdnqRzHehGuj06e+GlGV2onyTPbPVCKmoOaOKIcSqV0 +UrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=9WKCyPuB9T8bKOhOVkCcYDo3pljFCygLA2zTAK9THMM=; fh=qcCNa5IxmC1cU6N/mXsmIWchX0e96q2rQNudpfCbMtE=; b=eRB3R/1qk8ckY+RYxOWXvMbf9+6hGuO339cUNh73N6vFZJhGv+6LSgpeUxdMbi1oD9 7g1p2qqxZvYkbFhFBjT4pGJ4EoYEc0i80mUmxnCFH/PwqovEyN1s8jft7ETas17iaJ4r LVCaRe20CsOxoo/3QqJFXTulYzJs7N82OQykO6Kokro1+sIlZmyvPIESRORbbafRhd8E 8kg/Tu8/PGcRZkLJmnVV2e9THcY9NypffIZFF4qc0uQPZ9NZxTD3dRCFYwaNQqdA04uz VAyP91HM47BpSyLuenWl40eHHMfMIY4Nrlv0rTVYPO1Y2qAXBy36YNkLM3zEy/cVbxnM ZWqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b=xS9rFYqU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m18-20020ac84452000000b0042e7035cf32si7690565qtn.560.2024.02.27.08.36.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 08:36:40 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@kolabnow.com header.s=dkim20160331 header.b=xS9rFYqU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 423B13858C3A for ; Tue, 27 Feb 2024 16:36:40 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792070700383616295 X-GMAIL-MSGID: 1792070700383616295 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. */