diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-04-10 08:01:34 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-04-10 08:02:31 +0000 |
commit | e00ec2e51e69c91e6879496c5864b57d8288af19 (patch) | |
tree | 8c668ef829ec10a62eacc0872eaae23ad0a1e9c3 /extract-build-times.py | |
parent | 8a9d16e11494b0671480719ede416c0c2b555a3b (diff) | |
download | morph-e00ec2e51e69c91e6879496c5864b57d8288af19.tar.gz |
Add an extract-build-times.py application.
This app takes a morph cache directory and lists the build times of
all cached chunks.
Diffstat (limited to 'extract-build-times.py')
-rw-r--r-- | extract-build-times.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/extract-build-times.py b/extract-build-times.py new file mode 100644 index 00000000..9b1384de --- /dev/null +++ b/extract-build-times.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# +# Copyright (C) 2012 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import cliapp +import glob +import json +import os +import re +import StringIO + + +class ExtractBuildTimes(cliapp.Application): + + '''Extracts build times of chunks in a morph cache directory. + + Given a morph cache directory as the first argument, this app finds all + cached chunks, loads their meta data and prints their build times. + + ''' + + def process_args(self, args): + cachedir = args[0] + + def chunk_hash(chunk): + short = re.split('\.', chunk) + return os.path.basename(short[-3]) + + def chunk_name(chunk): + short = re.split('\.', chunk) + return short[-1] + + chunks = glob.glob(os.path.join(cachedir, '*.chunk.*')) + items = [] + + for chunk in chunks: + hash = chunk_hash(chunk) + metafile = os.path.join(cachedir, '%s.meta' % hash) + with open(metafile) as f: + data = f.read() + io = StringIO.StringIO(data) + metainfo = json.load(io) + time = metainfo['build-times']['overall-build']['delta'] + minutes = float(time) / 60.0 + items.append((chunk_name(chunk), minutes)) + + items = sorted(items, key=lambda x: x[1], reverse=True) + + for name, time in items: + print '%30s: %3.0f mins' % (name, time) + + +if __name__ == '__main__': + ExtractBuildTimes().run() |