Node.JS garbage collection event? or --trace-gc to stderr?
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.
精彩评论