From owner-freebsd-hackers@FreeBSD.ORG Tue Jan 22 17:14:53 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id CC1E1270; Tue, 22 Jan 2013 17:14:53 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id AACA669E; Tue, 22 Jan 2013 17:14:53 +0000 (UTC) Received: from pakbsde14.localnet (unknown [38.105.238.108]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 101AFB94A; Tue, 22 Jan 2013 12:14:53 -0500 (EST) From: John Baldwin To: freebsd-hackers@freebsd.org Subject: Re: libprocstat(3): retrieve process command line args and environment Date: Tue, 22 Jan 2013 12:01:06 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p22; KDE/4.5.5; amd64; ; ) References: <20130119151253.GB88025@gmail.com> In-Reply-To: <20130119151253.GB88025@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201301221201.06290.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 22 Jan 2013 12:14:53 -0500 (EST) Cc: Mikolaj Golub , Stanislav Sedov , Robert Watson X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jan 2013 17:14:53 -0000 On Saturday, January 19, 2013 10:12:54 am Mikolaj Golub wrote: > Hi, > > Some time ago Stanislav Sedov suggested to me extending libprocstat(3) > with functions to retrieve process command line arguments and > environment variables. > > In the first approach I tried, the newly added functions > procstat_getargv/getenvv allocated a buffer of necessary size, stored > the values and returned to the caller: > > http://people.freebsd.org/~trociny/libprocstat.1.patch > > The problem with this approach was that when I updated procstat(1) to > use this interface, I observed noticeable performance degradation > (about 30% on systems with MALLOC_PRODUCTION off), due to memory > allocation overhead: the original procstat(1) reuses the buffer for > all its retrievals. > > So my second approach was to add internal buffers to struct procstat, > which are used by procstat_getargv/getenvv to store values and reused > on the subsequent call: > > http://people.freebsd.org/~trociny/libprocstat.2.patch > > The drawback of this approach is that a user has to take care and > remember that a subsequent call rewrites argument vector obtained from > the previous call. On the other hand this is ok for typical use cases > while does not add allocation overhead, so I like this approach more. > > I would like to commit this second patch, if there are no objections > or suggestions how to improve the things. How is this different from kvm_getargv()? It seems to be a direct copy. -- John Baldwin