From patchwork Tue Nov 9 08:40:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Holger Blasum X-Patchwork-Id: 70501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6847CB70F7 for ; Tue, 9 Nov 2010 19:41:27 +1100 (EST) Received: (qmail 10833 invoked by alias); 9 Nov 2010 08:41:15 -0000 Received: (qmail 10652 invoked by uid 22791); 9 Nov 2010 08:41:12 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.sysgo.com (HELO mail.sysgo.com) (195.145.229.155) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Nov 2010 08:41:06 +0000 Received: from lantia.sysgo.com (unknown [172.22.2.7]) by mail.sysgo.com (Postfix) with ESMTP id E02C114543; Tue, 9 Nov 2010 09:41:03 +0100 (CET) Received: by lantia.sysgo.com (Postfix, from userid 113) id F3EB05A2A0; Tue, 9 Nov 2010 09:41:03 +0100 (CET) Received: from laptop-hbl.localdomain (unknown [172.25.1.146]) by lantia.sysgo.com (Postfix) with ESMTPS id 11F935A0F3; Tue, 9 Nov 2010 09:41:02 +0100 (CET) Date: Tue, 9 Nov 2010 09:40:31 +0100 From: Holger Blasum To: gcc-patches@gcc.gnu.org Cc: Ralf Wildenhues , Richard Guenther , Andi Kleen , Zdenek Dvorak Subject: Re: gcov: option to instrument whole basic block graph, no use of spanning tree optimization Message-ID: <20101109084031.GA9381@laptop-hbl.localdomain> References: <87oca0sppn.fsf@basil.nowhere.org> <20101108104552.GA26559@kam.mff.cuni.cz> <87bp60rrn9.fsf@basil.nowhere.org> <20101108142812.GA9556@laptop-hbl.localdomain> <20101108190956.GD16935@gmx.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20101108190956.GD16935@gmx.de> User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello Ralf, On Mon, Nov 08, 2010 at 08:09:56PM +0100, Ralf Wildenhues wrote: > here's a syntactic-only review: ... points taken, fixed in attached patch (combining both previous ones). Note: this way of amending the documentation I think would easily allow to add another option for e.g. adding/switching to e.g. atomic counter incrementation once that is included (which of course I would welcome). g, Index: gcc/doc/gcov.texi =================================================================== --- gcc/doc/gcov.texi (revision 166453) +++ gcc/doc/gcov.texi (working copy) @@ -41,6 +41,9 @@ * Gcov Intro:: Introduction to gcov. * Invoking Gcov:: How to use gcov. * Gcov and Optimization:: Using gcov with GCC optimization. +* Counter Size:: Counter size. +* Multithreaded Programs:: Collecting Coverage Data + from Multithreaded Programs. * Gcov Data Files:: The files used by gcov. * Cross-profiling:: Data file relocation. @end menu @@ -512,6 +515,34 @@ coverage of all the uses of the inline function will be shown for the same source lines, the line counts themselves might seem inconsistent. +@node Counter Size +@section Counter Size + +Counters are implemented as a 64-bit value which means that overflow +would occur only after @math{2^{64}} steps through a program path. +Overflow usually can be ruled out by ascertaining that coverage +run time times CPU speed is less than @math{2^{64}}. + +@node Multithreaded Programs +@section Collecting Coverage Data from Multithreaded Programs + +As the implementation of threads and context switching depends on +the operational environment, it is hard to implement a truly portable +coverage for multithreaded programs at the compiler level. So +@command{gcov} will not be faithful in multithreaded programs. If, +during compilation, the additional option @option{-fprofile-whole-graph} +is specified, then @command{gcov} will use a representation of +the whole basic block graph instead of the otherwise optimal +spanning tree optimization. That means that the compiled program +will use more memory but is more robust than when the spanning tree +optimization is used. In the absence of counter overflow that +implies that coverage in multithreaded programs is conservatively +estimated: it may be underreported but in particular this option +ensures that a non-zero coverage value means that the path has been +taken and conversely that if a path has been taken the coverage value +is non-zero. (This property still can be useful if one wants test +coverage.) + @c man end @node Gcov Data Files Index: gcc/opts.c =================================================================== --- gcc/opts.c (revision 166453) +++ gcc/opts.c (working copy) @@ -2018,6 +2018,10 @@ flag_gcse_after_reload = value; break; + case OPT_fprofile_whole_graph: + flag_profile_whole_graph = 1; + break; + case OPT_fprofile_generate_: profile_data_prefix = xstrdup (arg); value = true; Index: gcc/profile.c =================================================================== --- gcc/profile.c (revision 166453) +++ gcc/profile.c (working copy) @@ -1020,7 +1020,8 @@ on the spanning tree. We insert as many abnormal and critical edges as possible to minimize number of edge splits necessary. */ - find_spanning_tree (el); + if (!flag_profile_whole_graph) + find_spanning_tree (el); /* Fake edges that are not on the tree will not be instrumented, so mark them ignored. */ Index: gcc/common.opt =================================================================== --- gcc/common.opt (revision 166453) +++ gcc/common.opt (working copy) @@ -1299,6 +1299,10 @@ Common Report Var(flag_profile_values) Insert code to profile values of expressions +fprofile-whole-graph +Common RejectNegative Var(flag_profile_whole_graph,0) +Whole basic block graph for profiling instead of spanning tree (needs more memory, but better approximation for multithreading) + frandom-seed Common