PostSharp 是分析生产中运行的代码的好方法吗?
我想针对测试和生产中运行的某些服务运行分析代码。我的计划是使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于性能检测,您应该了解方面的开销。这种开销在以前版本的 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.