views:

623

answers:

3

Hi,

I would like to trace performance inside a c# mobile application, in order to know the amount of time needed by some long-running methods. The goal is to know the performance at the level of methods. This tracing would be decided at runtime.

First idea that came is to maintain a global variable "doWeHaveToTrace", to check it each time a potentialy tracable method is called, and trace it if that variable is true. And in this case, i probably would use a Logger or a TraceListener to write tracing infos into a file.

But i think this mechanism is quite heavy, because a variable has to be checked in each method, and the logger calls have to be coded.

I also thought about aspect programming (insert tracing code in before() and after() methods), but i don't think aspect programming could be allowed inside this project.

So i was wondering, is there any other good mechanisms that could provide such performance tracing ? Is it possible to trace a whole method ? And to decide to stop or resume tracing at runtime ?

I hope i was clear, Thanks

+1  A: 

Not sure exactly what you are trying to trace, but if you're trying to track time between long running methods, perhaps you'd be better off hooking into the .NET Profiling API. Here is a tutorial on usage.

A commerical profiler would be another, simpler option.

Reed Copsey
A: 

Read about how to Compile Conditionally with Trace and Debug in .NET (assuming you are using .NET). The Trace and Debug classes will provide you with all the run-time output you need for development purposes. Then you can remove all your debug/trace code (and the associated run-time overhead) in your deployed application simply by removing the TRACE compiler directives.

OR

You can use an external profiling application to do your performance and memory profiling. See here (from StackOverflow.com): What Are Some Good .NET Profilers?

Enjoy,

Robert C. Cartaino

Robert Cartaino
A: 

Can you just run it on a desktop machine, under an IDE, and do the usual things, like clocking it and/or sampling?

You're bound to find things that are taking time and could be speeded up.

Mike Dunlavey