How to determine which code in a project / solution is most often used?

If I have an existing solution containing several C # projects, are there any static analysis tools that can help me determine which areas of the code are most commonly used?

I would like to use this information to determine in which areas the test coverage should be covered.

I already looked at some static analysis tools, but they mostly seem to focus on things like complexity, coding conventions, code duplication, etc.

Alternatively, if there are no analysis tools available that can do this, do you have any tips on how to determine which code I should focus on testing first?

Thanks!

EDIT: Just to clarify what I'm looking for, this is not code coverage. I would like to describe what parts of my application are most often used, so I can in turn focus on improving coverage in these areas. I try to avoid just writing tests for areas that do not yet have them, as they can be edge cases that are not often run.

+6
c # visual-studio integration-testing testing
source share
7 answers

Even static analysis tools that try to figure out what happens at runtime usually don’t try to evaluate how often a piece of code is executed. The topic is quite complicated, as it is!

But dynamic analysis tools (such as profiling tools that either rely on transparent code verification or sample selection) can tell you after one or more "typical" executions (you specify entries that you think are typical), how often is or this function has been performed.

See Profiling (computer programming) on ​​Wikipedia .

+2
source share

If I understand the question correctly, you are looking for a profiler. Give EQATEC Profiler . It's free.

It was originally designed to profile the application before sending it (to detect bottlenecks by measuring the execution time of methods, etc.), so I'm not sure if it is suitable for the application in a productive environment. At the very least, it modifies your code for profiling purposes and may be undesirable. You have to check it out.

+2
source share

Code coverage is similar to what you want.

NCover is a popular .NET code coverage tool if you can afford it.

+1
source share

If you want to see only what is used: SD Shell C # Validation Tool

If you want to see how often it is used: SD C # profiling tool

+1
source share

What you are asking for is simply impossible to do for sure. The number of times that something executes can and will usually depend on the data entered at run time. The best you can hope for from a static analysis tool:

  1. direct response in static definition
  2. O (N) style analysis otherwise
Even the latter would be quite difficult to achieve success in general. For example, he will need to know the complexity of almost every function in the (huge and ever-expanding) .NET library. Some of them are difficult to even characterize.

How, for example, how long does it take to allocate a block of memory? Usually this is usually almost constant time, but it is always possible that the allocation can initiate a garbage collection cycle, in which case the time spent will be (approximately) proportional to the number of objects that are still in use that have been allocated since the last GC cycle ...

+1
source share

A "profiler" is what you are looking for; which one you choose is up to you.

I used the HP Diagnostic Server for this, although it would have cost money. He will tell me which methods are called how many times, and the average and worst time spent in them.

As an important safety tip, running a profiler will slow down your code; It is not ideal for long-term installation in a production environment.

+1
source share

If coverage is not what you are looking for, then you can use two things:

  • As suggested by the profiler and run predictive test scripts.
  • Use performance counters that end in a more permanent solution. They are quite difficult to implement, but they help diagnose the performance delta by analyzing the counters report. One way to implement them is to wrap borders and manage the counters from these wrappers. Be careful, as it is much easier to integrate into a new project than in an existing one.
0
source share

All Articles