PostSharp 是分析生产中运行的代码的好方法吗?

发布于 2024-08-18 22:25:27 字数 565 浏览 4 评论 0原文

我想针对测试和生产中运行的某些服务运行分析代码。我的计划是使用 PostSharp 实现一个看起来像的类

    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
        }
    }

在我走得太远之前,是否有我应该注意的潜在陷阱?这些方法的广泛使用(即仅在 assemblyinfo 中添加一行)是否会导致严重的(就计时数据的有效性而言)性能问题?

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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待"谢繁草 2024-08-25 22:25:27

对于性能检测,您应该了解方面的开销。这种开销在以前版本的 PostSharp 中很重要,但在 PostSharp 2.0 中得到了极大的改进。

关于您的代码,我认为危险在于写入文件可能很慢并且线程不安全。当然,这实际上取决于您的背景和目标。

性能计数器可能是一个不错的选择。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文