업데이트:

태그:

카테고리:

  • 이벤트루프 눈으로 확인하고 싶으신 분들께 추천합니다.
  • nodev14.20.1, libuvv 1.40.0을 기준으로합니다.
  1. nodejs를 클론합니다.
git clone https://github.com/nodejs/node.git
git checkout v14.20.1


  1. /node/deps/uv 폴더의 src/unix/core.c 혹은 src/win/core.c에서 uv__run함수를 찾습니다.


  1. 내부에서 호출되는 함수 하나하나 printf를 작성합니다.
    • printf는 stderr로 터미널에 출력될겁니다.


  1. nodejs 를 빌드합니다.
make -j4


  1. 비명을 지르는 자신의 맥북을 보면서 기도하면 됩니다.

  2. test.js

const fs = require("fs");

console.log("test");
console.log("test");

function timeoutFnc() {
  console.log("timeoutFnc");
}

setTimeout(timeoutFnc, 100);
setImmediate(timeoutFnc);
console.log("test");
console.log("test");

const test = fs.readFile("./stde", (err, data) => {
  console.log(data);
});

var http = require("http");

//create a server object:
http
  .createServer(function (req, res) {
    res.write("Hello World!"); //write a response to the client
    res.end(); //end the response
  })
  .listen(4000); //the server object listens on port 4000

setInterval(timeoutFnc, 100);
  1. 결과물
uv_update_time called
uv_update_time called
1.uv_run called
2.ur_loop alive called
uv_update_time called
3.uv_run timers called
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
test
test
uv_update_time called
test
test
worker called
worker called
worker called
worker called
uv_update_time called
1.uv_run called
2.ur_loop alive called
uv_update_time called
3.uv_run timers called
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
6.uv_check
timeoutFnc
7.uv_close
uv_update_time called
3.uv_run timers called
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
6.uv_check
7.uv_close
uv_update_time called
3.uv_run timers called
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
6.uv_check
7.uv_close
uv_update_time called
3.uv_run timers called
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
<Buffer >
6.uv_check
7.uv_close
uv_update_time called
3.uv_run timers called
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
uv_update_time called
6.uv_check
7.uv_close
uv_update_time called
3.uv_run timers called
uv_update_time called
timeoutFnc
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
uv_update_time called
6.uv_check
7.uv_close
uv_update_time called
3.uv_run timers called
uv_update_time called
uv_update_time called
timeoutFnc
4.uv__run_pending called
5.uv_io_poll
uv_update_time called
  • JS의 첫 줄을 채 실행하기 전에 이벤트루프가 활성화된 것을 볼 수 있습니다.

댓글남기기