[poky] Quick hack for profiling tasks
Richard Purdie
richard.purdie at linuxfoundation.org
Mon Jan 31 16:28:00 PST 2011
Hi,
One thing that is bugging me whilst I've been debugging some issues
we're having with the libc/libgcc package dependency issue is how long
do_package takes for libc. The question is where does it spend the time?
Answer, I have no idea.
I hacked together the patch below to find out. Its ugly and uses the
boilerplate profiling code from cooker, cut and pasted here to profile
the actual tasks that run.
I've yet to look at the results but it should allow us to optimise the
python tasks a bit if we can see where they spend time. I'm hoping this
lets others look at that too and also it give us some hints as to how we
might improve the core when turning on profiling in bitbake.
Cheers,
Richard
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 42d1726..02c0a08 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -365,7 +365,36 @@ def exec_task(fn, task, d):
if d.getVarFlag(task, "quieterrors") is not None:
quieterr = True
- return _exec_task(fn, task, d, quieterr)
+ profbasename = os.path.basename(fn) + "-" + task
+ try:
+ import cProfile as profile
+ except:
+ import profile
+ prof = profile.Profile()
+
+ ret = profile.Profile.runcall(prof, _exec_task, fn, task, d, quieterr)
+
+ prof.dump_stats("profile-%s.log" % (profbasename))
+
+ # Redirect stdout to capture profile information
+ pout = open('profile-%s.log.processed' % (profbasename), 'w')
+ so = sys.stdout.fileno()
+ orig_so = os.dup(sys.stdout.fileno())
+ os.dup2(pout.fileno(), so)
+
+ import pstats
+ p = pstats.Stats('profile-%s.log' % (profbasename))
+ p.sort_stats('time')
+ p.print_stats()
+ p.print_callers()
+ p.sort_stats('cumulative')
+ p.print_stats()
+
+ os.dup2(orig_so, so)
+ pout.flush()
+ pout.close()
+
+ return ret
except Exception:
from traceback import format_exc
if not quieterr:
More information about the poky
mailing list