简体   繁体   English

在macOS当前进程中识别堆栈和堆段

[英]Identify stack and heap segments in macOS current process

I'd like to add memory profiler to my daemon which runs under macOS. 我想将内存分析器添加到我的守护进程中,该守护进程在macOS下运行。 In linux, i could simply check the /proc/<pid>/map for any mapped memory in the process, and look for pathname = [heap] or pathname = [stack]. 在linux中,我可以简单地检查/proc/<pid>/map中进程中的任何映射内存,并查找pathname = [heap]或pathname = [stack]。

Is there any alternative mac syscall/MIG/mach message for that purpose ? 为此目的有没有替代mac syscall / MIG / mach消息?

I've tried to see if proc_pidinfo contain any valuable information, but unfortunately nothing related to my needs. 我试图看看proc_pidinfo包含任何有价值的信息,但遗憾的是没有任何与我的需求相关的信息。

Notice that apple provide such tool for other remote processes called vmmap and it doesn't provide any api at all (it's merely command-line tool) and there's no public API for this demand, but perhaps there's an API to extract this information from "within" the process itself. 请注意,apple为其他名为vmmap远程进程提供了这样的工具,并且它根本不提供任何api(它只是命令行工具),并且没有针对此需求的公共API,但是可能有一个API可以从“提取此信息”在“过程本身。

I don't know what public APIs (if any) it uses, but the closest equivalent to Linux's /proc/$pid/maps in macOS is the vmmap utility. 我不知道它使用了哪些公共API(如果有的话),但是与macOS中的Linux /proc/$pid/maps最接近的是vmmap实用程序。 Running it with a PID as an argument will give you a detailed report on all regions mapped by the process, including some interesting details on memory usage within malloc zones. 使用PID作为参数运行它将为您提供有关该进程映射的所有区域的详细报告,包括有关malloc区域内存使用情况的一些有趣详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM