Reputation: 673
I need to count the number of times a given line of code is hit during execution. I want to use it via debugging tool on my IDE and not a code or performance tool solution.
I am already using YourKit to profile the project, and do not want number of line calls via this tool.
I also do not want to count hits using code (with System.out.print and a variable) because I will be checking the procedure at different branches.
I already checked IntelliJ IDEA help.
Also checked both this posts: Debugging and counting breakpoint hits Counting breakpoint hits
But none of them replies to what I am looking for.
I am currently using IntelliJ's breakpoint options: Log to console
.
The way I am using the breakpoint option in IntelliJ I get a log message every time the breakpoint is hit, and then I have to count the number of messages.
I would like to get an actual number of hits so I do not have to count messages.
If anyone knows a simple direct solution to achieving this via IntelliJ I really appreciate. Thanks in advance.
Upvotes: 11
Views: 5623
Reputation: 4675
Like ABika said, enabling the debugger pane Overhead view ...
... lets you see the hit counts for your breakpoints.
However, in scenarios like this it can often be useful to set breakpoints to be non-stopping if they are merely intended for counting. Simply right-click a breakpoint or select it in the Breakpoints list and remove the tick mark next to Suspend:
This makes the breakpoint turn yellow:
Then you can run your code in debug mode without having to stop even a single time unless you want to.
Unlike the Variables or Frames views, the Overhead view remains available even after debugging has ended:
This can be a real lifesaver if a breakpoint can get hit hundreds or thousands of times. The configurable breakpoint conditions and filters can also be extremely useful in such scenarios.
Upvotes: 2
Reputation: 677
The Overhead tab in the Debugger view has a "Hits" column. You don't even have to have Suspend or Log to Console being enabled for the breakpoint to be counted. See the help page Monitor debugger overhead.
Upvotes: 13
Reputation: 1599
The approach of DaSqy Stc is good, but it doesn't work when there are other log messages are printed or if you want to track multiple breakpoints individually.
Solution is to keep the option "log to console" on and click inside the console, press [Ctrl]+[F] and search after "Breakpoint reached at RemoveFromList.remove(RemoveFromList.java:38)" and it says 1/6. The right number is the one you want.
Upvotes: 1