Author Topic: Gcov  (Read 13420 times)

Diogenes

  • Guest
Gcov
« on: November 15, 2010, 05:53:01 pm »
Hello, is possible invocate gcov ( Code coverage ) from CodeBlocks ?

Thanks !

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9415
Re: Gcov
« Reply #1 on: November 16, 2010, 12:53:55 pm »
Hello, is possible invocate gcov ( Code coverage ) from CodeBlocks ?
You can attach it as a "tool" in the tools menu using macros to point to the files as needed.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 198
Re: Gcov
« Reply #2 on: November 16, 2010, 10:56:02 pm »
Not sure if this helps (since you have to build the attached plugin yourself)

It is a gcov plugin in a eary stage. The only thing it can do
  • start gcov for all files of the active project and
  • show the line coverage in source editor (see screenshot))

« Last Edit: November 16, 2010, 10:59:14 pm by danselmi »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5016
Re: Gcov
« Reply #3 on: November 17, 2010, 08:39:55 am »
sounds very great.

I am looking forward for its expansion ;-)


Things from the top of my head :
- code in a library (for example : library X , and executable project Y [say a the unit tests for the library]) : how much of the library code was challenged in the unit tests
- overall percentage
- ...


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10277
Re: Gcov
« Reply #4 on: November 17, 2010, 08:53:41 am »
+1

danselmi: you could add a list with files sorted by coverage percentage, so someone can see which files are least used :)
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #5 on: March 15, 2011, 10:44:27 am »
Hi, this has been a while ago, is there any update to the plug in?
I need to carry out a simple task to find out the percentage of code lines executed on each run. That takes quite some time to do manually, especially with multiple small projects and files. Furthermore, I faced a problem that, it seems, one must run the program from the same path as it was compiled in? (the project directory) Else the run trace is not generated.
E.g. run trace for main executable is generated, but not for the dll's it is loading, because those have been copied from their output dir and the exe wasn't.
I also attach a very primitive cb script, that tries to do the job, but is not very good at it :)

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #6 on: March 17, 2011, 02:32:51 pm »
Let me share the changes I have made to the plugin. Attached is src and a binary, compiled with 1.12.0 sdk, so it should run with any dbg branch nightly.

Things new and fixed:

* Looking for a .gcov file in the base project directory, not in the same as corresponding src file. This makes projects with source code directory hierarchy work properly.
* wxTextFile was not able to open even slightly larger .gcov files, reading in a different way.
* The plugin does not print gcov output directly to cb log window. Instead it displays some more useful statistics per project basis, e.g.:

Gcov summary: 8 files analyzed
File1.CPP   : 41 of 73 lines executed (56.2%)
File2.cpp   : 487 of 786 lines executed (62.0%)
File3.cpp   : 307 of 473 lines executed (64.9%)
File4.cpp   : 1515 of 3120 lines executed (48.6%)
File5.cpp   : 938 of 2664 lines executed (35.2%)
File6.cpp   : 25 of 27 lines executed (92.6%)
File7.cpp   : 61 of 64 lines executed (95.3%)
main.cpp    : 88 of 89 lines executed (98.9%)
Total 3462 of 7296 lines executed (47.5%)
« Last Edit: March 22, 2011, 01:09:43 pm by ewww »

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #7 on: March 22, 2011, 01:09:33 pm »
Update

* Added menu item to run gcov on all projects in a workspace
* The previous version was using internal cbGcov parser to provide per file executed/total lines stats. That apparently is imprecise and may differ a lot from what gcov prints. Now the plugin is capturing the gcov process output instead.
* Parallel processing. Uses same setting as parallel compiler in the standard cb settings dialog. This gives only a minor improvement, since gcov is limited by I/O, not cpu load. E.g. on a 2 core machine i have got best results by setting process count to 16. Results may vary depending on number of cores and max count of files per project.

Still I've got a couple of related questions.

