from docopt import docopt
from vmtouchparser import parse

usage = \
"""
diskwarmer. Heats up files into the disk cache from previously
      produced vmtouch -v report.

Usage:
  warm [options] sort <report>

Options:
  -h --help        Show this screen.
  --version        Show version.
"""

def do_sort(path):
    records = parse(path)
    density = [(float(x.resident)/x.size, x.name) for x in records]
    for (x, name) in sorted(density, reverse=True):
        print x, name

def main():
    args = docopt(usage)
    if args['sort']:
        return do_sort(args['<report>'])

if __name__ == "__main__":
    main()


@@ -295,186 +295,470 @@
 def 
-do_sort(path):%0A    records = parse(path)%0A    density = %5B(float(x.resident)/x.size, x.name) for x in records%5D%0A    for (x, name) in sorted(density, reverse=True):%0A        print x, 
+sort_by_mapped_ratio(records):%0A  return sorted(records, key=lambda x: x.ratio, reverse=True)%0A%0Adef do_sort(path):%0A    records = parse(path)%0A    total_resident = reduce(lambda t,x: t+x.resident, records, 0)%0A    total_size = reduce(lambda t,x: t+x.size, records, 0)%0A    sum_resident = 0%0A    sum_size = 0%0A    for x in sort_by_mapped_ratio(records):%0A        sum_resident += x.resident%0A        sum_size += x.size%0A        print '%5B'+x.pic+'%5D', sum_resident, sum_size, x.
 name

Improve sort verb.