Skip to content

Commit 9c7e86b

Browse files
committed
add timing logic+output to s3_cache.py
1 parent 4c2626f commit 9c7e86b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ before_install:
77
- if [ "$TWBS_TEST" = validate-html ]; then echo "ruby=$(basename $(rvm gemdir)) jekyll=$JEKYLL_VERSION" > pseudo_Gemfile.lock; fi
88
install:
99
- time npm install -g grunt-cli
10-
- time ./test-infra/s3_cache.py download 'npm packages' test-infra/npm-shrinkwrap.canonical.json ./node_modules || time ./test-infra/uncached-npm-install.sh
11-
- if [ "$TWBS_TEST" = validate-html ]; then time ./test-infra/s3_cache.py download rubygems pseudo_Gemfile.lock $(rvm gemdir) || gem install -N jekyll -v $JEKYLL_VERSION; fi
10+
- ./test-infra/s3_cache.py download 'npm packages' test-infra/npm-shrinkwrap.canonical.json ./node_modules || time ./test-infra/uncached-npm-install.sh
11+
- if [ "$TWBS_TEST" = validate-html ]; then ./test-infra/s3_cache.py download rubygems pseudo_Gemfile.lock $(rvm gemdir) || time gem install -N jekyll -v $JEKYLL_VERSION; fi
1212
after_script:
13-
- if [ "$TWBS_TEST" = core ]; then time ./test-infra/s3_cache.py upload 'npm packages' test-infra/npm-shrinkwrap.canonical.json ./node_modules; fi
14-
- if [ "$TWBS_TEST" = validate-html ]; then time ./test-infra/s3_cache.py upload rubygems pseudo_Gemfile.lock $(rvm gemdir); fi
13+
- if [ "$TWBS_TEST" = core ]; then ./test-infra/s3_cache.py upload 'npm packages' test-infra/npm-shrinkwrap.canonical.json ./node_modules; fi
14+
- if [ "$TWBS_TEST" = validate-html ]; then ./test-infra/s3_cache.py upload rubygems pseudo_Gemfile.lock $(rvm gemdir); fi
1515
env:
1616
global:
1717
- JEKYLL_VERSION: 1.5.0

test-infra/s3_cache.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from os.path import isfile, dirname, basename, abspath
77
from hashlib import sha256
88
from subprocess import check_call as run
9+
from contextlib import contextmanager
10+
from datetime import datetime
911

1012
from boto.s3.connection import S3Connection
1113
from boto.s3.key import Key
@@ -20,6 +22,15 @@
2022
raise SystemExit("TWBS_S3_BUCKET environment variable not set!")
2123

2224

25+
@contextmanager
26+
def timer():
27+
start = datetime.utcnow()
28+
yield
29+
end = datetime.utcnow()
30+
elapsed = end - start
31+
print("\tDone. Took", int(elapsed.total_seconds()), "seconds.")
32+
33+
2334
def _sha256_of_file(filename):
2435
hasher = sha256()
2536
with open(filename, 'rb') as input_file:
@@ -47,19 +58,22 @@ def _tarball_filename_for(directory):
4758

4859
def _create_tarball(directory):
4960
print("Creating tarball of {}...".format(directory))
50-
run(['tar', '-czf', _tarball_filename_for(directory), '-C', dirname(directory), basename(directory)])
61+
with timer():
62+
run(['tar', '-czf', _tarball_filename_for(directory), '-C', dirname(directory), basename(directory)])
5163

5264

5365
def _extract_tarball(directory):
5466
print("Extracting tarball of {}...".format(directory))
55-
run(['tar', '-xzf', _tarball_filename_for(directory), '-C', dirname(directory)])
67+
with timer():
68+
run(['tar', '-xzf', _tarball_filename_for(directory), '-C', dirname(directory)])
5669

5770

5871
def download(directory):
5972
_delete_file_quietly(NEED_TO_UPLOAD_MARKER)
6073
try:
6174
print("Downloading {} tarball from S3...".format(friendly_name))
62-
key.get_contents_to_filename(_tarball_filename_for(directory))
75+
with timer():
76+
key.get_contents_to_filename(_tarball_filename_for(directory))
6377
except S3ResponseError as err:
6478
open(NEED_TO_UPLOAD_MARKER, 'a').close()
6579
print(err)
@@ -72,7 +86,8 @@ def download(directory):
7286
def upload(directory):
7387
_create_tarball(directory)
7488
print("Uploading {} tarball to S3... ({})".format(friendly_name, _tarball_size(directory)))
75-
key.set_contents_from_filename(_tarball_filename_for(directory))
89+
with timer():
90+
key.set_contents_from_filename(_tarball_filename_for(directory))
7691
print("{} cache successfully updated.".format(friendly_name))
7792
_delete_file_quietly(NEED_TO_UPLOAD_MARKER)
7893

0 commit comments

Comments
 (0)