summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/event.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-20 13:22:19 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-22 00:02:05 +0000
commit0381b78aa4dfc0d338fba69502e8f03a0c0f21e7 (patch)
tree6d9a33949354cb9824c1a8fcabea1422ac692bb9 /bitbake/lib/bb/event.py
parentc61c1eb26a082c81473a45977cad5f811d2cf598 (diff)
downloadpoky-0381b78aa4dfc0d338fba69502e8f03a0c0f21e7.tar.gz
bitbake: event/utils/methodpool: Add a cache of compiled code objects
With the addition of function line number handling, the overhead of the compile functions is no longer negligible. We tend to compile the same pieces of code over and over again so wrapping a cache around this is beneficial and removes the overhead of line numbered functions. Life cycle of a cache using a global like this is in theory problematic although in reality unlikely to be an issue. It can be dealt with if/as/when we deal with the other global caches. (Bitbake rev: 98d7002d1dca4b62042e1589fd5b9b3805d57f7a) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/event.py')
-rw-r--r--bitbake/lib/bb/event.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index bd2b0a4b05..5ffe89eae3 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -31,6 +31,7 @@ except ImportError:
31import logging 31import logging
32import atexit 32import atexit
33import traceback 33import traceback
34import ast
34import bb.utils 35import bb.utils
35import bb.compat 36import bb.compat
36import bb.exceptions 37import bb.exceptions
@@ -189,13 +190,15 @@ def register(name, handler, mask=None, filename=None, lineno=None):
189 if isinstance(handler, basestring): 190 if isinstance(handler, basestring):
190 tmp = "def %s(e):\n%s" % (name, handler) 191 tmp = "def %s(e):\n%s" % (name, handler)
191 try: 192 try:
192 import ast 193 code = bb.methodpool.compile_cache(tmp)
193 if filename is None: 194 if not code:
194 filename = "%s(e)" % name 195 if filename is None:
195 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST) 196 filename = "%s(e)" % name
196 if lineno is not None: 197 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST)
197 ast.increment_lineno(code, lineno-1) 198 if lineno is not None:
198 code = compile(code, filename, "exec") 199 ast.increment_lineno(code, lineno-1)
200 code = compile(code, filename, "exec")
201 bb.methodpool.compile_cache_add(tmp, code)
199 except SyntaxError: 202 except SyntaxError:
200 logger.error("Unable to register event handler '%s':\n%s", name, 203 logger.error("Unable to register event handler '%s':\n%s", name,
201 ''.join(traceback.format_exc(limit=0))) 204 ''.join(traceback.format_exc(limit=0)))