public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage
@ 2021-05-25  6:54 gejoed at rediffmail dot com
  2021-05-25  6:58 ` [Bug gcov-profile/100751] " gejoed at rediffmail dot com
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-25  6:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

            Bug ID: 100751
           Summary: __gcov_dump and __gcov_reset usage
           Product: gcc
           Version: 8.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gejoed at rediffmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 50864
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50864&action=edit
sample-prog.i which is the preprocessed version of sample-prog.c

I did go through the online manual of gcc gcov  on __gcov_dump() and
__gcov_reset() :
https://gcc.gnu.org/onlinedocs/gcc/Gcov-and-Optimization.html#Gcov-and-Optimization

I tried out using the functions in a sample program (sample-prog.c) that is
attached here.

The steps followed were :

(1)  gcc -fprofile-arcs -ftest-coverage sample-prog.c 
(2)  ./a.out
(3)  gcov sample-prog.c

While running a.out, when I give character 'g', the __gcov_dump() must be
invoked.
What I could observe is that first time __gcov_dump() is invoked , the
sample-prog.gcda file gets created.
For the second time and then onwards, __gcov_dump() invocation (by giving 'g'
character during the a.out run) doesn't happen.
This is concluded by looking at the time stamp of sample-prog.gcda file in the
same folder. It was still having the same time stamp of first time invocation
of __gcov_dump().

Another thing is  that, __gcov_reset() also doesn't appear to work. I tried
giving the character 'r' during the run of the program but couldn't see the
counters getting reset to 0 in the sample-prog.gcov file. The previous values
of lines covered were there.

Let me know if my approach is correct or if I miss any information here.

I'm attaching the preprocessed file (sample-prog.i) and the logs of the gcc
step used for the preprocessed file.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
@ 2021-05-25  6:58 ` gejoed at rediffmail dot com
  2021-05-25  7:01 ` gejoed at rediffmail dot com
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-25  6:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

Gejoe <gejoed at rediffmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gejoed at rediffmail dot com

--- Comment #1 from Gejoe <gejoed at rediffmail dot com> ---
Created attachment 50865
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50865&action=edit
Preprocessing logs giving gcc version

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
  2021-05-25  6:58 ` [Bug gcov-profile/100751] " gejoed at rediffmail dot com
@ 2021-05-25  7:01 ` gejoed at rediffmail dot com
  2021-05-25  7:56 ` marxin at gcc dot gnu.org
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-25  7:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #2 from Gejoe <gejoed at rediffmail dot com> ---
Created attachment 50866
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50866&action=edit
sample-prog.c file that may be useful for gcov usage test

The original sample source file.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
  2021-05-25  6:58 ` [Bug gcov-profile/100751] " gejoed at rediffmail dot com
  2021-05-25  7:01 ` gejoed at rediffmail dot com
@ 2021-05-25  7:56 ` marxin at gcc dot gnu.org
  2021-05-25 10:57 ` gejoed at rediffmail dot com
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-25  7:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2021-May/571
                   |                            |152.html
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-05-25
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
> For the second time and then onwards, __gcov_dump() invocation (by giving
> 'g' character during the a.out run) doesn't happen.

Yes, one can call __gcov_dump only once per run.
> 
> Another thing is  that, __gcov_reset() also doesn't appear to work. I tried
> giving the character 'r' during the run of the program but couldn't see the
> counters getting reset to 0 in the sample-prog.gcov file. The previous
> values of lines covered were there.

No, __gcov_reset resets run-time counters (profile collected so far during an
application run). If you want to clear profile, then simply remove .gcda files.

