[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-31 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #24 from Gejoe  ---
Thank you Martin for all the info. Kindly bear with me for the delayed
acknowledgement.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #23 from Martin Liška  ---
> 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 
#include 
#include 

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 
-:2:#include 
-:3:#include 
-: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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #22 from CVS Commits  ---
The master branch has been updated by Martin Liska :

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

commit r12--gd2a913c76f41692fd0bb955d1768f462133d813a
Author: Martin Liska 
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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #21 from Gejoe  ---
(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 
-:2:#include 
-:3:#include 
-: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!

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #20 from Martin Liška  ---
> 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?

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #19 from Gejoe  ---
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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #18 from Gejoe  ---
(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 !

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-28 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #17 from Gejoe  ---
Created attachment 50882
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50882=edit
sample-prog.i file

Preprocessed file contents.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-27 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #16 from Gejoe  ---
Created attachment 50881
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50881=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 
-:2:#include 
-:3:#include 
-: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:}

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-27 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #15 from Martin Liška  ---
> 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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-27 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #14 from Martin Liška  ---
(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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-27 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #13 from Gejoe  ---
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();
  <<<

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-26 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #12 from Gejoe  ---
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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-26 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

Martin Liška  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |WORKSFORME

--- Comment #11 from Martin Liška  ---
Closing as works for me and I've updated the documentation a bit.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-26 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #10 from CVS Commits  ---
The master branch has been updated by Martin Liska :

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

commit r12-1063-g403bb89bd7f4ec03d4dcbdf8668d0187358631a0
Author: Martin Liska 
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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-26 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #9 from Martin Liška  ---
(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?

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #8 from Gejoe  ---
(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 !

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #7 from Martin Liška  ---
> 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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #6 from Martin Liška  ---
> 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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #5 from Gejoe  ---
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.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

--- Comment #4 from Gejoe  ---
(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 )?

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

Martin Liška  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  ---
> 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

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

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

The original sample source file.

[Bug gcov-profile/100751] __gcov_dump and __gcov_reset usage

2021-05-25 Thread gejoed at rediffmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100751

Gejoe  changed:

   What|Removed |Added

 CC||gejoed at rediffmail dot com

--- Comment #1 from Gejoe  ---
Created attachment 50865
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50865=edit
Preprocessing logs giving gcc version