Date: Wed, 5 Sep 2001 12:54:19 +0200 From: Tuyet Tram DANG NGOC <Tuyet-Tram.Dang-Ngoc@prism.uvsq.fr> To: freebsd-questions@freebsd.org Subject: behaviour of getrusage () on FreeBSD Message-ID: <20010905125419.A76278@gibet.prism.uvsq.fr>
next in thread | raw e-mail | index | archive | help
Hello,
in ordre to know the size of the data allocated in my C
program at certain points of its execution, I wanted to use the
primitive function 'getrusage ()'
I encounter some problems when I use getrusage to display
memory usage by a code like the following :
[...]
getrusage (RUSAGE_SELF, &r);
printf ("user time : %ld.%02ld\n", r.ru_utime.tv_sec, \
r.ru_utime.tv_usec/10000) ;
printf ("system time : %ld.%02ld\n", r.ru_stime.tv_sec, \
r.ru_stime.tv_usec/10000) ;
ticks = (r.ru_utime.tv_sec + r.ru_stime.tv_sec + \
r.ru_utime.tv_usec/10000 + r.ru_stime.tv_usec/10000) * clock;
printf ("nombre de ticks : %ld\n", ticks) ;
printf ("max resident set size : %ld\n", r.ru_maxrss);
printf ("integral shared memory size : %ld\n", r.ru_ixrss / ticks);
printf ("integral unshared data : %ld\n", r.ru_idrss / ticks);
printf ("integral unshared stack : %ld\n", r.ru_isrss / ticks);
[...]
If I make such calls in my main program :
int main ()
{
/* step 1 */
Displaying information about getrusage (and be careful about not to
divide by the number of ticks which is 0 at the beginning)
/* step 2 */
big and long processing instructions allocating and using lot of memory
/* step 3 */
Displaying information about getrusage.
[...]
}
On a FreeBSD 4.3-RELEASE-p14, I get :
* On step 1 :
max resident set size : 0
integral shared memory size : 0
integral unshared data : 0
integral unshared stack : 0
user time : 0.00
system time : 0.00
Well, this seems normal, as it has just started.
* On step 3 (after a big instructions), I get :
max resident set size : 436
integral shared memory size : 4
integral unshared data : 13
integral unshared stack : 145
user time : 0.52
system time : 8.50
Well, no comments about these results, it's OK.
I launch the same program on another computer (a little
more powerful), on FreeBSD 4.3-RELEASE, and :
* step 1 :
max resident set size : 0
integral shared memory size : 0
integral unshared data : 0
integral unshared stack : 0
user time : 0.00
system time : 0.00
* step 3 :
max resident set size : 0
integral shared memory size : 0
integral unshared data : 0
integral unshared stack : 0
user time : 0.00
system time : 6.46
Questions :
- why the behaviours aren't the same as on the first computer ?
- why are all the data size, null ?
And finally with another computer (an old P75) with a
FreeBSD 5.0-CURRENT, I get :
* step 1 :
max resident set size : 208
integral shared memory size : 8
integral unshared data : 8
integral unshared stack : 256
user time : 0.00
system time : 0.00
* step 3 :
max resident set size : 372
integral shared memory size : 4
integral unshared data : 12
integral unshared stack : 130
user time : 1.88
system time : 70.39
- why at step 1 do I have non-null values ?
- why at step 3, the values are very different from computer 1 and 2 ?
I also tested on a computer with Linux (but without the division by
tcks as said on its man page), and on step 1 and on step 3, all data size are
always null.
On conclusion, my main questions are :
- is it a good idea to use getrusage () to get the size of a process
a *certain* point of its execution (I can't of course watch continuously
a 'top' command or a 'ps -v' command ;-)
- if yes, how can I use it with a determinist behaviour ?
- I also saw that if the big processing instructions of
step 2 are just reduced on the single instruction 'malloc (10000)',
then the r.ru_*time.tv_*sec are null, and so the values of number of ticks too,
and I will have division by zero, and no hope to get data size.
- I also look at 'ps' source code and saw that I could use
kvm_getproc (), but it is not portable when I will have to use it for Linux
and other un*x ;
- someone has told me to make my program read /proc/XXX/map
on FreeBSD and /proc/XXX/status on Linux, but it seems to be a little
"bulky", and I'm not sure I will alway have the rights on this directory.
And it's not portable.
-another one told me to make fork and generate a core to get the
size, but it's a little "bulky" for me ;-)
Does someone have an idea please ?
Thanks in advance,
Tram
--
Tuyêt Trâm ÐANG NGOC <dntt@prism.uvsq.fr>
Laboratoire PRiSM - Université de Versailles
http://www.prism.uvsq.fr/~dntt
Think different, think UNIX !
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010905125419.A76278>