I've just send documentation improvement for it:
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571152.html

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (2 preceding siblings ...)
  2021-05-25  7:56 ` marxin at gcc dot gnu.org
@ 2021-05-25 10:57 ` gejoed at rediffmail dot com
  2021-05-25 12:14 ` gejoed at rediffmail dot com
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-25 10:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #4 from Gejoe <gejoed at rediffmail dot com> ---
(In reply to Martin Liška from comment #3)
> > For the second time and then onwards, __gcov_dump() invocation (by giving
> > 'g' character during the a.out run) doesn't happen.
> 
> Yes, one can call __gcov_dump only once per run.

So, I understand that __gcov_dump could be used only after doing all the
testing with the application ,i.e- towards the end to get the profile/coverage
info. Am I right?


> > Another thing is  that, __gcov_reset() also doesn't appear to work. I tried
> > giving the character 'r' during the run of the program but couldn't see the
> > counters getting reset to 0 in the sample-prog.gcov file. The previous
> > values of lines covered were there.
> 
> No, __gcov_reset resets run-time counters (profile collected so far during
> an application run). If you want to clear profile, then simply remove .gcda
> files.

Resetting run-time counters - does that mean it would not get reflected in
.gcda files or the .c.gcov file contents created by gcov (assuming that the
application a.out is still on run )?

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (3 preceding siblings ...)
  2021-05-25 10:57 ` gejoed at rediffmail dot com
@ 2021-05-25 12:14 ` gejoed at rediffmail dot com
  2021-05-25 12:52 ` marxin at gcc dot gnu.org
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-25 12:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #5 from Gejoe <gejoed at rediffmail dot com> ---
Running the program:
./a.out 
g
When g is passed, return value is 8
When 
 is passed, return value is 0
r
When r is passed, return value is 8
When 
 is passed, return value is 0
<< the program is still running, waiting for next character entry>>



Now if we see the sample-prog.c.gcov file , it shows :
        -:   16:    do {
        -:   17:   
        4:   18:        c = getchar();
        4:   19:        result = isalnum(c);
        4:   20:        printf("When %c is passed, return value is %d\n", c,
result);
        -:   21: 
        4:   22:        if(c == 'g')
        2:   23:            __gcov_dump();
        2:   24:        else if(c == 'r')
    #####:   25:            __gcov_reset();
        -:   26:    
        3:   27:    }while(c != 'c');

Looking at line 25, it doesn't show the line is hit (by giving 'r' character
during a.out run) nor are the counter values reset for the other lines. The
count of 4,3,2 are seen for some lines because of a previous a.out run.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (4 preceding siblings ...)
  2021-05-25 12:14 ` gejoed at rediffmail dot com
@ 2021-05-25 12:52 ` marxin at gcc dot gnu.org
  2021-05-25 12:53 ` marxin at gcc dot gnu.org
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-25 12:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
> So, I understand that __gcov_dump could be used only after doing all the
> testing with the application ,i.e- towards the end to get the
> profile/coverage info. Am I right?

Yes, and you don't need to call it manually. Profile automatically saved when
an application exits.

> 
> Resetting run-time counters - does that mean it would not get reflected in
> .gcda files or the .c.gcov file contents created by gcov (assuming that the
> application a.out is still on run )?

Yes, __gcov_reset is supposed to be called at the beginning when an application
wants to start
profiling. Again, you don't need to call it manually.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (5 preceding siblings ...)
  2021-05-25 12:52 ` marxin at gcc dot gnu.org
@ 2021-05-25 12:53 ` marxin at gcc dot gnu.org
  2021-05-25 18:40 ` gejoed at rediffmail dot com
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-25 12:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
> Looking at line 25, it doesn't show the line is hit (by giving 'r' character
> during a.out run) nor are the counter values reset for the other lines. The
> count of 4,3,2 are seen for some lines because of a previous a.out run.

Yes, because once you can __gcov_dump, any profile is saved later.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (6 preceding siblings ...)
  2021-05-25 12:53 ` marxin at gcc dot gnu.org
@ 2021-05-25 18:40 ` gejoed at rediffmail dot com
  2021-05-26  7:31 ` marxin at gcc dot gnu.org
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-25 18:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #8 from Gejoe <gejoed at rediffmail dot com> ---
(In reply to Martin Liška from comment #6)

> Yes, __gcov_reset is supposed to be called at the beginning when an
> application wants to start
> profiling. Again, you don't need to call it manually.

But reset comes into a picture where something has happened already and then
the result needs to be cleared, isn't it ? At the application start, applying a
reset would not make sense I think. gcov_reset would be sensible only after a
gcov_dump , isn't it ?

Let me know if I miss the actual design/flow of these functions.

Thanks !

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (7 preceding siblings ...)
  2021-05-25 18:40 ` gejoed at rediffmail dot com
