简体   繁体   English

是否有Java代码覆盖工具记录调用行和方法的次数?

[英]Is there a Java code coverage tool that records the number of times lines and methods are called?

Hopefully the title describes what I'm after. 希望标题描述我追求的东西。 The closest I've found is Cobertura which looks like it will record the number of times a given line of code is called, but I haven't found anything at all to count how often a method is called. 我发现的最接近的是Cobertura ,它看起来会记录调用给定代码行的次数,但我还没有找到任何可以计算调用方法的频率。

如果您使用像eclipse这样的IDE,可以使用插件查看: - http://www.eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html

我已经使用Eclipse 测试和性能工具平台项目获得了良好的结果 - 它不仅会告诉您调用方法的次数,还会测量每个方法执行的时间,以便您可以使用if进行性能调整。

VisualVM (included with Sun/Oracle JDK) can do that for you. VisualVM (包含在Sun / Oracle JDK中)可以为您完成。

From CPU Profiling section of the Profiling Applications document : 从“ 概要分析应用程序”文档的“ CPU概要分析”部分:

This profile command returns detailed data on method-level CPU performance (execution time), showing the total execution time and number of invocations for each method. 此profile命令返回有关方法级CPU性能(执行时间)的详细数据,显示每个方法的总执行时间和调用次数。

如果代码持续运行,您可以始终只实现一个静态变量并自行计算。

Our Java (Counting) Profiler comes pretty close to exactly what OP wants. 我们的Java(Counting)Profiler非常接近OP想要的。

It counts entries into every basic block in the Java code; 它将条目计入Java代码中的每个基本块; this includes method entry points and any subsidiary blocks to control statements (if, while, try, ...). 这包括方法入口点和控制语句的任何子块(if,while,try,...)。 This achieves the same effective result as count executions of individual "lines" (not sure what that means exactly in a Java program but we'll let that go) with considerably lower overhead. 这实现了与单个“行”的计数执行相同的有效结果(不确定这在Java程序中是什么意思,但我们会放弃),而且开销要低得多。

The count data can be treated like coverage data; 计数数据可以像覆盖数据一样处理; nonzero means "covered". 非零意味着“覆盖”。

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

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