Search code examples
performanceprofilingcode-coverageinstrumentationopencover

How to improve OpenCover performance when I need only basic coverage data?


I need to run OpenCover against a battery of 1000+ tests. I am interested only in:

  • % of lines covered
  • Which lines are covered and which are not

I don't need:

  • Visit count
  • Number of CPU cycles / real execution time
  • Any performance report

From the documentation I can see that could use some parameters to tweak performance:

  • -log:Off
  • -mergebyhash
  • -skipautoprops
  • -threshold:1
  • -excludebyattribute:???
  • -hideskipped:All
  • -oldstyle

However since the documentation is not clear on how these attributes affect performance, I am currently following a trial and error approach, which can literally take days to execute since I have literally hundreds of tests to run, so any information would be highly appreciated.


Solution

  • -threshold:1 will have some effect as it reduces the data sent to the host however the 'injection' points will still be executed - once instrumented the code is not uninstrumented during the profile run.

    -oldstyle will also have some effect as it uses less IL per sequence point but it does not always work correctly due to security issues - YMMV

    -skipautoprops disables instrumentation of auto properties if you don't care about property usage e.g.

    public string Name { get; set;)
    

    If code is excluded either by filter or by attribute then the excluded code is not instrumented and will run at normal speed so you may find that excluding hotspots (heavily visited methods) and excluding any assemblies/type you don't care about may help the performance of your tests.

    The other parameters you've indicated -mergebyhash and -hideskipped:All affect the XML output.