I'm trying to profile NodeJS with Dtrace and it is not working out. The command that I'm using is:
dtrace -n 'profile-97/execname == "node" && arg1/{@[jstack(150, 8000)] = count(); } tick-60s { exit(0); }' > stacks.out
The output that I get is:
CPU ID FUNCTION:NAME
0 312432 :tick-30s
If I do dtrace -l
then I get for example:
58814 instr kernel setup_APIC_eilvt-jne 0xffffffff81045e27
58815 instr kernel setup_APIC_eilvt-je 0xffffffff81045e34
58816 instr kernel setup_APIC_eilvt-je 0xffffffff81045e38
58817 instr kernel setup_APIC_eilvt-callr 0xffffffff81045e46
58818 instr kernel setup_APIC_eilvt-callr 0xffffffff81045e6a
58819 instr kernel lapic_timer_setup.part.4-cli 0xffffffff81045ea0
58820 instr kernel lapic_timer_setup.part.4-jbe 0xffffffff81045eaa
58821 instr kernel lapic_timer_setup.part.4-jbe 0xffffffff81045eaf
58822 instr kernel lapic_timer_setup.part.4-callr 0xffffffff81045ed4
58823 instr kernel lapic_timer_setup-je 0xffffffff81045f39
58824 instr kernel lapic_timer_setup-repz 0xffffffff81045f3b
58825 instr kernel local_apic_timer_interrupt-je 0xffffffff81045f74
58826 instr kernel local_apic_timer_interrupt-callr 0xffffffff81045f90
58827 instr kernel local_apic_timer_interrupt-je 0xffffffff81045f99
58828 instr kernel clear_local_APIC-jne 0xffffffff8104610e
58829 instr kernel clear_local_APIC-jg 0xffffffff810461c3
58830 instr kernel clear_local_APIC-je 0xffffffff8104629a
58831 instr kernel disable_local_APIC-jne 0xffffffff810463bd
58832 instr kernel disable_local_APIC-je 0xffffffff810463c7
58833 instr kernel disable_local_APIC-callr 0xffffffff810463c9
58834 instr kernel disable_local_APIC-repz 0xffffffff81046400
58835 instr kernel lapic_suspend-jne 0xffffffff8104641d
58836 instr kernel lapic_suspend-jg 0xffffffff81046555
58837 instr kernel lapic_suspend-cli 0xffffffff81046561
58838 instr kernel lapic_suspend-callr 0xffffffff81046568
And if I list all the processes that open files with:
dtrace -q -n syscall::open:entry'{ printf("%-16s%-16s\n", execname,copyinstr(arg0)); }'
I get all the processes opening files, it even show NodeJS starting and getting ready for work :)
vminfo /var/run/utmp
vminfo /var/run/utmp
systemd /proc/145/cgroup
vminfo /var/run/utmp
vminfo /var/run/utmp
vminfo /var/run/utmp
vminfo /var/run/utmp
systemd /proc/460/cgroup
vminfo /var/run/utmp
vminfo /var/run/utmp
node /etc/ld.so.cache
node /lib/x86_64-linux-gnu/libdl.so.2
node /lib/x86_64-linux-gnu/librt.so.1
node /usr/lib/x86_64-linux-gnu/libstdc++.so.6
node /lib/x86_64-linux-gnu/libm.so.6
node /lib/x86_64-linux-gnu/libgcc_s.so.1
node /lib/x86_64-linux-gnu/libpthread.so.0
node /lib/x86_64-linux-gnu/libc.so.6
node /dev/urandom
node /home/davidgatti/test/ble.js
node /etc/resolv.conf
node /etc/nsswitch.conf
node /dev/urandom
node /dev/pts/0
node /dev/null
node /dev/pts/0
vminfo /var/run/utmp
vminfo /var/run/utmp
systemd /proc/145/cgroup
What I'm doing wrong? How should I probe NodeJS or any other process to get some useful info out?
Sadly this won't work under Linux because Dtrace it strictly tied with the system kernel.
Dtrace works for example under macOS or Solaris because there is one version of the kernel, and if any changes are made the authors can do the appropriate changed to Dtrace.
Since not only Linux has many different kernels in each distribution, you are free to compile your own version however you want, and this means that it is impossible to create a working Dtrace for this system.
Since Dtrace needs to hook in specific parts of the kernel to be able to trace what is going on within the app.
You can read more about this in the Issue section of the original Dtrace for linux repo.