@ 2021-05-26  7:31 ` marxin at gcc dot gnu.org
  2021-05-26  7:34 ` cvs-commit at gcc dot gnu.org
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-26  7:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #9 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Gejoe from comment #8)
> (In reply to Martin Liška from comment #6)
> 
> > Yes, __gcov_reset is supposed to be called at the beginning when an
> > application wants to start
> > profiling. Again, you don't need to call it manually.
> 
> But reset comes into a picture where something has happened already and then
> the result needs to be cleared, isn't it ?

It's the other way around, you start an application and then you decide you
want to start profiling, so you call __gcov_reste.

> At the application start,
> applying a reset would not make sense I think.

Yes, it does not make sense.

> gcov_reset would be sensible
> only after a gcov_dump , isn't it ?

No, as explained.

> 
> Let me know if I miss the actual design/flow of these functions.

Btw. why do you need calling __gcov_dump and __gcov_reset manually? How is your
training run special?

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (8 preceding siblings ...)
  2021-05-26  7:31 ` marxin at gcc dot gnu.org
@ 2021-05-26  7:34 ` cvs-commit at gcc dot gnu.org
  2021-05-26  7:34 ` marxin at gcc dot gnu.org
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-26  7:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:403bb89bd7f4ec03d4dcbdf8668d0187358631a0

commit r12-1063-g403bb89bd7f4ec03d4dcbdf8668d0187358631a0
Author: Martin Liska <mliska@suse.cz>
Date:   Tue May 25 09:52:01 2021 +0200

    DOC: update documentation of __gcov_{dump,reset}

    gcc/ChangeLog:

            PR gcov-profile/100751
            * doc/gcov.texi: Document that __gcov_dump can be called just
            once and that __gcov_reset resets run-time counters.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (9 preceding siblings ...)
  2021-05-26  7:34 ` cvs-commit at gcc dot gnu.org
@ 2021-05-26  7:34 ` marxin at gcc dot gnu.org
  2021-05-26 15:13 ` gejoed at rediffmail dot com
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-26  7:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #11 from Martin Liška <marxin at gcc dot gnu.org> ---
Closing as works for me and I've updated the documentation a bit.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (10 preceding siblings ...)
  2021-05-26  7:34 ` marxin at gcc dot gnu.org
@ 2021-05-26 15:13 ` gejoed at rediffmail dot com
  2021-05-27 13:53 ` gejoed at rediffmail dot com
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-26 15:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #12 from Gejoe <gejoed at rediffmail dot com> ---
Thanks for all the info.

> Btw. why do you need calling __gcov_dump and __gcov_reset manually? How is
> your training run special?

Actually I work for a firm where the program runs on a device continually and
we get the .gcda files from the device using a command which in turn invoked
__gcov_dump(). Similarly to reset all the counters, we thought of using
__gcov_reset after a __gcov_dump. We tar up the gcda files and take to the
source code where gcov is run.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (11 preceding siblings ...)
  2021-05-26 15:13 ` gejoed at rediffmail dot com
@ 2021-05-27 13:53 ` gejoed at rediffmail dot com
  2021-05-27 13:57 ` marxin at gcc dot gnu.org
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-27 13:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #13 from Gejoe <gejoed at rediffmail dot com> ---
I modified my sample-prog.c file just by adding a line of  __gcov_reset before
the while loop. 

However after a.out run , the sample-prog.c.gcov file was still showing the
counters though I didn't give 'g' for __gcov_dump invocation.

Quoting a portion from sample-prog.c.gcov file :

#####:    9:int main()
        -:   10:{
        -:   11:    unsigned char c;
        -:   12:    int result;
    #####:   13:    unsigned char data[]={127,49,255,255};
    #####:   14:    c = '5';
        -:   15: 
    #####:   16:    __gcov_reset();                                            
      <<<<<<<<Added here jin the original sample-prog.c file just to check the
reset behaviour
        -:   17:    do {
        -:   18:   
        4:   19:        c = getchar();
        4:   20:        result = isalnum(c);
        4:   21:        printf("When %c is passed, return value is %d\n", c,
result);
        -:   22: 
        4:   23:        if(c == 'g')
        1:   24:            __gcov_dump();
        3:   25:        else if(c == 'r')
    #####:   26:            __gcov_reset();
        -:   27:
        3:   28:    }while(c != 'c');


I'm trying to now when would __gcov_reset help us in seeing the counter values
reset to ##### instead of old data(numbers like 4,1,3, etc in .c.gcov file).

Let me know if I miss any info.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (12 preceding siblings ...)
  2021-05-27 13:53 ` gejoed at rediffmail dot com
@ 2021-05-27 13:57 ` marxin at gcc dot gnu.org
  2021-05-27 13:58 ` marxin at gcc dot gnu.org
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-27 13:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #14 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Gejoe from comment #13)
> I modified my sample-prog.c file just by adding a line of  __gcov_reset
> before the while loop. 
> 

Can you please create a test-case that does not need human interaction (remove
getchar please)? Thanks.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (13 preceding siblings ...)
  2021-05-27 13:57 ` marxin at gcc dot gnu.org
@ 2021-05-27 13:58 ` marxin at gcc dot gnu.org
  2021-05-28  5:49 ` gejoed at rediffmail dot com
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-27 13:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #15 from Martin Liška <marxin at gcc dot gnu.org> ---
> I'm trying to now when would __gcov_reset help us in seeing the counter
> values reset to ##### instead of old data(numbers like 4,1,3, etc in .c.gcov
> file).

Note that .gcda profiles are always merged after a program finishes.
__gcov_reset resets only run-time profile (counters collected so far during a
run), so merging happens anyway. If you want to reset a .gcda file, then remove
it.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (14 preceding siblings ...)
  2021-05-27 13:58 ` marxin at gcc dot gnu.org
@ 2021-05-28  5:49 ` gejoed at rediffmail dot com
  2021-05-28  6:15 ` gejoed at rediffmail dot com
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-28  5:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #16 from Gejoe <gejoed at rediffmail dot com> ---
Created attachment 50881
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50881&action=edit
sample-prog.c edited to show __gcov_reset call.

The steps used for compiling and running the attached .c file are as follows:
   gcc -v -save-temps  -fprofile-arcs -ftest-coverage sample-prog.c 
   gcc   -fprofile-arcs -ftest-coverage sample-prog.o
   ./a.out 

The output of a.out run is :
__gcov_dump() invoked!
__gcov_reset() invoked!
__gcov_dump() invoked!
__gcov_reset() invoked!

$ gcov sample-prog.c
sample-prog.c:source file is newer than notes file 'sample-prog.gcno'
(the message is displayed only once per source file)
File 'sample-prog.c'
Lines executed:83.33% of 18
Creating 'sample-prog.c.gcov'

$ cat sample-prog.c.gcov
        -:    0:Source:sample-prog.c
        -:    0:Graph:sample-prog.gcno
        -:    0:Data:sample-prog.gcda
        -:    0:Runs:2
        -:    0:Programs:1
        -:    0:Source is newer than graph
        -:    1:#include <stdio.h>
        -:    2:#include <ctype.h>
        -:    3:#include <unistd.h>
        -:    4:
        -:    5:extern void __gcov_reset(void);
        -:    6:extern void __gcov_flush(void);
        -:    7:extern void __gcov_dump( void);
        -:    8:
        2:    9:int main()
        -:   10:{
        -:   11:    unsigned char c;
        2:   12:    int count=0;
        2:   13:        c = 'g';
        -:   14:
        -:   15:        do {
        -:   16:   
        -:   17:                if(c == 'g'){
        -:   18:                        __gcov_dump();
       20:   19:                        printf("__gcov_dump() invoked!\n");
        4:   20:                        c = 'r';
    #####:   21:                }
    #####:   22:                else if(c == 'r'){
        -:   23:                        __gcov_reset();
       16:   24:                        printf("__gcov_reset() invoked!\n");
    #####:   25:                        c = 'f';
        4:   26:                }
        4:   27:                if(count == 2)
        -:   28:                        c = 'g';
       20:   29:                else if (count > 10)
        2:   30:                        c = 'e';
       18:   31:                count++;
        2:   32:        }while(c != 'e');
       20:   33:    
       20:   34:        return 0;
        -:   35:}

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (15 preceding siblings ...)
  2021-05-28  5:49 ` gejoed at rediffmail dot com
@ 2021-05-28  6:15 ` gejoed at rediffmail dot com
  2021-05-28  6:18 ` gejoed at rediffmail dot com
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-28  6:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #17 from Gejoe <gejoed at rediffmail dot com> ---
Created attachment 50882
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50882&action=edit
sample-prog.i file

Preprocessed file contents.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (16 preceding siblings ...)
  2021-05-28  6:15 ` gejoed at rediffmail dot com
@ 2021-05-28  6:18 ` gejoed at rediffmail dot com
  2021-05-28  6:22 ` gejoed at rediffmail dot com
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-28  6:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #18 from Gejoe <gejoed at rediffmail dot com> ---
(In reply to Martin Liška from comment #14)
> (In reply to Gejoe from comment #13)
> > I modified my sample-prog.c file just by adding a line of  __gcov_reset
> > before the while loop. 
> > 
> 
> Can you please create a test-case that does not need human interaction
> (remove getchar please)? Thanks.

I have attached the .c file as attachment 50881 in Comment #16.
I have shown the steps and .gcov file output there as well.

The preprocess file is attached as #50882.

I read your reply in Comment#15 as well.

I'm trying to understand line #22 to #26 specifically of .c.gcov file(as shown
in commment #16. Let me know if the steps followed in compilation or execution
had any thing wrong.

Thank you for the support !

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (17 preceding siblings ...)
  2021-05-28  6:18 ` gejoed at rediffmail dot com
@ 2021-05-28  6:22 ` gejoed at rediffmail dot com
  2021-05-28  7:30 ` marxin at gcc dot gnu.org
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-28  6:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #19 from Gejoe <gejoed at rediffmail dot com> ---
Just to add on :

The a.out was run twice and hence the value of 20 against line # 19, 29 of
.c.gcov file(as shown in commment #16). Let me know if anything is not clear.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (18 preceding siblings ...)
  2021-05-28  6:22 ` gejoed at rediffmail dot com
@ 2021-05-28  7:30 ` marxin at gcc dot gnu.org
  2021-05-28  9:57 ` gejoed at rediffmail dot com
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-28  7:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #20 from Martin Liška <marxin at gcc dot gnu.org> ---
> I'm trying to understand line #22 to #26 specifically of .c.gcov file(as
> shown in commment #16. Let me know if the steps followed in compilation or
> execution had any thing wrong.

What is wrong with that? What values are expected?

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (19 preceding siblings ...)
  2021-05-28  7:30 ` marxin at gcc dot gnu.org
@ 2021-05-28  9:57 ` gejoed at rediffmail dot com
  2021-05-28 11:38 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-05-28  9:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #21 from Gejoe <gejoed at rediffmail dot com> ---
(In reply to Martin Liška from comment #20)
> > I'm trying to understand line #22 to #26 specifically of .c.gcov file(as
> > shown in commment #16. Let me know if the steps followed in compilation or
> > execution had any thing wrong.
> 
> What is wrong with that? What values are expected?

Actually if we look at line #22 should have the value 16 (after a.out run) and
line #24,25 should have values 4 each instead of what is actually present there
in comment#16.Instead the value of 16,4,4 are shown for line # 24,26,27
respectively. That was my query.

Is that because of some difference with source files and .gcda files as shown
there (in .c.gcov file in Comment #16) as follows ? 
    0:Source is newer than graph

I did delete the gcda file and did the same compilation steps again :
$ gcc -v -save-temps  -fprofile-arcs -ftest-coverage sample-prog.c
$ gcc   -fprofile-arcs -ftest-coverage sample-prog.o
$./a.out

The output was :
$ ./a.out 
__gcov_dump() invoked!
__gcov_reset() invoked!
__gcov_dump() invoked!
__gcov_reset() invoked!

The sample-prog.c.gcov file contents now look fine :
        -:    0:Source:sample-prog.c
        -:    0:Graph:sample-prog.gcno
        -:    0:Data:sample-prog.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <stdio.h>
        -:    2:#include <ctype.h>
        -:    3:#include <unistd.h>
        -:    4:
        -:    5:extern void __gcov_reset(void);
        -:    6:extern void __gcov_flush(void);
        -:    7:extern void __gcov_dump( void);
        -:    8:
        1:    9:int main()
        -:   10:{
        -:   11:    unsigned char c;
        1:   12:    int count=0;
        1:   13:        c = 'g';
        -:   14:
        -:   15:        do {
        -:   16:   
       10:   17:                if(c == 'g'){
        2:   18:                        __gcov_dump();
    #####:   19:                        printf("__gcov_dump() invoked!\n");
    #####:   20:                        c = 'r';
        -:   21:                }
        8:   22:                else if(c == 'r'){
    #####:   23:                        __gcov_reset();
        2:   24:                        printf("__gcov_reset() invoked!\n");
        2:   25:                        c = 'f';
        -:   26:                }
       10:   27:                if(count == 2)
        1:   28:                        c = 'g';
        9:   29:                else if (count > 10)
        1:   30:                        c = 'e';
       10:   31:                count++;
       10:   32:        }while(c != 'e');
        -:   33:    
        1:   34:        return 0;
        -:   35:}
==========================================================

So, for either a one time call of __gcov_dump (though we may attempt to call
__gcov_dump many times)  or at the exit of the program execution, the merge of
profile happens due to which __gcov_reset doesn't get reflected at all. Am I
right ?

Thanks again!

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (20 preceding siblings ...)
  2021-05-28  9:57 ` gejoed at rediffmail dot com
@ 2021-05-28 11:38 ` cvs-commit at gcc dot gnu.org
  2021-05-28 11:41 ` marxin at gcc dot gnu.org
  2021-06-01  5:25 ` gejoed at rediffmail dot com
  23 siblings, 0 replies; 25+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-28 11:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #22 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:d2a913c76f41692fd0bb955d1768f462133d813a

commit r12-1111-gd2a913c76f41692fd0bb955d1768f462133d813a
Author: Martin Liska <mliska@suse.cz>
Date:   Fri May 28 13:35:33 2021 +0200

    DOC: Update __gcov_dump documentation.

            PR gcov-profile/100751

    gcc/ChangeLog:

            * doc/gcov.texi: Revert partially a hunk that was wrong.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (21 preceding siblings ...)
  2021-05-28 11:38 ` cvs-commit at gcc dot gnu.org
@ 2021-05-28 11:41 ` marxin at gcc dot gnu.org
  2021-06-01  5:25 ` gejoed at rediffmail dot com
  23 siblings, 0 replies; 25+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-28 11:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #23 from Martin Liška <marxin at gcc dot gnu.org> ---
> So, for either a one time call of __gcov_dump (though we may attempt to call
> __gcov_dump many times)  or at the exit of the program execution, the merge
> of profile happens due to which __gcov_reset doesn't get reflected at all.
> Am I right ?

Oh, I actually wrongly updated the documentation. When __gcov_reset is called,
run-time counters are reset to zero AND __gcov_dump can be called again (or
profile will be saved at exit).

Slightly modified test-case does now:

$ cat sample-prog.c
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>

extern void __gcov_reset(void);
extern void __gcov_flush(void);
extern void __gcov_dump( void);

int main()
{
    unsigned char c;
    int count=0;
        c = 'g';

        do {
    printf ("c: '%c'\n", c);

                if(c == 'g'){
                        __gcov_dump();
                        printf("__gcov_dump() invoked!\n");
                        c = 'r';
                }
                else if(c == 'r'){
                        __gcov_reset();
                        printf("__gcov_reset() invoked!\n");
                        c = 'f';
                }
                if(count == 2)
                        c = 'g';
                else if (count > 10)
                        c = 'e';
                count++;
        }while(c != 'e');

        return 0;
}

$ gcc sample-prog.c --coverage -g && ./a.out && gcov -t sample-prog.c
c: 'g'
__gcov_dump() invoked!
c: 'r'
__gcov_reset() invoked!
c: 'f'
c: 'g'
__gcov_dump() invoked!
c: 'r'
__gcov_reset() invoked!
c: 'f'
c: 'f'
c: 'f'
c: 'f'
c: 'f'
c: 'f'
c: 'f'
        -:    0:Source:sample-prog.c
        -:    0:Graph:sample-prog.gcno
        -:    0:Data:sample-prog.gcda
        -:    0:Runs:1
        -:    1:#include <stdio.h>
        -:    2:#include <ctype.h>
        -:    3:#include <unistd.h>
        -:    4:
        -:    5:extern void __gcov_reset(void);
        -:    6:extern void __gcov_flush(void);
        -:    7:extern void __gcov_dump( void);
        -:    8:
        1:    9:int main()
        -:   10:{
        -:   11:    unsigned char c;
        1:   12:    int count=0;
        1:   13:        c = 'g';
        -:   14:
        -:   15:        do {
       10:   16:    printf ("c: '%c'\n", c);
        -:   17:   
       10:   18:                if(c == 'g'){
        2:   19:                        __gcov_dump();
    #####:   20:                        printf("__gcov_dump() invoked!\n");
    #####:   21:                        c = 'r';
        -:   22:                }
        8:   23:                else if(c == 'r'){
    #####:   24:                        __gcov_reset();
        2:   25:                        printf("__gcov_reset() invoked!\n");
        2:   26:                        c = 'f';
        -:   27:                }
       10:   28:                if(count == 2)
        1:   29:                        c = 'g';
        9:   30:                else if (count > 10)
        1:   31:                        c = 'e';
       10:   32:                count++;
       10:   33:        }while(c != 'e');
        -:   34:    
        1:   35:        return 0;
        -:   36:}

Which should be correct in my oppinion.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage
  2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
                   ` (22 preceding siblings ...)
  2021-05-28 11:41 ` marxin at gcc dot gnu.org
@ 2021-06-01  5:25 ` gejoed at rediffmail dot com
  23 siblings, 0 replies; 25+ messages in thread
From: gejoed at rediffmail dot com @ 2021-06-01  5:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #24 from Gejoe <gejoed at rediffmail dot com> ---
Thank you Martin for all the info. Kindly bear with me for the delayed
acknowledgement.

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2021-06-01  5:25 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25  6:54 [Bug gcov-profile/100751] New: __gcov_dump and __gcov_reset usage gejoed at rediffmail dot com
2021-05-25  6:58 ` [Bug gcov-profile/100751] " gejoed at rediffmail dot com
2021-05-25  7:01 ` gejoed at rediffmail dot com
2021-05-25  7:56 ` marxin at gcc dot gnu.org
2021-05-25 10:57 ` gejoed at rediffmail dot com
2021-05-25 12:14 ` gejoed at rediffmail dot com
2021-05-25 12:52 ` marxin at gcc dot gnu.org
2021-05-25 12:53 ` marxin at gcc dot gnu.org
2021-05-25 18:40 ` gejoed at rediffmail dot com
2021-05-26  7:31 ` marxin at gcc dot gnu.org
2021-05-26  7:34 ` cvs-commit at gcc dot gnu.org
2021-05-26  7:34 ` marxin at gcc dot gnu.org
2021-05-26 15:13 ` gejoed at rediffmail dot com
2021-05-27 13:53 ` gejoed at rediffmail dot com
2021-05-27 13:57 ` marxin at gcc dot gnu.org
2021-05-27 13:58 ` marxin at gcc dot gnu.org
2021-05-28  5:49 ` gejoed at rediffmail dot com
2021-05-28  6:15 ` gejoed at rediffmail dot com
2021-05-28  6:18 ` gejoed at rediffmail dot com
2021-05-28  6:22 ` gejoed at rediffmail dot com
2021-05-28  7:30 ` marxin at gcc dot gnu.org
2021-05-28  9:57 ` gejoed at rediffmail dot com
2021-05-28 11:38 ` cvs-commit at gcc dot gnu.org
2021-05-28 11:41 ` marxin at gcc dot gnu.org
2021-06-01  5:25 ` gejoed at rediffmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).