libprocstat(3): retrieve process command line args and environment
Mikolaj Golub
trociny at FreeBSD.org
Sat Jan 19 15:13:05 UTC 2013
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
More information about the freebsd-hackers
mailing list