From owner-freebsd-hackers@FreeBSD.ORG Fri Oct 21 08:44:26 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 329AF106564A for ; Fri, 21 Oct 2011 08:44:26 +0000 (UTC) (envelope-from strontium90@gmail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id B909B8FC13 for ; Fri, 21 Oct 2011 08:44:25 +0000 (UTC) Received: by wyi40 with SMTP id 40so4800853wyi.13 for ; Fri, 21 Oct 2011 01:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=hWYAO9rJ89jGyRK/X4l/YGFbzVptqpce2IVuEXoBwPc=; b=fh01ZOyVgtVeQ05PchIs9hKIhlwgD2Tp2pQOIsMdvZY1ML8D18iBKbAY4iFHO/aT/8 DZaHoUiNO3517+wyG32mDMqAm6AiQZM3xxsOeNc54fcbT9P50QUE8lew0xZYQKZqbT5w Fuwx52C1kl9ndvLM8a3o6ifn8THuzg9VL/+ME= Received: by 10.216.88.140 with SMTP id a12mr4876822wef.82.1319186664484; Fri, 21 Oct 2011 01:44:24 -0700 (PDT) Received: from iv-sv-328.creatis.insa-lyon.fr (iv-sv-328.creatis.insa-lyon.fr. [195.220.108.195]) by mx.google.com with ESMTPS id fy13sm20390521wbb.18.2011.10.21.01.44.22 (version=SSLv3 cipher=OTHER); Fri, 21 Oct 2011 01:44:23 -0700 (PDT) Message-ID: <4EA130E5.9060807@gmail.com> Date: Fri, 21 Oct 2011 10:44:21 +0200 From: Razmig K User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:7.0) Gecko/20111003 Thunderbird/7.0 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org References: <4EA0610B.90206@gmail.com> In-Reply-To: <4EA0610B.90206@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: Measuring memory footprint in C/C++ code on FreeBSD X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2011 08:44:26 -0000 Le 20.10.2011 19:57, Razmig K a écrit : > the memory footprint in C/C++ code for a program running under FreeBSD > and Linux in terms of total process size including heap objects Well getrusage does actually exist in Linux, but its behaviour isn't the same as on FreeBSD; struct rusage memory usage information fields ru_ixrss (shared text), ru_idrss (unshared data) and ru_isrss (unshared stack) are always zero. To test and understand the behaviour of getrusage on FreeBSD, I have written a small C++ program that allocates several large double arrays on the stack as well as on the heap with few loops to delay execution, and tried using the aforementioned fields, in addition to ru_maxrss (max resident size) to deduce memory usage information of the program as reported by top, namely fields RES and SIZE, but somehow I didn't manage to get a result matching that of the latter. First of all, I'm not sure if I interpret man getrusage correctly. For ru_ixrss, it says that it is an "integral" value indicating the amount of memory used by the text segment that was also shared among other processes, and is expressed in units of kilobytes * ticks-of-execution, where ticks are statistics clock ticks, the statistics clock having a frequency of sysconf(_SC_CLK_TCK) ticks per second. Does this imply that I need to divide ru_ixrss by sysconf(_SC_CLK_TCK) * a certain number of seconds? In that case, what do I use for the latter? ru_stime or ru_utime? I have observed that unlike ru_idrss, ru_ixrss and ru_isrss depend on execution time which contradicts the manpage, since all three fields are supposed to be specified in the same unit. Lastly, I don't see how to use getrusage to deduce information on the program's heap use. As I said in my first message, I need to measure the memory footprint in terms of total process size including heap objects. Thanks again for any tips. ~Razmig