查找Java中每个语句的执行计数
我正在学习 Bentley J. 的《更多编程珍珠》(Addison-Wesley,1988 年),但我无法找到任何 Java 工具/分析器来告诉我每个语句在实际中执行的次数,这一事实让我感到困惑。流程(参考:第一章素数查找算法优化)。我尝试过使用探查器,尝试过检测 API,但可能我看错了地方。你们能否拿出一些魔术/工具并为我指明正确的方向,或者我们无法在 Java 中执行此操作,因为每个语句可能无法完全形成一个机器指令,并且可能无法为每个语句保留计数可能或者它只是我们可以查看并处理的方法的 CPU 时间/调用计数。
I am studying More programming pearls (Addison-Wesley, 1988) by Bentley J. and am stumped by the fact that I am unable to find any tool/ profiler for Java that can tell me the number of times each statement in executed in an actual flow (reference: Prime Number Finding algorithm optimization in Chapter 1). I tried using profilers, tried instrumentation API but may be I am looking at the wrong place. Can you guys please pull out some magic trick/tool and point me in the right direction or is it that we just can't do this in Java since each statement may not form exactly one machine instruction and keeping a count per statement may not be possible OR its just a method's CPU time/call count that we can look at and work on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我非常确定一些不同的代码覆盖率工具(例如 emma 和 clover)会记录每个语句的执行次数,因为它会显示在报告中。
我猜测他们实际上在编译阶段重写了类文件以插入一些跟踪代码,不确定这是否适合您。
编辑:正如未知Cobertura 可用于记录语句执行计数
I'm pretty sure some of the various code coverage tools such as emma and clover record the number of times each statement is executed because it's displayed in the reports.
I'm guessing that they actually rewrite the class files during there compile phrase to insert some tracking code, not sure if this is suitable for you or not.
EDIT: As recomended by unknown Cobertura can be used to record statement execution counts
您可能想知道语句的调用计数,但这与应该修复哪些内容以获得更好的性能只有相当间接的关系。 这是我与语言无关的方法使用,Jon Bentley 认为它非常好。
You may want to know the invocation count of statements, but that has only a pretty indirect relationship to what should be fixed to get better performance. This is the language-agnostic method I use, and Jon Bentley has recognized it as pretty good.