问题描述
有时,当我检查一个没有写的代码时,我会在调试模式下启动eclipse并使用数字来理解一个程序。例如,如果它们是从数据库中检索到的n个项目,那么知道服务中有n个已处理的项目可以很有趣。
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.
当循环是使用,事情变得更复杂:如果我们处于while循环,执行次数没有定义,如果有替代,执行流程可以大大改变。
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.
当然不是很方便,我想知道是否有一种计算断点命中次数的方法。我知道Eclipse可以在固定的点击次数后暂停执行,但是我只是希望Eclipse以正常的执行流程来计数。
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.
谢谢!
推荐答案
您可以添加一个条件进入你的断点。最简单的可能是这样的:
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;
这篇关于调试和计数断点命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!