查找Java中每个语句的执行计数

发布于 2024-08-04 04:16:15 字数 268 浏览 2 评论 0原文

我正在学习 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 技术交流群。

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

发布评论

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

评论(2

淡笑忘祈一世凡恋 2024-08-11 04:16:15

我非常确定一些不同的代码覆盖率工具(例如 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

  • Emma open source, but doesn't seem to actually record statement counts
  • Clover commercial coverage tool certainly does
  • Cobertura Newer open source tool than emma and does record statement counts
月亮坠入山谷 2024-08-11 04:16:15

您可能想知道语句的调用计数,但这与应该修复哪些内容以获得更好的性能只有相当间接的关系。 这是我与语言无关的方法使用,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.

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