开发者

Node.JS garbage collection event? or --trace-gc to stderr?

开发者 https://www.devze.com 2023-03-03 11:58 出处:网络
As a general practice, when I write scripts, log messages always go to stderr and data (status messages, results from an algorithm, whatever) goes to stdout.

As a general practice, when I write scripts, log messages always go to stderr and data (status messages, results from an algorithm, whatever) goes to stdout.

I would like to get this sent to stderr. Can that be done?

I would be fine to use my own handler to some sort of process.on('gc') event if there is one. Is there one?

I am writing some code now where stdout is reserved for data and I have no choice but to turn of开发者_Go百科f --trace-gc. I am using memoryUsage() as a second best thing, but it does not tell the usage right before and right after GC, it just tells you the usage whenever memoryUsage() happened to be called.


A quick check of the v8 source code (where the garbage collector lives - [node src dir]/deps/v8/src/heap.cc and platform-posix.cc) shows that garbage collection messages are printed to the console using the standard linux vprint() (from printf(3)) so I'm pretty sure you cannot trap them without patching the source code.

0

精彩评论

暂无评论...
验证码 换一张
取 消