First, I am using cb in command line mode to build my workspace. I would find it very useful to run coverage the same way. Is it possible to invoke a non-compiler plugin from command line?
Also, if anyone has got a good idea how to display the more detailed statistics in cb editor windows, you are welcome to share the knowledge :) More specifically I am talking about branch and call stats. Adding those next to line call count isn't that pretty at all, dont you think?
« Last Edit: March 25, 2011, 03:32:26 pm by ewww »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5016
Re: Gcov
« Reply #8 on: March 22, 2011, 01:29:50 pm »
I once issued as a post build step of my project/target the launching of a plug-in (Cppcheck plug-in).
It worked, but there some issues with the active project. Should retrieve my old laptop from underneath its pile of dust, and check how I did it...
Will try to do so this evening ;-)

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #9 on: March 22, 2011, 01:39:53 pm »
Hmmmm... Post-build will not do in this case. You have to run the target first, potentially multiple times, to generate the coverage data first. I can always make a stand alone binary which is parsing a full compiler command line output to perform this step, but still running all from within cb would be a more integrated solution ;)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9415
Re: Gcov
« Reply #10 on: March 24, 2011, 05:30:27 pm »
...found a bug (which crashes C::B):
If you have a virtual target active, this line:
Code: [Select]
wxFileName objname(prj->GetBuildTarget(prj->GetActiveBuildTarget())->GetObjectOutput() + sep + prjfile->GetObjName());
...in void cbGcov::GcovProject(cbProject* prj) will crash C::B because prj->GetBuildTarget(prj->GetActiveBuildTarget()) will be a NULL pointer. You cannot rely on obtaining a valid build target always, so you need to verify this.

Edit: Also, in the same method I see two more crash candidates:
Accessing a project pointer without verification:
Code: [Select]
void cbGcov::GcovProject(cbProject* prj)
{
  m_JobsWorkingdir = prj->GetBasePath();
...accessing a project file pointer without verification:
Code: [Select]
   ProjectFile *prjfile = prj->GetFile(k);
    if(prjfile->compile)

Be careful! Always verify what you get.
« Last Edit: March 24, 2011, 05:35:53 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 198
Re: Gcov
« Reply #11 on: March 24, 2011, 11:13:06 pm »
... anyone has got a good idea how to display the more detailed statistics in cb editor windows, you are welcome to share the knowledge :) More specifically I am talking about branch and call stats. Adding those next to line call count isn't that pretty at all, dont you think?
Does nobody have an idea? Perhaps it is not suitable to show in the editor (http://ggcov.sourceforge.net/ has some additional views).
« Last Edit: March 24, 2011, 11:18:32 pm by danselmi »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10277
Re: Gcov
« Reply #12 on: March 24, 2011, 11:32:15 pm »
« Last Edit: March 24, 2011, 11:33:46 pm by oBFusCATed »
<debugger plugin maintainer>
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #13 on: March 25, 2011, 03:31:52 pm »
Hi

One more update, possibly a final one :)

* Checking more pointers for validity, as suggested.
* Clean project/workspace removes the corresponding .gcno .gcda files
* When running cbGcov on workspace, after each project is finished the open editor windows are updated for that project

Known limitation: Newly opening an editor window will update it with gcov info only if it is a part of the currently active project. This should not be a problem, if I could get cbProject* in cbGcov::OnEditorOpen()
Code: [Select]
void cbGcov::OnEditorOpen(CodeBlocksEvent &event)
{
  EditorBase * eb = event.GetEditor();
  cbProject* prj = event.GetProject();  // this is always null?
  if(!eb || !eb->IsBuiltinEditor())
  {
    return;
  }

  cbEditor *ed = Manager::Get()->GetEditorManager()->GetBuiltinEditor(eb);
  if(!ed)
  {
    return;
  }
  if (!prj && ed->GetProjectFile())  // ed->GetProjectFile() always NULL too?
  {
    prj = ed->GetProjectFile()->GetParentProject(); 
  }

  ShowCovData(ed,prj);
}

I am unable to get the cbProject out of the event even when the file opened does belong to a project. How can I do that?

