summaryrefslogtreecommitdiffstats
path: root/scripts/tiny/dirsize.py
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2013-10-28 14:32:40 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-10-29 10:41:39 +0000
commit91c00fb70e787a13a5dca9865f7d59fcd1633eda (patch)
treee1ba1286104ea4564b207ea51cc4dbbad5080d1e /scripts/tiny/dirsize.py
parent7f1b40b56ada32393a53e7da042add3d7f46e09e (diff)
downloadpoky-91c00fb70e787a13a5dca9865f7d59fcd1633eda.tar.gz
scripts: Add ksize.py and dirsize.py
Fixes [YOCTO #5388] These scripts can be useful when working to reduce the size of the Linux kernel and the root filesystem. ksize.py displays the kernel build size by the built-in.o files. dirsize.py displays the various sizes of the components of the root directory. (From OE-Core rev: 26099eb8ac855aa08e5e1a307affe42fe5f43859) Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/tiny/dirsize.py')
-rwxr-xr-xscripts/tiny/dirsize.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/scripts/tiny/dirsize.py b/scripts/tiny/dirsize.py
new file mode 100755
index 0000000000..40ff4ab895
--- /dev/null
+++ b/scripts/tiny/dirsize.py
@@ -0,0 +1,93 @@
1#!/usr/bin/env python
2#
3# Copyright (c) 2011, Intel Corporation.
4# All rights reserved.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19#
20#
21# Display details of the root filesystem size, broken up by directory.
22# Allows for limiting by size to focus on the larger files.
23#
24# Author: Darren Hart <dvhart@linux.intel.com>
25#
26
27import os
28import sys
29import stat
30
31class Record:
32 def create(path):
33 r = Record(path)
34
35 s = os.lstat(path)
36 if stat.S_ISDIR(s.st_mode):
37 for p in os.listdir(path):
38 pathname = path + "/" + p
39 ss = os.lstat(pathname)
40 if not stat.S_ISLNK(ss.st_mode):
41 r.records.append(Record.create(pathname))
42 r.size += r.records[-1].size
43 r.records.sort(reverse=True)
44 else:
45 r.size = os.lstat(path).st_size
46
47 return r
48 create = staticmethod(create)
49
50 def __init__(self, path):
51 self.path = path
52 self.size = 0
53 self.records = []
54
55 def __cmp__(this, that):
56 if that is None:
57 return 1
58 if not isinstance(that, Record):
59 raise TypeError
60 if len(this.records) > 0 and len(that.records) == 0:
61 return -1
62 if len(this.records) == 0 and len(that.records) > 0:
63 return 1
64 if this.size < that.size:
65 return -1
66 if this.size > that.size:
67 return 1
68 return 0
69
70 def show(self, minsize):
71 total = 0
72 if self.size <= minsize:
73 return 0
74 print "%10d %s" % (self.size, self.path)
75 for r in self.records:
76 total += r.show(minsize)
77 if len(self.records) == 0:
78 total = self.size
79 return total
80
81
82def main():
83 minsize = 0
84 if len(sys.argv) == 2:
85 minsize = int(sys.argv[1])
86 rootfs = Record.create(".")
87 total = rootfs.show(minsize)
88 print "Displayed %d/%d bytes (%.2f%%)" % \
89 (total, rootfs.size, 100 * float(total) / rootfs.size)
90
91
92if __name__ == "__main__":
93 main()