Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 224 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Good way to do performance logging (C#)

#1
I am trying to get some detailed performance information from an application my company is developing. Examples of information I am trying to get would be how long a network transaction takes, how much CPU/memory the application is using, how long it takes for a given method to complete, etc.

I have had some failed attempts at this in the past (like trying to measure small time periods by using DateTime.Now). On top of that I don't know much of anything about getting CPU and memory statistics. Are there any good .Net classes, libraries, or frameworks out there that would help me collect this sort of information and/or log it to a text file?
Reply

#2
What you are looking for is [Performance Counters][1]. For .net you need [this Performance Counter][2].


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
For cpu/memory use performance counters. For more specific information about specific methods (or lines of code) and specific objects, use a profiler. red-gate makes a great profiler.

[To see links please register here]

Reply

#4
Performance counters are one way to go, and the System.Diagnostics.Stopwatch class are good foundational places to look for doing this.

With performance counters (beyond those provided) you will need to manage both the infrastructure of tracking the events, as well as reporting the data. The performance counter base classes supply the connection details for hooking up to the event log, but you will need to provide other reporting infrastructure if you need to report the data in another way (such as to a log file, or database).

The stopwatch class is a wrapper around the high performance timer, giving you microsecond or nanosecond resolution depending on the processor or the platform. If you do not need that high of resolution you can use System.DateTime..Now.Ticks to get the current tick count for the processor clock and do differential math with that, giving you millisecond or bettter precision for most operations.

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

One last caution with performance counters, be aware that not all performance counters are on all machines. For instance ASP.NET counters are not present on a machine which does not have IIS installed, etc.
Reply

#5
for a modern opensource library to do performance metrics and monitoring consider using app-metrics.

github:

[To see links please register here]

website

[To see links please register here]

Reply

#6
A platform independent open source performance recorder build on top of [aspect injector][1] can be found here:

[To see links please register here]

. It can be added to any C# project. Instructions on how to use can be found in the README in Gitlab.

## Benefits

- It's aspect oriented, meaning you don't have to litter your code with DateTime.Now - you just annotate the appropriate methods
- It takes care of pretty printing the results - you can do with the what you like e.g. printing them to a file

## Notes

- This performance recorder is focused on the timing of methods only. It doesn't cover CPU or memory usage.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through