In our VB6 applications, we added a few utility functions for tracking the amount of time spent in a function. We did this to track performance bottlenecks.
Basically, how it worked was there were two utility functions: StartTickCount() and EndTickCount(). You would pass the name of the function in each, and the functions would use a dictionary to get the tick count when StartTickCount() was called, and then subtract the tick count when EndTickCount() was called. This wasn't perfect because it didn't of course take into consideration that calls to get tick count takes time, etc, but basically it worked for our purposes. The pain in the butt part was making sure to call StartTickCount() at the beginning of each function and EndTickCount() at each exit point:
Private Function SomeFuction() as String
' indicate the function started
StartTickCount("MyClass.SomeFunction")
' some logic that causes the function to end
If (some logic) Then
EndTickCount("MyClass.SomeFunction")
Return "Hello!"
End If
' final exit point
EndTickCount("MyClass.SomeFunction")
Return "World"
End Function
Anyway, is there any functionality built in, either through the VS 2010 debugger or in the System.Reflection
namespace, to do something similar in VB.NET?
Basically, what I want is to log the number of times each function is called, the total amount to time spent in that function, the average number of seconds spent in that function, and the maximum amount of time spent in a single call in that function.
I can certainly write this by hand (since we already did once in VB6), but if there are existing tools to make it easier, I'd rather use them.
I'd have a look at the stopwatch class - it's designed for this type of thing.
However there is also a fantastic tool out there to do this already and it actually does a better job with very little work. It has a 10-day free trial as well.
http://www.jetbrains.com/profiler/
(I don't work for and am not affiliated with jetbrains - but I wish I was because they make some really cool products)