查找 Java 程序的实际运行时调用树
假设我有一个包含数百个方法的大程序。根据输入的性质,程序流程正在发生变化。
我想我想对原来的流程进行更改。找到调用层次结构/引用并理解流程是一件很大的麻烦。
我在 Eclipse 中对此有任何解决方案吗?或者插件?例如,我只需要一个按时间顺序排列的方法名称日志。然后我不需要担心与我的“给定输入”不相关的方法
更新:在 Eclipse 中使用调试模式或添加打印消息是不可行的。节目实在是太大了:)
Suppose I have a big program that consists of hundreds of methods in it. And according to the nature of input the program flow is getting changed.
Think I want to make a change to the original flow. And it is big hassle to find call hierarchy/ references and understand the flow.
Do I have any solution for this within Eclipse? Or a plugin? As an example, I just need a Log of method names that is in order of time. Then I don't need to worry about the methods that are not relevant with my "given input"
Update : Using debug mode in eclipse or adding print messages are not feasible. The program is sooooo big. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 AspectJ 来记录所有名为 的方法的名称无需更改您的原始程序。
请参阅跟踪例如。
You could use AspectJ to log the name of all methods called without changing your original program.
See tracing for instance.
如果您想知道的是调用了什么方法,而不是精确的顺序,那么您可以考虑使用测试覆盖率工具。这些工具对源代码进行检测,以不同粒度(仅方法调用,和/或由条件控制的每个代码块)收集“已执行”事实。
SD 测试覆盖率工具 就是一个可以执行此操作的工具。
它不会收集调用图,甚至不会收集调用顺序。
如果您想对仪器进行更多控制,可以考虑使用DMS Software Reengineering Toolkit。 DMS 将以自定义源到源控制的任意方式解析、转换和漂亮打印 Java 程序变换重写规则。将日志记录转换插入到每个方法的开始和退出中会很容易(事实上,这几乎正是 SD 测试覆盖率工具的工作原理)。给定原始的 Enter-X 和 Exit-X 数据,构建运行时调用树是一项简单的任务。
If all you want to know is what methods got called, rather than the precise order, you might consider using a test coverage tool. These tools instrument the source code to collect "this got executed" facts at various degrees of granularity (method call only, and/or every code block controlled by a conditional).
The SD Test Coverage Tool is a tool that will do this.
It won't collect the call graph or even the order of the calls.
If you want more control over the instrumentation, you can consider using the DMS Software Reengineering Toolkit. DMS will parse, transform, and prettyprint Java in arbitrary ways controlled by custom source-to-source program transformation rewrite rules. It would be easy to insert logging transformations into the start and exit of each method (and in fact this is almost exactly how the SD test coverage tool works). Given the raw enter-X and exit-X data, constructing the runtime call tree is a straightforward task.