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.
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.
Scroll to the end, and watch the line number
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.
Related
it happens to me many times: I'm stepping with the debugger through my code, and ups! i made one step too far! Debugging, and made one step over too far
what now? restart the whole debugging session?
actually, there is a way to go ‘backwards’
The feature is called 'Drop to frame' right click on any line in stack, choose 'Drop to frame' and you go back to selected method beginning
https://help.eclipse.org/2021-03/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/views/debug/ref-droptoframe.htm
You can only jump to the start of the current function . Please keep that in mind.
I have had a problem with a custom component I am writing. The issue seems to be a resource not loading properly (not sure why) at design-time.
To track it down I'd like to put in some debug-code that will execute at design-time, and give output in form of some messages.
Is there a log or something similar that can be written to at design-time?
Thanks
There's a really nice trick you can use to add debug statements in IntelliJ without actually changing the code. The answer is to use non-suspending breakpoints.
Add a breakpoint at the necessary point in the code, then right click on it. De-select "Suspend", and then put whatever you want in the "Log evaluated expression" - this will give you access to the fields of the instance.
Run your app in debug mode, and you'll get debugging info in the console without having to manually examine everything.
Many times I came into situation while debugging in Eclipse that I Don't Know where to put break point! For example, I just need to know when a client make a request to server which method it hits for this request. As I don't know where it will hit , I can't put a break point.
Can anybody suggest this if this conditional break point functionality available in Eclipse or any plugin? Or any other solution?
At the moment I've been using logging to keep a track of my continuously changing values within an update loop. Problem is is that this can be time consuming.
I can use the debugger but it stops code executing and due to what I'm doing causes weird results and false values.
Does anyone know if it's possible to "watch" the variables while keeping the code running. Like having one watch within a scope.
Android Studio/IntelliJ have some really nice features in breakpoints that let the IDE take an action when it hits a breakpoint instead of just dropping your app into the debugger (which it can of course also do). On any given breakpoint, there's a checkbox in the options that controls whether it will actually suspend your app and drop it into the debugger; you can turn that on or off independently. You can have it log a message to the debugger console, or have it evaluate any expression and log the results to the console.
I find these options super-handy; it's the equivalent of adding debug logging to your code, but you can add and change it on the fly without modifying your code and doing a rebuild-restart cycle.
There's also some really powerful filtering that will selectively control whether or not the breakpoint is triggered based on certain criteria; you can even set up cascades of breakpoints where one doesn't fire until a previous one is hit.
Experiment with some of the options.
Is there any way to programmatically set breakpoints in Java?
Assume you have the filename with the source code line:
Test.java:123
How this can be done?
The Eclipse IDE does not allow you to set a breakpoint from your java code.
However, it does allow you to set conditional breakpoints. With a conditional breakpoint, you can tell Eclipse to only break on a line after some Java expression evaluates to true. You can only tell it to break after some number of iterations. These modes should suffice for almost every usecase.
To enable a conditional breakpoint, right-click on a breakpoint and go to "Breakpoint properties".
Back in the days of VisualAge Jave, I did this with
DebugSupport.halt()
This is something that would have to be supported by the IDE, and would break if the IDE dependencies were not present. As fas I know there are no IDEs today that support this.
I had the same problem but with 10000 files of java which i wanted to search for some string and put breakpoints based on that search.
You can generate xml file containing all breakpoints you need.
How to get that xml file structure?? simply go to debug mode --> right click ->Export breakpoints->then save the file anywhere.open that file and see how it is constructed.
what i did that i searched all the files line by line and generated that xml file and imported it to eclipse.
-You may wonder that how you can loop through 10000 file line by line as it will take a lot of time,you are right but what i did to overcome this is by inserting all lines into indexed field on mysql db.
-I know your case is not that complex but i hope it gives you an idea.you may come with something even better.
Most debuggers will let you break on an exception, so just create your own BreakpointException class, throw and immediately catch it. Have the debugger pause only on BreakpointException.