summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-16 14:44:45 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-18 13:17:10 +0000
commitcf72cec468f0fba30aac13e5765cab4aa8ea50b2 (patch)
treebb7b3f0de2e4b0fbe30bebe3be7ba495437db561
parentb58049b4e70f896ec60f3f35c28e55b15db3039c (diff)
downloadpoky-cf72cec468f0fba30aac13e5765cab4aa8ea50b2.tar.gz
bitbake: codeparser: Avoid log bufer overhead in cache case
Creating the new log instances triggers a lot of python logging overhead in a commonly called function (about 600,000 for parsing OE-Core). We only need the log functionality if we're parsing, not if we just hit from the cache. Therefore defer the log setup overhead until we know it is a cache miss. Whilst this complicates the code slightly, the performance gain is worth it as for parsing OE-Core we drop 60 million funciton calls (from 225 overall). (Bitbake rev: ac868167ad854f9bb32dcb2e63528870547805a7) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/codeparser.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py
index 0cec452c00..3b3c3b41ff 100644
--- a/bitbake/lib/bb/codeparser.py
+++ b/bitbake/lib/bb/codeparser.py
@@ -195,6 +195,10 @@ class BufferedLogger(Logger):
195 self.target.handle(record) 195 self.target.handle(record)
196 self.buffer = [] 196 self.buffer = []
197 197
198class DummyLogger():
199 def flush(self):
200 return
201
198class PythonParser(): 202class PythonParser():
199 getvars = (".getVar", ".appendVar", ".prependVar", "oe.utils.conditional") 203 getvars = (".getVar", ".appendVar", ".prependVar", "oe.utils.conditional")
200 getvarflags = (".getVarFlag", ".appendVarFlag", ".prependVarFlag") 204 getvarflags = (".getVarFlag", ".appendVarFlag", ".prependVarFlag")
@@ -276,7 +280,9 @@ class PythonParser():
276 self.contains = {} 280 self.contains = {}
277 self.execs = set() 281 self.execs = set()
278 self.references = set() 282 self.references = set()
279 self.log = BufferedLogger('BitBake.Data.PythonParser', logging.DEBUG, log) 283 self._log = log
284 # Defer init as expensive
285 self.log = DummyLogger()
280 286
281 self.unhandled_message = "in call of %s, argument '%s' is not a string literal" 287 self.unhandled_message = "in call of %s, argument '%s' is not a string literal"
282 self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message) 288 self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message)
@@ -303,6 +309,9 @@ class PythonParser():
303 self.contains[i] = set(codeparsercache.pythoncacheextras[h].contains[i]) 309 self.contains[i] = set(codeparsercache.pythoncacheextras[h].contains[i])
304 return 310 return
305 311
312 # Need to parse so take the hit on the real log buffer
313 self.log = BufferedLogger('BitBake.Data.PythonParser', logging.DEBUG, self._log)
314
306 # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though 315 # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though
307 node = "\n" * int(lineno) + node 316 node = "\n" * int(lineno) + node
308 code = compile(check_indent(str(node)), filename, "exec", 317 code = compile(check_indent(str(node)), filename, "exec",
@@ -321,7 +330,11 @@ class ShellParser():
321 self.funcdefs = set() 330 self.funcdefs = set()
322 self.allexecs = set() 331 self.allexecs = set()
323 self.execs = set() 332 self.execs = set()
324 self.log = BufferedLogger('BitBake.Data.%s' % name, logging.DEBUG, log) 333 self._name = name
334 self._log = log
335 # Defer init as expensive
336 self.log = DummyLogger()
337
325 self.unhandled_template = "unable to handle non-literal command '%s'" 338 self.unhandled_template = "unable to handle non-literal command '%s'"
326 self.unhandled_template = "while parsing %s, %s" % (name, self.unhandled_template) 339 self.unhandled_template = "while parsing %s, %s" % (name, self.unhandled_template)
327 340
@@ -340,6 +353,9 @@ class ShellParser():
340 self.execs = set(codeparsercache.shellcacheextras[h].execs) 353 self.execs = set(codeparsercache.shellcacheextras[h].execs)
341 return self.execs 354 return self.execs
342 355
356 # Need to parse so take the hit on the real log buffer
357 self.log = BufferedLogger('BitBake.Data.%s' % self._name, logging.DEBUG, self._log)
358
343 self._parse_shell(value) 359 self._parse_shell(value)
344 self.execs = set(cmd for cmd in self.allexecs if cmd not in self.funcdefs) 360 self.execs = set(cmd for cmd in self.allexecs if cmd not in self.funcdefs)
345 361