Good way to log performance (C #)

I am trying to get detailed performance information from an application that my company is developing. Examples of the information I'm trying to get will be how long the network transaction takes, how much processor / memory the application is using, how long it takes to complete this method, etc.

In the past, I have had unsuccessful attempts (for example, trying to measure small periods of time using DateTime.Now). Also, I don't know anything about getting processor and memory statistics. Are there any good .Net classes, libraries, or frameworks that can help me collect this information and / or write it to a text file?

+4
source share
3 answers

What you are looking for are performance counters . For .net you need this performance counter .

+7
source

Performance counters are one way, and the System.Diagnostics.Stopwatch class is a good base place to look for this.

With performance counters (other than those provided), you need to manage both the event tracking infrastructure and report data. The base classes of the performance counter provide connection details for connecting to the event log, but you need to provide a different reporting infrastructure if you need to report data in another way (for example, to a log file or database).

A stopwatch is a wrapper around a high-performance timer that gives you permission to microsecond or nanosecond depending on the processor or platform. If you don’t need such a high resolution, you can use System.DateTime..Now.Ticks to get the current hour counter for the processor clock and do the differential math with this, giving you a millisecond or bet accuracy for most operations.

When tracking CPU statistics, remember that in some cases multiple processors and multiple cores will complicate any accurate statistics.

Last warning with performance counters, remember that not all performance counters are on all machines. For example, ASP.NET counters are not available on a computer on which IIS is not installed, etc.

0
source

For processor / memory performance counters. For more specific information about specific methods (or lines of code) and specific objects, use the profiler. red-gate makes an excellent profiler.

http://www.red-gate.com/products/ants_performance_profiler

0
source

All Articles