Is PostSharp a good way to profile code running in production?
I would like to run profiling code against some services running in testing and production. My plan is to use PostSharp to implement a class that looks like
public class TimerAttribute : OnMethodBoundaryAspect
{
//some data members
//...
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
//write method entry time to file
}
public override void OnExit(MethodExecutionEventArgs eventArgs)
{
//write method exit time to file
}
}
Before I go too far, are there any potential pitfalls I should开发者_如何学Go be aware of? Will widespread use (i.e. just adding a line to assemblyinfo) of these methods cause serious (in terms of the validity of the timing data) performance issues?
For performance instrumentation, you should be aware of the overhead of the aspect. This overhead was important in previous versions of PostSharp, but has been greatly improved in PostSharp 2.0.
Regarding your code, I see the danger is that writing to the file may be slow and thread unsafe. It really depends on your context and objectives, of course.
Performance counters may be a good alternative.
精彩评论