如何获取内存使用情况的统计信息? [英] how to get statistics about memory usage ?
问题描述
在一个程序中,我需要获取一些关于内存使用情况的统计信息。
我实际上需要ps给出的数字 - o vsr,rss"命令。
目前,我制作了一个popen(ps ...),然后在scanf上显示它显示的b
。这有点复杂,这会扭曲测量值。
有更好的方法吗?
我试过getrusage()。但是返回的值并不是真的与我的需求相关。
我也查看了mallinfo(),没有成功。
首先,我不知道那是什么块。 (什么尺寸 ?)。然后,那就是
不计算堆栈大小和代码大小,只计算malloc。
(顺便说一下,它或多或少是一个C ++代码。那么,新是否计入
mallinfo()?)
然后,我的程序如何知道它的常驻集合大小?特别是它的
虚拟内存大小?
谢谢。
Christophe
Hi,
Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.
For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?
I have tried "getrusage()". However values returned are not really
relevant for my needs.
I also looked at "mallinfo()", without success.
First, I do not know what is that a "block" (which size ?). Then, that does
not count the stack size and the code size, just the malloc.
(By the way, it''s more or less a C++ code. So, are the "new" counted in
mallinfo() ?)
Then, how can my program know its "resident set size" and especially its
"virtual memory size"?
Thanks.
Christophe
推荐答案
Christophe Lohr写道:
Christophe Lohr wrote:
在程序中,我需要获取一些有关内存使用情况的统计信息。我实际上需要ps -o vsr,rss给出的数字。命令。
目前,我制作了一个popen(ps ...),然后在scanf上显示它所显示的内容。这有点复杂,这会扭曲测量结果。
有没有更好的方法?
我尝试过getrusage()。然而,返回的值与我的需求并不相关。
我也看了mallinfo(),没有成功。
首先,我不知道是什么阻止 (什么尺寸 ?)。然后,这不计算堆栈大小和代码大小,只计算malloc。
(顺便说一下,它或多或少是一个C ++代码。所以,新是什么?在mallinfo()中计算?)
然后,我的程序如何知道它的驻留集大小?尤其是它的虚拟内存大小?
谢谢。
Christophe
Hi,
Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.
For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?
I have tried "getrusage()". However values returned are not really
relevant for my needs.
I also looked at "mallinfo()", without success.
First, I do not know what is that a "block" (which size ?). Then, that does
not count the stack size and the code size, just the malloc.
(By the way, it''s more or less a C++ code. So, are the "new" counted in
mallinfo() ?)
Then, how can my program know its "resident set size" and especially its
"virtual memory size"?
Thanks.
Christophe
C语言本身知道不是这样的事情。但是,很可能,你的平台提供了一些获取此类信息的方式(可能以合理的方式支付b $ b)<提示,提示>。查看您的文档或发布到
相关新闻组。
HTH,
--ag
>
-
Artie Gold - 德克萨斯州奥斯汀
http://goldsays.blogspot.com (新帖子8/5)
http://www.cafepress.com/goldsays
如果你没有什么可隐瞒的,你就不会尝试!
The C language itself knows not of such things. Is is likely, however,
that your platform provides some way of getting such information (likely
in a reasonable way) <hint, hint>. See your documentation or post to a
relevant newsgroup.
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you''re not trying!"
Christophe Lohr写道:
Christophe Lohr wrote:
在程序中,我需要获取一些有关内存使用情况的统计信息。
我实际上需要ps -o vsr,rss给出的数字。命令。
目前,我制作了一个popen(ps ...),然后在scanf上显示它所显示的内容。这有点复杂,这会扭曲测量结果。
有没有更好的方法?
我尝试过getrusage()。然而,返回的值与我的需求并不相关。
我也看了mallinfo(),没有成功。
首先,我不知道是什么阻止 (什么尺寸 ?)。然后,这不计算堆栈大小和代码大小,只计算malloc。
(顺便说一下,它或多或少是一个C ++代码。所以,新是什么?在mallinfo()中计算?)
然后,我的程序如何知道它的驻留集大小?尤其是它的虚拟内存大小?
谢谢。
Christophe
Hi,
Inside a program, I need to get some statistics about memory usage.
I actually need figures given by the "ps -o vsr,rss" command.
For the moment, I make a popen("ps...") followed of a scanf on what it
displays. It is a little complicated, and that distorts measurements.
Is there a better way?
I have tried "getrusage()". However values returned are not really
relevant for my needs.
I also looked at "mallinfo()", without success.
First, I do not know what is that a "block" (which size ?). Then, that does
not count the stack size and the code size, just the malloc.
(By the way, it''s more or less a C++ code. So, are the "new" counted in
mallinfo() ?)
Then, how can my program know its "resident set size" and especially its
"virtual memory size"?
Thanks.
Christophe
这是所有系统特定的,所以OT在comp.lang.c中。从你是什么
说,
我相信comp.unix.programmer将是你获得
帮助的好地方。 < OT>在Linux上,可以在/ proc文件系统中找到你想要的东西,你可以在杯子里询问一下< / OT>
-David
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.programmer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>
-David
" David Resnick" < LN ******** @ gmail.com>写道:
[...]
"David Resnick" <ln********@gmail.com> writes:
[...]
这是所有系统特定的,所以OT在comp.lang.c中。从你的内容来说,
我相信comp.unix.programmer将是你获得帮助的好地方。 < OT>在Linux上,可以在/ proc文件系统中找到你想要的内容,你可以在杯子中询问这个< / OT>
This is all system specific, so OT in comp.lang.c. From what you are
saying,
I believe comp.unix.programmer would be a good place for you to get
help. <OT> On Linux, May find what you want in /proc file system, you
could ask about that in cup </OT>
< STILL_OT>
/ proc是特定于Linux的,虽然其他类似Unix的系统可能会提供类似的东西。
< / STILL_OT>
-
Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
<STILL_OT>
/proc is Linux-specific, though some other Unix-like systems may
provide something similar.
</STILL_OT>
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
这篇关于如何获取内存使用情况的统计信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!