Debugging and counting breakpoint hits

穿精又带淫゛_ 提交于 2019-11-30 07:52:04

问题


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!


回答1:


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;



回答2:


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



来源:https://stackoverflow.com/questions/9252597/debugging-and-counting-breakpoint-hits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!