I am about to endeavor on learning as much as I can about
tracing/profiling in the CLR.. and in my readings so far I have not
found a way to get time based performance metrics without being
intrusive to the codebase.
i.e. on a current winform system I am working with to optimize, I have
used the free .NET profiler to view the CLR garbage collection
lifecycles and call-graphs etc.. but that information didn't seem to
express as much of a high level view of performance as I needed.
So, I wanted to ask opinions on what I did in the end:
I went into the class for a form that had questionable performance, and
for each method in the class I added as the first call "long start =
DateTime.Now.Ticks;" and.. at the end of the method I added "long end =
DateTime.Now.Ticks;", followed by a tracing statement to write out the
difference in ticks so that I could calculate the cost for the routine.
Using reflection I grabbed the methodname from the currently executing
method. Using the tracing log I created from these statements, I was
able to import the data into a SQL table and generate cost charts,
conversions to seconds, etc.
The one major downside to this is that it requires modification of the
code base with the above statements. I am wondering, are there any sort
of events relating to the CLR that would notify you of entry to a method
and exiting of the method? If that were the case I could write a
seperate perf project for the purposes of tracing the code.
One major problem with the method I am using is the possible case of
multiple returns within the control flow. I then have to carefully read
the code and place the statements at each possible exit point.
Appreciate any input.
JP
Naveen - 28 Jan 2006 16:27 GMT
There are profiling API's. It is unmanaged and not part of the
framework. You can read more about this here.
http://blogs.msdn.com/davbr/default.aspx