From owner-svn-src-all@FreeBSD.ORG Sat Dec 10 08:26:53 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B71FD1065670; Sat, 10 Dec 2011 08:26:53 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 56CFF8FC12; Sat, 10 Dec 2011 08:26:51 +0000 (UTC) Received: by bkbzv15 with SMTP id zv15so4853973bkb.13 for ; Sat, 10 Dec 2011 00:26:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:references:x-comment-to:sender:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=FVK8bYJ3T/B+hQEEn884hd+VdpkZXGYc7OB7/P8QSJo=; b=NqVBdssWUR4UNBW5pzEy6EjYdPDin53nUOacFe2NzjOIUNvsVIedZKpflwed6PrVyw BgKdf9b4VA/cNoxELT9/tKOCm/u/dj4Y8qJa+sDNzoYB8ZJqHnmD+hkYHX+483Si/EEy ZUnWGEO5vu8H5aUoWRiuM28JEIwcjT5DkvEmI= Received: by 10.205.81.141 with SMTP id zy13mr5534365bkb.50.1323505611159; Sat, 10 Dec 2011 00:26:51 -0800 (PST) Received: from localhost ([95.69.173.122]) by mx.google.com with ESMTPS id d2sm15586371bky.11.2011.12.10.00.26.47 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 10 Dec 2011 00:26:49 -0800 (PST) From: Mikolaj Golub To: John Baldwin References: <201111242054.pAOKs6vj012296@svn.freebsd.org> <201111281330.11720.jhb@freebsd.org> <86liqt1ier.fsf@kopusha.home.net> <4EE1024C.6040800@FreeBSD.org> <86k466aip3.fsf@kopusha.home.net> <4EE12CE0.5070803@FreeBSD.org> X-Comment-To: John Baldwin Sender: Mikolaj Golub Date: Sat, 10 Dec 2011 10:26:46 +0200 In-Reply-To: <4EE12CE0.5070803@FreeBSD.org> (John Baldwin's message of "Thu, 08 Dec 2011 16:32:16 -0500") Message-ID: <86y5ukvnll.fsf@kopusha.home.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Cc: svn-src-head@freebsd.org, Robert Watson , svn-src-all@freebsd.org, src-committers@freebsd.org, Kostik Belousov Subject: Re: svn commit: r227956 - head/usr.bin/procstat X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Dec 2011 08:26:53 -0000 --=-=-= On Thu, 08 Dec 2011 16:32:16 -0500 John Baldwin wrote: >> JB> Hmm, I would stick as close to limits output as possible. I would >> JB> consider duplicating the unit field in each of soft and hard, so you >> JB> end up with something like this: >> >> JB> PID COMM RLIMIT SOFT HARD >> JB> 48798 zsh cputime 100000 secs infinity secs >> JB> 48798 zsh filesize infinity kb infinity kb >> JB> 48798 zsh datasize 524288 kb 524288 kb >> >> JB> etc. >> >> Ok. >> >> JB> (Things like 'openfiles' is simply more intuitive than 'nofile' (no >> JB> file?, huh? oh, num open files.. (except not all users will make the >> JB> last step there). >> >> Then why do we have so non-intuitive rlimit_ident names? >> >> It looks like they are used only in procfs_rlimit.c. Do procfs(5) users always >> make that last step with 'nofile'? :-) JB> Well, I suspect it's best not to change the names in procfs in case JB> there are existing binaries that parse the output of that file JB> (unfortunately). >> Is it possible to change rlimit_ident names? Just to ones that are used by >> limit(1) or (if they look too long) to something like below: JB> Hmm, I have no idea what other things might use rlimit_ident. Probably JB> not many. (Also, for fun, note that the 'ulimit' and 'limit' built-in JB> commands in sh and csh also have their own sets of names, fun!) I would JB> maybe add a rlimit_names[] (just leave rlimit_ident alone), and give JB> that the names from limits(1), and change both procstat and sh's JB> ulimit' command to use those. Adding yet another rlimit names to the header file does not look so attractive for me as it was just using/reusing what we had :-). So I decided to hardcode the names in procstat_rlimit.c (see the attached patch). Output example: PID COMM RLIMIT SOFT HARD 11949 zsh cputime 10000 sec infinity 11949 zsh filesize infinity infinity 11949 zsh datasize 524288 kB 524288 kB 11949 zsh stacksize 65536 kB 65536 kB 11949 zsh coredumpsize 190734 MB 190734 MB 11949 zsh memoryuse infinity infinity 11949 zsh memorylocked infinity infinity 11949 zsh maxprocesses 5547 5547 11949 zsh openfiles 11095 11095 11949 zsh sbsize infinity infinity 11949 zsh vmemoryuse infinity infinity 11949 zsh pseudo-terminals infinity infinity 11949 zsh swapuse infinity infinity -- Mikolaj Golub --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=procstat_rlimit.c.patch Index: usr.bin/procstat/procstat_rlimit.c =================================================================== --- usr.bin/procstat/procstat_rlimit.c (revision 228285) +++ usr.bin/procstat/procstat_rlimit.c (working copy) @@ -28,7 +28,6 @@ #include #include -#define _RLIMIT_IDENT #include #include #include @@ -36,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -43,17 +43,60 @@ #include "procstat.h" +static struct { + const char *name; + const char *suffix; +} rlimit_param[13] = { + {"cputime", "sec"}, + {"filesize", "B "}, + {"datasize", "B "}, + {"stacksize", "B "}, + {"coredumpsize", "B "}, + {"memoryuse", "B "}, + {"memorylocked", "B "}, + {"maxprocesses", " "}, + {"openfiles", " "}, + {"sbsize", "B "}, + {"vmemoryuse", "B "}, + {"pseudo-terminals", " "}, + {"swapuse", "B "}, +}; + +#if RLIM_NLIMITS > 13 +#error "Resource limits have grown. Add new entries to rlimit_param[]." +#endif + static struct rlimit rlimit[RLIM_NLIMITS]; +static +const char *humanize_rlimit(int indx, rlim_t limit) +{ + static char buf[14]; + int scale; + + if (limit == RLIM_INFINITY) + return "infinity "; + + scale = humanize_number(buf, sizeof(buf) - 1, (int64_t)limit, + rlimit_param[indx].suffix, HN_AUTOSCALE | HN_GETSCALE, HN_DECIMAL); + (void)humanize_number(buf, sizeof(buf) - 1, (int64_t)limit, + rlimit_param[indx].suffix, HN_AUTOSCALE, HN_DECIMAL); + /* Pad with one space if there is no suffix prefix. */ + if (scale == 0) + sprintf(buf + strlen(buf), " "); + return (buf); +} + void procstat_rlimit(struct kinfo_proc *kipp) { int error, i, name[4]; size_t len; - if (!hflag) - printf("%5s %-16s %-10s %12s %12s\n", "PID", "COMM", "RLIMIT", - "CURRENT", "MAX"); + if (!hflag) { + printf("%5s %-16s %-16s %16s %16s\n", + "PID", "COMM", "RLIMIT", "SOFT ", "HARD "); + } name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_RLIMIT; @@ -68,11 +111,9 @@ procstat_rlimit(struct kinfo_proc *kipp) return; for (i = 0; i < RLIM_NLIMITS; i++) { - printf("%5d %-16s %-10s %12jd %12jd\n", kipp->ki_pid, - kipp->ki_comm, rlimit_ident[i], - rlimit[i].rlim_cur == RLIM_INFINITY ? - -1 : rlimit[i].rlim_cur, - rlimit[i].rlim_max == RLIM_INFINITY ? - -1 : rlimit[i].rlim_max); + printf("%5d %-16s %-16s ", kipp->ki_pid, kipp->ki_comm, + rlimit_param[i].name); + printf("%16s ", humanize_rlimit(i, rlimit[i].rlim_cur)); + printf("%16s\n", humanize_rlimit(i, rlimit[i].rlim_max)); } } --=-=-=--