Is it a good idea to use alert in C++ addon?

40 views
Skip to first unread message

liuyanghejerry

unread,
May 10, 2014, 12:02:28 PM5/10/14
to nod...@googlegroups.com
Hi all,

I'm currently writing a new addon via C++, which targets to find out busy loops in Node.js.

Sometimes we may write a busy loop in javascript, such as:

while (a > 1) {
// do something
}

a +1; // oops, never get here

Most of the time, easy to find. But there're some situation it is too tricky to find these points.

And since we're in the busy loop, any of the other javascript code can't happen.

To find these busy loops, my basic idea is to use profile. V8 provides a way to start a profile, and if we have a chance to start it, profile result will show where the busy loop is. But like I said, have no way to trigger anything inside javascript land when loop.

I had a little scratch here to show my mind. The basic idea is to catch a signal, like SIGINT, to fire an alarm and begin a profile. When the alarm is alert, stop that profile. Hotest code should be the code where busy loop is.

I'm not familiar with Linux programing neither with Node's kernel. So I'm wondering is it a good idea to use alert in C++ addon to have a profile?

--
Best Regards,
liuyanghejerry

Tomasz Janczuk

unread,
May 11, 2014, 12:12:24 AM5/11/14
to nod...@googlegroups.com
Check out https://github.com/tjanczuk/tripwire. It is a native addon that allow you to set a timeout on the execution of an event handler in Node.js. If the JavaScript code does not return control to the Node's event loop handler within a specified time, an exception will be generated that will break out from the unortunate piece of code (even if it is a `while(true);`). You can intercept that exception in the `uncaughtException` handler and proceed as desired. 
Reply all
Reply to author
Forward
0 new messages