Skip to content

Commit

Permalink
replace profiling script with context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed Aug 8, 2014
1 parent 4a4e787 commit 449d74c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 14 additions & 0 deletions amodem/profiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import cProfile
import contextlib


@contextlib.contextmanager
def save(filename=None):
if filename:
pr = cProfile.Profile()
pr.enable()
yield
pr.disable()
pr.dump_stats(filename)
else:
yield
5 changes: 4 additions & 1 deletion amodem/recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from . import common
from . import config
from . import ecc
from . import profiling

modem = sigproc.MODEM(config)

Expand Down Expand Up @@ -290,9 +291,11 @@ def main(args):
default=sys.stdin)
p.add_argument('-o', '--output', type=argparse.FileType('wb'),
default=sys.stdout)
p.add_argument('-p', '--profile', type=str)
args = p.parse_args()
try:
main(args)
with profiling.save(filename=args.profile):
main(args)
except Exception as e:
log.exception(e)
finally:
Expand Down
5 changes: 0 additions & 5 deletions scripts/profile.sh

This file was deleted.

0 comments on commit 449d74c

Please sign in to comment.