[bitbake-devel] [PATCH] build.py: record time spent executing each function

chris.laplante at agilent.com chris.laplante at agilent.com
Sun Jan 19 02:14:38 UTC 2020


> In order to have a quick way to see if optimizing some task function
> actually has an effect, add a single line to the log file for each
> function executed listing the wallclock, system and user time
> spent. That can also help figure out which parts of a recipe is taking
> the longest and hence find places that might be worth looking at.
> 
> bitbake already has the --profile/-P option, but that produces an
> enourmous amount of output, and AFAICT only concerns python code, so
> won't help finding suboptimal shell functions.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
> ---
>  lib/bb/build.py | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/lib/bb/build.py b/lib/bb/build.py
> index 3d9cc10c..945efeae 100644
> --- a/lib/bb/build.py
> +++ b/lib/bb/build.py
> @@ -19,6 +19,7 @@ import shlex
>  import glob
>  import time
>  import stat
> +import resource
>  import bb
>  import bb.msg
>  import bb.process
> @@ -172,6 +173,14 @@ class StdoutNoopContextManager:
>      def name(self):
>          return sys.stdout.name
> 
> +def _get_times():
> +    wall = time.monotonic()
> +    self = resource.getrusage(resource.RUSAGE_SELF)
> +    children = resource.getrusage(resource.RUSAGE_CHILDREN)
> +    user = self.ru_utime + children.ru_utime
> +    sys =  self.ru_stime + children.ru_stime
> +
> +    return (wall, user, sys)

Not sure why you sent this to me, to be honest. But while I'm here... I don't think using variable names like "self" and "sys" is a good idea in Python. May lead to confusion.

Chris


More information about the bitbake-devel mailing list