From owner-freebsd-hackers@FreeBSD.ORG Sat Jan 19 15:13:05 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id C64D851C; Sat, 19 Jan 2013 15:13:05 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-ee0-f41.google.com (mail-ee0-f41.google.com [74.125.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 1106BFBD; Sat, 19 Jan 2013 15:13:04 +0000 (UTC) Received: by mail-ee0-f41.google.com with SMTP id c13so2266747eek.0 for ; Sat, 19 Jan 2013 07:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:date:from:to:cc:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=AknV0tjCXexVs389uWgJMgdZPmGpyEcQAX9YwZdm8P4=; b=XaI0rdgt8FHzwrJooRcySHbjLtWIwFj5mn5O7B+4xGWWssyQ5uaWoOT905tRz5BIUN gr4zPfyZ/7gUgR3WBJvTm1SuwJiLIVKegbwvFrLjQGJz9HZ5BviIEVBjSE+00pj7PcXe pQ1Uo8lFEy3WEStQRdQEKp96N18T9Sn8gtMOwTM/gAOp3rLMxEip/ChsUHavUjNsWkmg +IhLUb2z7se1a3DcJmj5o4wS8d7NsDrfnqpjd44So8af/qhFOznjexQneTPftZnAtT48 O6iorq1RCPyc6fumqJspgnk0xeYZzGtxe4D7KcfZXRGkFDWNre1qcBxKgFD3RZUMo/Wk n/Jw== X-Received: by 10.14.194.195 with SMTP id m43mr39073238een.44.1358608378061; Sat, 19 Jan 2013 07:12:58 -0800 (PST) Received: from localhost ([178.150.115.244]) by mx.google.com with ESMTPS id z8sm12737977eeo.11.2013.01.19.07.12.56 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 19 Jan 2013 07:12:57 -0800 (PST) Sender: Mikolaj Golub Date: Sat, 19 Jan 2013 17:12:54 +0200 From: Mikolaj Golub To: freebsd-hackers@freebsd.org Subject: libprocstat(3): retrieve process command line args and environment Message-ID: <20130119151253.GB88025@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Cc: 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: Sat, 19 Jan 2013 15:13:05 -0000 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