开发者

Is PostSharp a good way to profile code running in production?

开发者 https://www.devze.com 2022-12-17 00:00 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号