From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 4 11:55:14 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65490106566B for ; Thu, 4 Feb 2010 11:55:14 +0000 (UTC) (envelope-from gleb.kurtsou@gmail.com) Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.27]) by mx1.freebsd.org (Postfix) with ESMTP id E4AC08FC0A for ; Thu, 4 Feb 2010 11:55:13 +0000 (UTC) Received: by ey-out-2122.google.com with SMTP id 22so542674eye.9 for ; Thu, 04 Feb 2010 03:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=oC9a/L9kmgReURWjFWFXrJiGOi0ZiYzZV5LDZbQRCPA=; b=uw08Mqn4NQgsjYMxBVnugrGq7hmVnFT1JlOZjjBE1xULXMbD5S8/UiQbTYIE3BbrF3 8TMPbM8Isj/5EL+H//SfvI/m0hLFJaIFYbj16XAjbfgIM3SZpuEU33AO/atx3XcY55gb 0XsM08mCSOhRcXejOiN4YsKQGBmO7/rqerxRg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=F2g6pmgIeyuahKJA/lg/2o6zfQWvocoI5cuemEgn0d0IfD+OCGS7e1l9ZhE9fSmblo 6cg+JpB4cqWrEImUULYrGXfzWzmoviP6GKMiCQ0/4r2LbDMNieT5kFijE7iEVzTTP5H1 hHttUFheRkMaoda+ZAgyFn6K3jwdgPV8EtTq0= Received: by 10.213.44.17 with SMTP id y17mr3421734ebe.25.1265284512807; Thu, 04 Feb 2010 03:55:12 -0800 (PST) Received: from localhost (lan-78-157-90-54.vln.skynet.lt [78.157.90.54]) by mx.google.com with ESMTPS id 14sm26546ewy.11.2010.02.04.03.55.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 04 Feb 2010 03:55:11 -0800 (PST) Date: Thu, 4 Feb 2010 13:55:06 +0200 From: Gleb Kurtsou To: Xin LI , Ed Schouten Message-ID: <20100204115505.GA5272@tops.skynet.lt> References: <200902251724.40212.fbsd.hackers@rachie.is-a-geek.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="xHFwDpU9dbj6ez1V" Content-Disposition: inline In-Reply-To: <200902251724.40212.fbsd.hackers@rachie.is-a-geek.net> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: freebsd-hackers@freebsd.org Subject: Re: [PATCH] Support for thresholds in du(1) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Feb 2010 11:55:14 -0000 --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On (25/02/2009 17:24), Mel wrote: > Hi, > > attached is a small patch to add threshold support to du(1). I've been using > it on 7-STABLE machines for a while, cause I got tired of the noise I get > when sorting and then reformatting to human-readable. Especially since > sorting isn't part of the equasion "I'd like to see all dirs exceeding a > given size". > I've not updated the manpage on -STABLE yet, should be the same as HEAD. > > Example usage: > # du -xht 20m . > 29M ./contrib/binutils > 52M ./contrib/gcc > 237M ./contrib > 35M ./crypto > 28M ./lib > 20M ./share > 55M ./sys/dev > 139M ./sys > 545M . > > I'll file a PR for it, if there's no objections to this feature / > implementation, the style(9) or the usage of -t. > -- > Mel Hi, I've cleaned up original patch: * fixed style and some bugs * as suggested changed it to use expand_number * implemented support for negative threshold values I find the patch very useful. Does it look ok to be commited, or should I file a PR so it won't get lost once again. Example usage: src/sys/crypto % du -ht 100k 137K ./des 482K . src/sys/crypto % du -A -ht +100k 129K ./des 446K . src/sys/crypto % du -ht -100k 56K ./camellia 11K ./salsa20 38K ./sha2 9.0K ./rc4 68K ./des/arch/i386 70K ./des/arch 88K ./rijndael 37K ./via 8.0K ./hmac 36K ./blowfish/arch/i386 37K ./blowfish/arch 85K ./blowfish --xHFwDpU9dbj6ez1V Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="du-threshold.path.txt" diff --git a/usr.bin/du/du.1 b/usr.bin/du/du.1 index af2ff84..b0e1748 100644 --- a/usr.bin/du/du.1 +++ b/usr.bin/du/du.1 @@ -42,7 +42,7 @@ .Nm .Op Fl A .Op Fl H | L | P -.Op Fl a | s | d Ar depth +.Op Fl a | s | d Ar depth | t Ar threshold .Op Fl c .Op Fl l .Op Fl h | k | m | B Ar blocksize @@ -107,6 +107,14 @@ This option exists solely for conformance with Display an entry for each specified file. (Equivalent to .Fl d Li 0 ) +.It Fl t Ar threshold +Display only entries for which size exceeds +.Ar threshold . +If +.Ar threshold +is negative, display only entries for which size is less then absolute +value of +.Ar threshold . .It Fl d Ar depth Display an entry for all files and directories .Ar depth diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c index 63677f5..ff62c5b 100644 --- a/usr.bin/du/du.c +++ b/usr.bin/du/du.c @@ -90,6 +90,7 @@ main(int argc, char *argv[]) FTS *fts; FTSENT *p; off_t savednumber, curblocks; + int64_t threshold, threshold_sign; int ftsoptions; int listall; int depth; @@ -106,12 +107,14 @@ main(int argc, char *argv[]) save = argv; ftsoptions = 0; savednumber = 0; + threshold = 0; + threshold_sign = 1; cblocksize = DEV_BSIZE; blocksize = 0; depth = INT_MAX; SLIST_INIT(&ignores); - while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrx")) != -1) + while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrt:x")) != -1) switch (ch) { case 'A': Aflag = 1; @@ -179,6 +182,14 @@ main(int argc, char *argv[]) break; case 'r': /* Compatibility. */ break; + case 't' : + if (expand_number(optarg, &threshold) != 0 || + threshold == 0) { + warnx("invalid threshold: %s", optarg); + usage(); + } else if (threshold < 0) + threshold_sign = -1; + break; case 'x': ftsoptions |= FTS_XDEV; break; @@ -248,6 +259,10 @@ main(int argc, char *argv[]) blocksize /= DEV_BSIZE; } + if (threshold != 0) + threshold = howmany(threshold / DEV_BSIZE * cblocksize, + blocksize); + rval = 0; (void)signal(SIGINFO, siginfo); @@ -271,7 +286,9 @@ main(int argc, char *argv[]) p->fts_parent->fts_bignum += p->fts_bignum += curblocks; - if (p->fts_level <= depth) { + if (p->fts_level <= depth && threshold <= + threshold_sign * howmany(p->fts_bignum * + cblocksize, blocksize)) { if (hflag) { prthumanval(p->fts_bignum); (void)printf("\t%s\n", p->fts_path); --xHFwDpU9dbj6ez1V--