Node.js Profile Processing Taking Forever

Posted on .

I was doing some Node.js V8 profiling work at the office near the end of the day and noticed my profile processing was taking a long time. I figured it is just processor intensive and left it running for the day while I went home. To my surprise, the next day it was still running! htop showed me it had accumulated 12 hours of CPU time and was still not finished. This led me to track down a related issue and how to fix it.

As you may know, you generate a profiling log by running node --prof command. This writes a long file with a lot of data. You then process it by running

node --process-prof file.log > processed.txt

According to the issue, where it gets stuck is that sometimes the log file is written with invalid data at the end, maybe due to some Node.js version's deficiencies or maybe the Node.js instance was killed abruptly. How to fix it is simple: go to the end of the file and ensure it has an empty line. If it has one, add a second one for good measure. If the last line in the file with content looks wrong to you, you can delete it and it shouldn't affect much.

After this the profile processing should run quickly.