Sometimes when I examine a code I didn’t write, I launch eclipse in debug mode and use figures to understand a program. For example, if they are n items retrieved from the DB, it can be interesting to know that there’re n processed items in a service, etc.
When loops are used, things get more complicated: if we’re in a “while” loop, the number of execution is not defined and if there are alternatives, the flow of execution can greatly change.
For this purpose, I sometimes set a breakpoint in a portion of code and count how many times we reach it.
Of course, it’s not very convenient and I wonder if there is a way to count the number of breakpoint hits. I know that Eclipse can suspend execution after a fixed number of hits but I just want Eclipse to count them in a normal flow of execution.
I’d be glad to hear your opinions about it.
Thanks!
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
When a programmer creates code they can add what is known as a breakpoint. A breakpoint is a point in the program where the code will stop executing. For example, if the programmer amended the logic error in the trace table example they may wish to trigger a break point at line 5 in the algorithm.
Managing breakpoints using the Breakpoints window Visual Studio provides a straightforward way to manage all your breakpoints under a single toolbox window, which you can find by navigating to Debug | Windows | Breakpoints (keyboard shortcut: Ctrl + D + B).
You can add a condition into your breakpoint. The simplest one could look something like this:
System.err.println("Passing checkpoint"); return false;
You can also extend it by calling your own static class:
org.foo.StaticCounter.COUNTER++; System.err.println("Passing checkpoint " + org.foo.StaticCounter.COUNTER); return false;
As an alternative to counting breakpoints, you could use a profiling tool, such as the one here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With