Tracking performance in C #
I would like to track the performance in a c # mobile app to find out the amount of time it takes for some lengthy methods. The goal is to find out performance at the method level. This trace will be resolved at runtime.
The first idea is to maintain a global doWeHaveToTrace variable, check it every time a potentially tracked method is called, and track it if this variable is true. And in that case, I would probably use a Logger or TraceListener to write the trace information to a file.
But I think this mechanism is quite heavy, because the variable must be checked in every method, and the logger calls must be encoded.
I also thought about programming aspects (insert tracing code into methods before()
and after()
), but I don't think programming aspects can be allowed inside this project.
So I was wondering if there are other good mechanisms that could provide this kind of performance tracking? Can the whole method be traced? And decide to stop or resume tracking at runtime?
source to share
Not sure what exactly you are trying to track, but if you are trying to track the time between lengthy methods, you might be better off connecting to the .NET Profiling API . Here is a tutorial on how to use it.
The commercial profiler would be another, simpler option.
source to share
Read about how to conditionally compile with Trace and Debug in .NET (assuming you are using .NET). The Trace and Debug classes will give you all the runtime output you need for development purposes. Then you can remove all your debug / trace code (and the associated runtime overhead) in your deployed application by simply removing the TRACE compiler directives.
OR
You can use an external profiling application to perform performance and memory profiling. See here (from the Stack Overflow site): What Are Good .NET Profilers?
source to share