Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging and counting breakpoint hits

Tags:

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!

like image 692
Guillaume Gallois Avatar asked Feb 12 '12 20:02

Guillaume Gallois


People also ask

How do you Debug a breakpoint?

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.

What is a breakpoint in coding?

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.

How do I view breakpoints in Visual Studio?

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).


2 Answers

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; 
like image 96
Eugene Kuleshov Avatar answered Oct 11 '22 15:10

Eugene Kuleshov


As an alternative to counting breakpoints, you could use a profiling tool, such as the one here.

like image 20
highlycaffeinated Avatar answered Oct 11 '22 15:10

highlycaffeinated