秘密のAPI process.uvCounters() とは何か?
IIJ 大津繁樹 (@jovi0608)
2011年12月14日
> node -e 'console.log(process.uvCounters())' { eio_init: 0, req_init: 0, handle_init: 7, stream_init: 0, tcp_init: 0, udp_init: 0, pipe_init: 0, tty_init: 0, prepare_init: 1, check_init: 2, idle_init: 2, async_init: 1, timer_init: 1, process_init: 0, fs_event_init: 0 }
node-v0.6.5/deps/uv/src/unix/core.c 312 void uv__req_init(uv_req_t* req) { 313 /* loop->counters.req_init++; */ 314 req->type = UV_UNKNOWN_REQ; 315 }
void Work(uv_work_t* req) { ... } void Done(uv_work_t* req) { ... } HandleputQueue(const Arguments& args) { HandleScope scope; callback = Persistent<Function>::New( Local<Function>::Cast(args[0])); int status = uv_queue_work(uv_default_loop(), &request, Work, Done); return Undefined(); } void RegisterModule(Handle<Object> exports) { exports->Set(String::NewSymbol("putQueue"), FunctionTemplate::New(putQueue)->GetFunction()); } NODE_MODULE(thread_test, RegisterModule);
var thread_test = require('./thread_test.node'); var prev = process.uvCounters().req_init; thread_test.putQueue(function(msg) { var now = process.uvCounters().req_init; console.log(prev,now,msg); });
> node test.js 14 15 'Work Done'
require('http').createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "127.0.0.1"); (function monitor() { var now = new Date(); var c = process.uvCounters(); console.log(now.toLocaleString(),c.tcp_init,c.req_init); setTimeout(monitor, 1000); })();
時間 tcp_init req_init Wed Dec 14 2011 16:24:55 GMT+0900 (JST) 1 15 Wed Dec 14 2011 16:24:56 GMT+0900 (JST) 277 292 Wed Dec 14 2011 16:24:57 GMT+0900 (JST) 1976 1992 Wed Dec 14 2011 16:24:58 GMT+0900 (JST) 4032 4049