All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: poky <poky@yoctoproject.org>
Subject: Quick hack for profiling tasks
Date: Tue, 01 Feb 2011 00:28:00 +0000	[thread overview]
Message-ID: <1296520080.13501.15996.camel@rex> (raw)

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:



             reply	other threads:[~2011-02-01  0:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01  0:28 Richard Purdie [this message]
2011-02-01  0:40 ` Quick hack for profiling tasks 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296520080.13501.15996.camel@rex \
    --to=richard.purdie@linuxfoundation.org \
    --cc=poky@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.