All of lore.kernel.org
 help / color / mirror / Atom feed
* Quick hack for profiling tasks
@ 2011-02-01  0:28 Richard Purdie
  2011-02-01  0:40 ` Richard Purdie
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Purdie @ 2011-02-01  0:28 UTC (permalink / raw)
  To: poky

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:



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-02-03 11:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-01  0:28 Quick hack for profiling tasks Richard Purdie
2011-02-01  0:40 ` Richard Purdie
2011-02-01  1:43   ` Mark Hatle
2011-02-01 11:05     ` Richard Purdie
2011-02-01 15:38       ` Mark Hatle
2011-02-02 14:28         ` Richard Purdie
2011-02-03 11:22           ` Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.