summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-07-16 15:56:38 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-07-17 10:45:57 +0100
commite16dd314450cb2b85e4984c17fa60403b662ef8c (patch)
tree0e3276eae79d9f130183188df5fa64698e66b466 /bitbake/lib/bb/utils.py
parent6933d4b57ef9b2b6bbc8c97069a4f54e46eb3e4d (diff)
downloadpoky-e16dd314450cb2b85e4984c17fa60403b662ef8c.tar.gz
bitbake: cooker/process/utils: Create profiling common function to remove code duplication
We have code duplication in the way we handle profiling of code sections. Create a common function in utils which covers this. The main loop and idle loop profile files were also reversed. Fix this and the naming, removing a couple of unused variables containing the profile log names in the process too. (Bitbake rev: b4f6bae97ac9607420fc49fd4c9e957d89c9a5f3) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py28
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():
1418def nonblockingfd(fd): 1418def 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
1421def 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
1421def process_profilelog(fn, pout = None): 1449def 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: