diff options
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 1cc74ed546..f688f7dd68 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -1418,6 +1418,34 @@ def cpu_count(): | |||
1418 | def nonblockingfd(fd): | 1418 | def nonblockingfd(fd): |
1419 | fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) | 1419 | fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) |
1420 | 1420 | ||
1421 | def profile_function(profile, function, output_fn, process=True): | ||
1422 | """Common function to profile a code block and optionally process the | ||
1423 | output using or processing function. | ||
1424 | |||
1425 | Arguments: | ||
1426 | |||
1427 | - ``profile``: a boolean saying whether to enable profiling or not | ||
1428 | - ``function``: the function call to profile/run | ||
1429 | - ``outputfn``: where to write the profiling data | ||
1430 | - ``process``: whether to process the profiling data and write a report | ||
1431 | |||
1432 | Returns the wrapped function return value | ||
1433 | """ | ||
1434 | if profile: | ||
1435 | try: | ||
1436 | import cProfile as profile | ||
1437 | except: | ||
1438 | import profile | ||
1439 | prof = profile.Profile() | ||
1440 | ret = profile.Profile.runcall(prof, function) | ||
1441 | prof.dump_stats(output_fn) | ||
1442 | if process: | ||
1443 | process_profilelog(output_fn) | ||
1444 | serverlog("Raw profiling information saved to %s and processed statistics to %s.processed" % (output_fn, output_fn)) | ||
1445 | return ret | ||
1446 | else: | ||
1447 | return function() | ||
1448 | |||
1421 | def process_profilelog(fn, pout = None): | 1449 | def process_profilelog(fn, pout = None): |
1422 | # Either call with a list of filenames and set pout or a filename and optionally pout. | 1450 | # Either call with a list of filenames and set pout or a filename and optionally pout. |
1423 | if not pout: | 1451 | if not pout: |