5

I have a very cpu-intensive application. I wonder if it's possible to get the current stack trace in order to understand, via SIGINT termination, for example, in which specific function is the current computation.

I tried adding the following handler:

process.on('SIGINT', function() {
    log('SIGINT!')
    var stack = new Error().stack;
    log( stack );
    log('quitting.');
    process.exit();
});

but it seems that it's called only when the intensive computation is ended and not immediately as I press Ctrl-C.

any idea on how to follow the execution without polluting the code with log messages?

2 Answers 2

1

The --trace-sigint option was initially introduced in nodejs/node#290207. It was reviewed & subsequently merged into Node's main release channel in May 2020 as part of the v12.17.0 release.

When this option is passed to the node runtime, any SIGINT (CTRL-C in most environments) will not only end execution of the script, but also print a stack trace.

Sign up to request clarification or add additional context in comments.

Comments

0

I do not have a specific answer for your issue but I would look for synchronous code (like fs.*Sync)

I suggest node-inspector (https://github.com/node-inspector/node-inspector) which allow to get a clue of what is happening either with step by step in the code and some reporting about resources usage

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.