Get the time spent waiting on breakpoints in a debugger


Get the time spent waiting on breakpoints in a debugger



Background



Suppose I have a metaphorical patient whose heart beats once per second, and every second, I check whether his last heartbeat was more than five seconds late (and, if so, declare him to be in danger):


let lastHeartbeat = Date.now();
// Heartbeater
setInterval(() => lastHeartbeat = Date.now(), 1000);

// Health-checker
setInterval(
() => {
if((Date.now() - lastHeartbeat) > 5000){
alert("Patient has flatlined");
}
},
1000
);



Issue



If I use a debugger to pause the execution of this script at some point, I have a problem: if I remain on a breakpoint for more than five seconds, then, once script execution resumes, my health-checker function is certain to declare that the patient has flatlined.



Desired behaviour



Instead, I'd like to factor in the time spent in the debugger.



i.e., if I spend twenty seconds sitting on a breakpoint just after an initial heartbeat occurring, and the patient's heart beats again within just one second of releasing that breakpoint, then that patient should not be declared as flatlining.



Is there any way to subtract the time spent in the debugger from the health-check condition? e.g.:


if((Date.now() - lastHeartbeat - lastTimeSpentInDebugger) > 5000)



Note: I'm specifically running the JS in Node.js, rather than in a browser.





not sure how you would determine lastTimeSpentInDebugger
– epascarello
2 days ago





is this relevant? it is 6 years old :/
– MrPickles
2 days ago






@MrPickles This program will always be run in debug mode, so the presence of the v8debug global variable does not add any useful information (unless it has some properties on it, but I can't find any information that suggests that it does). We need to know when the debugger (which listens at all times) is paused on a breakpoint.
– Jamie Birch
2 days ago


v8debug









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV