Re: Measuring memory footprint in C/C++ code on FreeBSD

看板FB_hackers作者時間14年前 (2011/10/22 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串10/11 (看更多)
In the last episode (Oct 21), Razmig K said: > Le 21.10.2011 10:44, Peter Jeremy a 矇crit : > > On 2011-Oct-20 19:57:31 +0200, Razmig K<strontium90@gmail.com> wrote: > > It's not clear whether the program is attempting to determine it's own > > (or a child's) memory footprint, or that of an arbitrary process. In > > the former case, getrusage() is the obvious choice. This as a portable > > interface. > > The program has to determine its own memory footprint. It has no children. > > > If you want to examine arbitrary processes, the best interface on > > FreeBSD would be kvm_getprocs(3). > > > > BTW, since you mention heap objects, I presume you are aware that > > malloc() uses mmap(), rather than sbrk() to obtain memory. > > No I wasn't aware of that. > > In few words, the program needs to obtain and report information > reported by the SIZE column of top, since it is going to be run many > times, and it is impractical to watch top for this purpose. top also uses kvm_getprocs, so you can use that as a template (see the manpage and source at usr/src/usr.bin/top/machine.c). If you call it with the KERN_PROC_PID flag, you can get the stats for a single processs by pid. If you want even more detail, you can look at the source to the procstat command, which uses some other calls to dump the vm map of processes. -- Dan Nelson dnelson@allantgroup.com _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
文章代碼(AID): #1EeRDati (FB_hackers)
討論串 (同標題文章)
完整討論串 (本文為第 10 之 11 篇):
文章代碼(AID): #1EeRDati (FB_hackers)