Weird `strace` limitations

I am trying to figure out why the cli is so sluggish, to the point of being unusable. To this end, I have obtained the strace binary from debian and copied it to my nas.
I can run strace -p ${pid-of-middlewared} but that has provided no insights.

When I attempt strace cli directly, I get an error:

root@truenas:~# ~dap/bin/strace cli
/mnt/rpool/home/dap/bin/strace: test_ptrace_get_syscall_info: PTRACE_TRACEME: Operation not permitted
/mnt/rpool/home/dap/bin/strace: ptrace(PTRACE_TRACEME, ...): Operation not permitted
+++ exited with 1 +++
root@truenas:~#

If I run cli in the background, and attempt to attach to it:

root@truenas:~# cli &
[1] 3508239
root@truenas:~# ~dap/bin/strace -p 3508239
/mnt/rpool/home/dap/bin/strace: test_ptrace_get_syscall_info: PTRACE_TRACEME: Operation not permitted
/mnt/rpool/home/dap/bin/strace: attach: ptrace(PTRACE_ATTACH, 3508239): Operation not permitted

However, I can attach to the middlewared process:

root@truenas:~# ~dap/bin/strace -p 2304 2>&1 | head -4
/mnt/rpool/home/dap/bin/strace: test_ptrace_get_syscall_info: PTRACE_TRACEME: Operation not permitted
/mnt/rpool/home/dap/bin/strace: Process 2304 attached
epoll_wait(12, [{events=EPOLLIN, data={u32=25, u64=25}}], 11, 27887) = 1
recvfrom(25, "\211\tkeepalive", 262144, 0, NULL, NULL) = 11
root@truenas:~#

Anyone have a clue?

There is this weird autrace programme on TrueNAS – perhaps I’ll try that again just on the cli.

Just been running echo ls | python -m trace --trace /bin/cli – that is really wild. Wow. Over 1.5GB trace file.

strace would help.

Turns out that running as root user is different from running in a sudo bash shell.
strace works much better, but cli is still strangely sluggish.