From patchwork Fri Jun 14 11:33:02 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: 1947875 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=M01J+A19; 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 4W0xxQ2L95z20KL for ; Fri, 14 Jun 2024 21:33:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 486FD3882165 for ; Fri, 14 Jun 2024 11:33:43 +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.154]) by sourceware.org (Postfix) with ESMTPS id B04C23882100 for ; Fri, 14 Jun 2024 11:33:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B04C23882100 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 B04C23882100 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.103.80.154 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718364802; cv=none; b=t7H30JncVur8WzLFsh3NzXILNkDuMnbRMdp04pCXQhUKin6ybbkZPkiFP1O559f7hFITUGFrMntfW72q5Q5Zbbcfit/h+n7E3VqQhWd1BFDkkvKPcRFfFpZELCKwNRyHuNH1GNHJ7R0OTZw6D8a7KV8A/2DdcWyCzu8n/YruDnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718364802; c=relaxed/simple; bh=d1G3uJwh57r0aXWwywh9XftUjZUTTgM2z5P35cq8UR8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=rREQmFE8ZaOjgMhhN4zMc7kT3Q1SSY6whKn0+zOdDhi3Q5NoUN1Rzs4z3bTi5p1UWQLBvc5m5C3phS9CbzJnkyuRqwlAjcX5zjChspjFcC67rj2OJ4fsuaZuWlKQEiTsWD44Jfku6ul37lwxNRKqgjoo4zb2AZNUnY5FLIp89KU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 8A31930830F4; Fri, 14 Jun 2024 13:33:18 +0200 (CEST) Authentication-Results: ext-mx-out013.mykolab.com (amavis); dkim=pass 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=1718364797; x=1720179198; bh=iquwShw9Aux4KpeJXck+Q0J9O4Vzko6/4xq+TcE33+4=; b=M01J+A19nVAM IrTj8leL0YPpRC5iLeb+kuiM8125reBLW97vW7VLQI77T/319KiiHnwi8gDF5q1X aM5lFS/HMLC5rNLHvUpySY1+uXJeyybIn6rHGdvnqiYzXVx+7XtTnm2SXwM9IJj+ Z1n3x9fJl3AwBOyQFVl6B+eQMeehnZJfS5dDrzsA1qycEmQdBf5ZTITKLhEToozW KIyzCOlMGYkXjrfYsmgc30aBYg8AIfPXr37lqUDJnOw9ZTOWmn9LZNNK9yaz9qEl zzG2fuOJgkS0pYjC0+7RPb0rTVqlfjRgRfJyZfesce6M3Dkb5IXu01LjLYV/oqsB 3k797RhtQg== X-Virus-Scanned: amavis at mykolab.com X-Spam-Score: -1 X-Spam-Level: X-Spam-Status: No, score=-12.3 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-out013.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id qCRRzAjkVFZE; Fri, 14 Jun 2024 13:33:17 +0200 (CEST) Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 982AF30830F3; Fri, 14 Jun 2024 13:33:17 +0200 (CEST) Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 661EA21B3771; Fri, 14 Jun 2024 13:33:17 +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/2] Add examples on filteirng in gcov tutorial Date: Fri, 14 Jun 2024 13:33:02 +0200 Message-Id: <20240614113302.481469-2-j@lambda.is> In-Reply-To: <20240614113302.481469-1-j@lambda.is> References: <20240614113302.481469-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 Add a section with some examples on the --include and --exclude flags in the gcov tutorial. gcc/ChangeLog: * doc/gcov.texi: Add tutorial on function filtering. --- gcc/doc/gcov.texi | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi index a9690bf5a69..dc79bccb8cf 100644 --- a/gcc/doc/gcov.texi +++ b/gcc/doc/gcov.texi @@ -933,6 +933,92 @@ the file doesn't match the executable (differing number of basic block counts) it will ignore the contents of the file. It then adds in the new execution counts and finally writes the data to the file. +You can report on a subset of functions by using @option{--include} +and @option{--exclude}. This is very useful when combined with +@option{--stdout} trying to understand behavior and coverage for a +particular function by running a test, looking at @command{gcov} +output, testing another input, and running @command{gcov} again. + +@smallexample +$ gcov -m --stdout --include inc tmp + -: 0:Source:tmp.cpp + -: 0:Graph:tmp.gcno + -: 0:Data:tmp.gcda + -: 0:Runs:1 + 2*: 8: void inc () @{ b++; @} +------------------ +Foo::inc(): + #####: 8: void inc () @{ b++; @} +------------------ +Foo::inc(): + 2: 8: void inc () @{ b++; @} +------------------ +@end smallexample + +@command{gcov} will match on mangled names by default, which you can +control with the @option{-M} flag. Note that matching and reporting +are independent, so you can match on mangled names while printing +demangled names, and vice versa. To report on the @code{int} +instantiation of @code{Foo} matching on mangled and demangled names: + +@smallexample +$ gcov -t -m -M tmp --include 'Foo' + -: 0:Source:tmp.cpp + -: 0:Graph:tmp.gcno + -: 0:Data:tmp.gcda + -: 0:Runs:1 + 1: 7: Foo(): b (1000) @{@} + 2: 8: void inc () @{ b++; @} +@end smallexample + +@smallexample +$ gcov -t -m tmp --include 'FooIi' + -: 0:Source:tmp.cpp + -: 0:Graph:tmp.gcno + -: 0:Data:tmp.gcda + -: 0:Runs:1 + 1: 7: Foo(): b (1000) @{@} + 2: 8: void inc () @{ b++; @} +@end smallexample + +The arguments to @option{--include} and @option{--exclude} are +extended regular expressions (like @command{grep -E}), so the pattern +@code{in.?} matches both @code{inc} and @code{main}. If used with +@option{-M} then all @code{int} instantiations of @code{Foo} would +match too. @option{--include} and @option{--exclude} can be used +multiple times, and if a name matches multiple filters it is the last +one to match which takes preference. For example, to match +@code{main} and the @code{int} instatiation of @code{inc}, while +omitting the @code{Foo} constructor: + +@smallexample +$ gcov -t -m -M --include in --exclude Foo --include '::inc' tmp + -: 0:Source:tmp.cpp + -: 0:Graph:tmp.gcno + -: 0:Data:tmp.gcda + -: 0:Runs:1 + 2: 8: void inc () @{ b++; @} + 1: 18:main (void) + -: 19:@{ + -: 20: int i, total; + 1: 21: Foo counter; + -: 22: + 1: 23: counter.inc(); + 1: 24: counter.inc(); + 1: 25: total = 0; + -: 26: + 11: 27: for (i = 0; i < 10; i++) + 10: 28: total += i; + -: 29: + 1*: 30: int v = total > 100 ? 1 : 2; + -: 31: + 1: 32: if (total != 45) + #####: 33: printf ("Failure\n"); + -: 34: else + 1: 35: printf ("Success\n"); + 1: 36: return 0; +@end smallexample + @node Gcov and Optimization @section Using @command{gcov} with GCC Optimization