#!/usr/bin/env python # -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil -*- r'''Report on space used by readahead Report the space used and the largest files by the /etc/readahead.d/* files. ''' __author__ = 'Tony Nelson' __email__ = 'tonynelson@georgeanelson.com' __url__ = 'http://georgeanelson.com/readaheadsize.py' __copyright__ = 'Copyright 2007 by George A. Nelson. All rights reserved.' __license__ = 'GPL' __date__ = '20 Feb 2007' __version__ = '0.1.0' import os import sys rd = '/etc/readahead.d/' min_size = 4*1024*1024 rfl = os.listdir(rd) rfl = [f for f in rfl if not f.endswith('~')] rfl.sort() for rfn in rfl: print '%-30s' % rfn, sizes = [] missing = [] for fn in open(os.path.join(rd, rfn), 'r'): fn = fn[:-1] size = 0 if fn[0].isdigit(): size, fn = fn.split(' ') size = int(size) if os.path.exists(fn): if size == 0: size = os.stat(fn).st_size sizes.append((fn, size)) else: missing.append(fn) sizes.sort(key=lambda v: -v[1]) tot = sum(size[1] for size in sizes) print '%4d files (%4d missing) %4d MB used' % ( len(sizes)+len(missing), len(missing), tot/(1024*1024) ) for i in xrange(min(len(sizes),15)): fn, size = sizes[i] if size < min_size: break print ' %6d KB %s' % (size/1024, fn) print