diff options
author | Chris Laplante <chris.laplante@agilent.com> | 2020-09-09 12:55:30 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-09-09 23:40:02 +0100 |
commit | 42172900af06baeee559d33b150d5febdf8e960a (patch) | |
tree | 3e67b99d4766a6da42e07e3ae0adb69503353c96 /lib/bb/utils.py | |
parent | 0457482e252f216618a6fccad0030fcd6c5a304f (diff) | |
download | bitbake-contrib-42172900af06baeee559d33b150d5febdf8e960a.tar.gz |
utils: process_profilelog: use context manager
Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r-- | lib/bb/utils.py | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index e51b8ca50..2d4b258b8 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -1071,21 +1071,20 @@ def process_profilelog(fn, pout = None): # Either call with a list of filenames and set pout or a filename and optionally pout. if not pout: pout = fn + '.processed' - pout = open(pout, 'w') - - import pstats - if isinstance(fn, list): - p = pstats.Stats(*fn, stream=pout) - else: - p = pstats.Stats(fn, stream=pout) - p.sort_stats('time') - p.print_stats() - p.print_callers() - p.sort_stats('cumulative') - p.print_stats() - - pout.flush() - pout.close() + + with open(pout, 'w') as pout: + import pstats + if isinstance(fn, list): + p = pstats.Stats(*fn, stream=pout) + else: + p = pstats.Stats(fn, stream=pout) + p.sort_stats('time') + p.print_stats() + p.print_callers() + p.sort_stats('cumulative') + p.print_stats() + + pout.flush() # # Was present to work around multiprocessing pool bugs in python < 2.7.3 |