Advertisement
GenuineSounds

MCLogTimes

Jan 7th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import unicode_literals
  4. import re
  5. import sys
  6. from collections import Counter
  7.  
  8. import click
  9.  
  10. @click.command('mclog', help='')
  11. @click.argument('path')
  12. def cli(path):
  13.     with open(path, 'r') as log:
  14.         counter = Counter()
  15.         for line in log:
  16.             res = re.search(r'Bar (?:Step|\w+): (.*?) took (\d+\.\d+)s', line)
  17.             if res:
  18.                 what = res.group(1)
  19.                 time = float(res.group(2))
  20.  
  21.                 if 'Reloading Texture Manager' in what:
  22.                     what = 'Reloading Texture Manager'
  23.  
  24.                 if ' - ' in what:
  25.                     what = what.split(' - ', 2)[1]
  26.  
  27.                 counter[what] += time
  28.  
  29.     print('╒═══════════════════════════════════════════════════════════╕')
  30.     print('│                  Minecraft Startup Times                  │')
  31.     print('╞════════════════════════════════════════════════╤══════════╡')
  32.     for what, time in counter.most_common(30):
  33.         print('│ {:46s} │ {:8.3f} │'.format(what, time))
  34.  
  35.     print('│ {:46s} │ {:8.3f} │'.format('Total*', sum(counter.values())))
  36.     print('└────────────────────────────────────────────────┴──────────┘')
  37.  
  38. if __name__ == '__main__':
  39.     cli(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement