| 1 | #!/usr/bin/env python2
|
| 2 | """
|
| 3 | virtual_memory.py
|
| 4 | """
|
| 5 |
|
| 6 | import csv
|
| 7 | import os
|
| 8 | import sys
|
| 9 | import re
|
| 10 |
|
| 11 | # VmSize, VmData might be interesting too.
|
| 12 | METRIC_RE = re.compile('^(VmPeak|VmRSS):\s*(\d+)')
|
| 13 |
|
| 14 |
|
| 15 | def main(argv):
|
| 16 | action = argv[1]
|
| 17 |
|
| 18 | if action == 'baseline':
|
| 19 | input_dirs = argv[2:]
|
| 20 |
|
| 21 | out = csv.writer(sys.stdout)
|
| 22 | out.writerow(('host', 'shell_name', 'shell_hash', 'metric_name',
|
| 23 | 'metric_value'))
|
| 24 |
|
| 25 | # Dir name looks like "$host.$job_id"
|
| 26 | for input_dir in input_dirs:
|
| 27 | d = os.path.basename(input_dir)
|
| 28 | host, job_id = d.split('.')
|
| 29 | for name in os.listdir(input_dir):
|
| 30 | n, _ = os.path.splitext(name)
|
| 31 | shell_name, shell_hash = n.split('-')
|
| 32 | path = os.path.join(input_dir, name)
|
| 33 | with open(path) as f:
|
| 34 | for line in f:
|
| 35 | m = METRIC_RE.match(line)
|
| 36 | if m:
|
| 37 | name, value = m.groups()
|
| 38 | row = (host, shell_name, shell_hash, name, value)
|
| 39 | out.writerow(row)
|
| 40 |
|
| 41 | else:
|
| 42 | raise RuntimeError('Invalid action %r' % action)
|
| 43 |
|
| 44 |
|
| 45 | if __name__ == '__main__':
|
| 46 | try:
|
| 47 | main(sys.argv)
|
| 48 | except RuntimeError as e:
|
| 49 | print >> sys.stderr, 'FATAL: %s' % e
|
| 50 | sys.exit(1)
|