From owner-freebsd-questions Wed Sep 5 3:54:31 2001 Delivered-To: freebsd-questions@freebsd.org Received: from soleil.uvsq.fr (soleil.uvsq.fr [193.51.24.1]) by hub.freebsd.org (Postfix) with ESMTP id 58F2437B406 for ; Wed, 5 Sep 2001 03:54:23 -0700 (PDT) Received: from lucifer.prism.uvsq.fr (lucifer.prism.uvsq.fr [193.51.25.7]) by soleil.uvsq.fr (8.11.3/jtpda-5.3.3) with ESMTP id f85AsKB79859 for ; Wed, 5 Sep 2001 12:54:21 +0200 (CEST) Received: from gibet.prism.uvsq.fr (gibet.prism.uvsq.fr [193.51.25.3]) by lucifer.prism.uvsq.fr (8.9.3/jtpda-5.3.2) with ESMTP id MAA03054 for ; Wed, 5 Sep 2001 12:52:13 +0200 (MET DST) Received: from (dntt@localhost) by gibet.prism.uvsq.fr (8.11.1/jtpda-5.3.3) id f85AsJI76295 for freebsd-questions@freebsd.org; Wed, 5 Sep 2001 12:54:19 +0200 (CEST) Date: Wed, 5 Sep 2001 12:54:19 +0200 From: Tuyet Tram DANG NGOC To: freebsd-questions@freebsd.org Subject: behaviour of getrusage () on FreeBSD Message-ID: <20010905125419.A76278@gibet.prism.uvsq.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 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