Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Jan 2013 17:12:54 +0200
From:      Mikolaj Golub <trociny@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Cc:        Stanislav Sedov <stas@FreeBSD.org>, Robert Watson <rwatson@FreeBSD.org>
Subject:   libprocstat(3): retrieve process command line args and environment
Message-ID:  <20130119151253.GB88025@gmail.com>

next in thread | raw e-mail | index | archive | help
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.

-- 
Mikolaj Golub



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130119151253.GB88025>