简体   繁体   English

在运行时监视java类以监视性能 - >有没有一个工具已经这样做了?

[英]Instrument java classes at runtime to monitor performance --> is there a tool that already does this?

I've been looking at various java performance monitoring tools. 我一直在寻找各种java性能监控工具。

I worked out a solution that uses perf4j + aspectj, so that I can define which classes to monitor with an aspectj pointcut expression. 我制定了一个使用perf4j + aspectj的解决方案,以便我可以使用aspectj切入点表达式定义要监视的类。 However aspectj also (AFAIK), does not allow you to change the pointcut expression at runtime. 但是,aspectj(AFAIK)也不允许您在运行时更改切入点表达式。 So if I need to monitor new classes I would have to change the aop.xml and recompile (or atleast restart the app if using AspectJ load time weaving). 因此,如果我需要监视新类,我将不得不更改aop.xml并重新编译(或者如果使用AspectJ加载时编织,则至少重新启动应用程序)。

I have not found anything so far that can instrument classes at runtime without needing a restart of the application. 到目前为止,我还没有发现可以在运行时检测类而无需重新启动应用程序的任何内容。 Is there a tool/technology out there which can do that? 是否有工具/技术可以做到这一点?

These types of tools typically don't instrument classes at runtime. 这些类型的工具通常不会在运行时检测类。 Instead they use the JVMTI interface (if you don't understand what this is, google it). 相反,他们使用JVMTI接口(如果你不明白这是什么,谷歌吧)。

Prime examples of products that use it: 使用它的产品的主要示例:

Yourkit, JProfiler Yourkit,JProfiler

There's a few open source tools, but I haven't really found any of them to be nearly as polished as their commercial counterparts. 有一些开源工具,但我还没有发现它们中的任何一个几乎和它们的商业对应物一样精致。

Found a perfect little library BTrace , which does exactly what I needed. 找到了一个完美的小图书馆BTrace ,它完全符合我的需要。 It works by manipulating the byte code of the instrumented class at runtime, no need to restart your application. 它的工作原理是在运行时操作已检测类的字节代码,无需重新启动应用程序。 Check out the user guide to see how easy it is to set it up. 查看用户指南 ,了解设置它是多么容易。

Another thing worth mentioning about Btrace is that, the authors have made a lot effort to make it safe to work in a production environment. 另外值得一提的是Btrace,作者已经做了很多努力,使其在生产环境中安全工作。

To guarantee that the tracing actions are "read-only" (ie, the trace actions don't change the state of the program traced) and bounded (ie, trace actions terminate in bounded time), a BTrace program is allowed to do only a restricted set of actions. 为了保证跟踪操作是“只读”(即跟踪操作不会改变跟踪的程序状态)和有界(即跟踪操作在有限时间内终止),BTrace程序只允许执行一组有限的行动。

I suggest using Eclipse's (or NetBeans) debugger/profiler. 我建议使用Eclipse(或NetBeans)调试器/分析器。
It is very powerful. 它非常强大。

There is also an entire project dedicated to these tools: 还有一个专门用于这些工具的整个项目:
http://www.eclipse.org/projects/project.php?id=tptp.performance http://www.eclipse.org/projects/project.php?id=tptp.performance

and some interesting plugins: 和一些有趣的插件:
http://code.google.com/a/eclipselabs.org/p/jvmmonitor/ http://code.google.com/a/eclipselabs.org/p/jvmmonitor/

As Matt said, YouKit Java Profiler can instrument Java byte-code. 正如Matt所说, YouKit Java Profiler可以使用Java字节码。 YourKit allows to write own probes and insert them into the running Java apps. YourKit允许编写自己的探针并将它们插入到正在运行的Java应用程序中。 Probe API allows to access method parameters, return values, catch exceptions, etc. Probe API允许访问方法参数,返回值,捕获异常等。

The docs is here: http://www.yourkit.com/docs/11/help/probes.jsp 文档在这里: http//www.yourkit.com/docs/11/help/probes.jsp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM