节点配置文件中的 ___mac_get_pid 符号是什么?

What is the ___mac_get_pid symbol in a node profile?

我正在 OSX 上分析一些多进程 nodejs 代码 运行。

我看到了:

[C++]:
   ticks  total  nonlib   name
  23398   63.6%   63.8%  ___mac_get_pid

什么是___mac_get_pid?它的名字当然暗示它是一些代码"gets a PID on a Mac",但时间似乎过长。

谷歌搜索没有提供任何有用信息。

__mac_get_pidmac_get_pid 库函数背后的系统调用。它在手册页 mac_get 中有描述:http://man.cx/mac_get(3)

mac_get_pid .. get the label of a file, socket, socket peer or process The mac_get_pid() and mac_get_proc() system calls return the process label associated with an arbitrary process ID, or the current process.

Label storage for use with these calls must first be allocated and prepared using the mac_prepare(3) functions. When an application is done using a label, the memory may be returned using mac_free(3).

这里的"MAC"不是MacOSX/macOS,而是POSIX.1e's Mandatory Access Control ("was introduced in FreeBSD 5.0 as part of the TrustedBSD Project"). The mac_get_pid is implemented in macOS/Dawrin/XNUas"Extended non-POSIX.1e interfaces".

可能在使用的 nodejs 库中有一些方法试图对进程列表进行详细的工作(如 ps/top),但它们无法限制请求的速率。使用 mac_get_pid 使用探查器(不是 v8 profiler which stacktraces only js,而是附加到 nodejs 进程的一些外部探查器)或使用调试器(gdb/lldb)通过手动停止和检查回溯直到找到谁调用mac_get_pid(继续并在您不在 mac_get_pid 时再次停止)是找出调用者的必要步骤。