gareth_bowles
gareth_bowles

Reputation: 21130

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.

Upvotes: 5

Views: 508

Answers (6)

Ira Baxter
Ira Baxter

Reputation: 95334

Our Java (Counting) Profiler comes pretty close to exactly what OP wants.

It counts entries into every basic block in the Java code; this includes method entry points and any subsidiary blocks to control statements (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.

The count data can be treated like coverage data; nonzero means "covered".

Upvotes: 0

Oleg Mikheev
Oleg Mikheev

Reputation: 17444

VisualVM (included with Sun/Oracle JDK) can do that for you.

From CPU Profiling section of the Profiling Applications document:

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.

Upvotes: 1

Justin Muller
Justin Muller

Reputation: 1303

What about EclEmma's Method Coverage Indicator

Upvotes: 1

mikera
mikera

Reputation: 106351

I've used the Eclipse Test & Performance Tools Platform Project with good results - it will not only tell you the number of times a method is called but also measure how long every method took to execute so that you can used if for performance tuning.

Upvotes: 1

everconfusedGuy
everconfusedGuy

Reputation: 2797

There are plugins available if you are using an IDE like eclipse Check this out :- http://www.eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html

Upvotes: 1

Dan675
Dan675

Reputation: 1767

If the code is running persistently, you could always just implement a static variable and count it yourself.

Upvotes: 0

Related Questions