Or... should I really build the proper SDK? ;)
« Last Edit: March 25, 2011, 03:35:37 pm by ewww »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9415
Re: Gcov
« Reply #14 on: March 26, 2011, 10:07:19 am »
One more update, possibly a final one :)
not really, unfortunately. The crash remains as you did only half the way.
This line:
Code: [Select]
wxString objOutput = prj->GetBuildTarget(prj->GetActiveBuildTarget())->GetObjectOutput();...in void cbGcov::CleanProject(cbProject* prj) will still crash if you have activated a virtual target.
You also need to verify the return value of:
Code: [Select]
prj->GetBuildTarget(prj->GetActiveBuildTarget())...as I had written btw..
The idea is good, but I really think this plugin needs way more testing. I was my #1 crash candidate the last couple of days even I did no use it. :?

...also, this: _(".gcda") makes no sense. You don't want to translate the file extension, don't you? use _T() or wxT() instead for strings you don't want to translate... but that's only minor.
« Last Edit: March 26, 2011, 10:08:59 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #15 on: March 27, 2011, 03:23:08 pm »
Quote
not really, unfortunately. The crash remains as you did only half the way.
Yes, you are right, i didnt pay attention and missed your point on which pointer to check there. However, when saying this may be the last update, I meant that at least until now I was doing this plugin for my own purposes and right now it delivers just what I need :)

I fully agree that at this stage it is not properly tested to be "production ready" or so. This is a small plugin and it did not seem to catch much attention here on the forum, so I figured, it is usable enough to be worth hanging as an attachment on this thread :)

I do not know how you generally handle contrib plugins, but sure I would be interested in doing some more work on it, if you think it could be made a part a release package, or so. Let me make another revision some time next week with proper error checking so it at least does not crash the host. Thing is, it does it's direct job perfectly well for me on my machine and my build configuration :) Checking for special cases is a bit difficult in such a scenario, especially that I am not aware of many cb specifics, e.g. no idea virtual targets existed, etc :)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5016
Re: Gcov
« Reply #16 on: March 27, 2011, 03:26:35 pm »
this plug-in sounds nice, and might become a contrib plugin.
How should you structure it, well just have a look at some other contrib plug-ins.
Valgrind, ....

Offline ewww

  • Multiple posting newcomer
  • *
  • Posts: 15
Re: Gcov
« Reply #17 on: March 31, 2011, 10:50:44 am »
I have cleaned up the project a bit. Added doxy comments, more appropriate checks for null pointers. That should make the code more reusable and stable. Hope someone actually makes use of it :)
« Last Edit: March 31, 2011, 11:00:17 am by ewww »

boshuizw

  • Guest
Re: Gcov
« Reply #18 on: May 26, 2011, 12:30:28 am »
Hi all, I'd like to use the plug in for code coverage on some of my Code::Blocks projects, however I'm getting the following error when I tried to download and run the plug in project file.

error: bad value (core2) for -march= switch
error: bad value (core2) for -mtune= switch

I'm assuming this could have a work around in the project build options, but I've been unable to find a workable solution.  Does anyone have any insights to this error.

Thank you

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9415
Re: Gcov
« Reply #19 on: May 26, 2011, 06:14:58 am »
I'm assuming this could have a work around in the project build options, but I've been unable to find a workable solution.  Does anyone have any insights to this error.
Check the compiler options and disable this switch. Most likely you are using a very old compiler that does not support that options or a branched compiler suite.

Next time please provide more information about your platform, version (C::B/compiler) etc. you are using. Otherwise it's hard to tell. Also see my sig on how to troubleshoot a compiler issue...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 198
Re: Gcov
« Reply #20 on: October 21, 2015, 12:04:52 am »
I recently worked on this plugin.

It has its own repo now:
https://github.com/danselmi/cbGcov

But now I am stuck with one problem:
The summary report should span over the whole panel, but it stayes small (see attachment) until the panel gets resized or the panel becomes active again. Probably i made a mistake with the sizer related settings.

Any help is welcome.

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 198
Re: Gcov
« Reply #21 on: October 07, 2017, 11:24:58 pm »
So, I found some time to work on this.

Summary table spans the whole panel.
Editor showing call statistics and annotated branch and call infos.
made nicer looking icons.

repo is still here: https://github.com/danselmi/cbGcov

We use it regularly at work, it is stable and usefull.

Regards, danselmi