Skip to contentSkip to conversation

bitbake: add event masks

PATCH In review Bogdan Marinescu 3 participants 3 messages May 31, 2013 – Jun 14, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake: add event masks

Add more arguments to an "addhandler" command. Each argument (after the first one, which is the name of the handler) is the name of an event class that the handler wants to be notified on. "*" is a shortcut for "listen to all events". This changes the current behaviour of bitbake, which is to broadcast all events to all listeners; instead, only the handlers that registered themselves to an event with "addhandler" will receive that event. This should improve performance, although only performance measurements will be confirm or deny this claim.
This is part of the fix for YOCTO #3812, but implements filtering only for class event handlers; the other part (events filter for UIs) will be the subject of a different patch.

---
 bitbake/lib/bb/cookerdata.py                       |    3 +-
 bitbake/lib/bb/event.py                            |   23 +++++--
 bitbake/lib/bb/parse/ast.py                        |   18 +++--
 meta/classes/base.bbclass                          |    9 ++-
 meta/classes/bugzilla.bbclass                      |    2 +-
 meta/classes/buildhistory.bbclass                  |    9 ++-
 meta/classes/buildstats.bbclass                    |    2 +-
 meta/classes/cross.bbclass                         |    5 +-
 meta/classes/distrodata.bbclass                    |   48 +++++++-------
 meta/classes/migrate_localcount.bbclass            |   69 ++++++++++----------
 meta/classes/multilib.bbclass                      |    5 +-
 meta/classes/multilib_global.bbclass               |    2 +-
 meta/classes/native.bbclass                        |    5 +-
 meta/classes/nativesdk.bbclass                     |    5 +-
 meta/classes/packageinfo.bbclass                   |   51 +++++++--------
 meta/classes/prexport.bbclass                      |    2 +-
 meta/classes/primport.bbclass                      |    2 +-
 meta/classes/recipe_sanity.bbclass                 |    5 +-
 meta/classes/sanity.bbclass                        |    2 +-
 meta/classes/tinderclient.bbclass                  |    2 +-
 meta/classes/typecheck.bbclass                     |    9 ++-
 meta/conf/distro/include/csl-versions.inc          |    4 +-
 .../distro/include/tcmode-external-sourcery.inc    |   10 +--
 23 files changed, 141 insertions(+), 151 deletions(-)
bitbake/lib/bb/cookerdata.py +2 -1
index 149878f..4add06a 100644
@@ -251,7 +251,8 @@ class CookerDataBuilder(object):
         # Nomally we only register event handlers at the end of parsing .bb files
         # We register any handlers we've found so far here...
         for var in data.getVar('__BBHANDLERS') or []:
-            bb.event.register(var, data.getVar(var))
+            (name, mask) = var
+            bb.event.register(name, data.getVar(name), mask)
 
         if data.getVar("BB_WORKERCONTEXT", False) is None:
             bb.fetch.fetcher_init(data)
bitbake/lib/bb/event.py +18 -5
index 2826e35..d269c04 100644
@@ -63,6 +63,8 @@ def clean_class_handlers():
 _handlers = clean_class_handlers()
 _ui_handlers = {}
 _ui_handler_seq = 0
+_event_handler_map = {}
+_catchall_handlers = {}
 
 def execute_handler(name, handler, event, d):
     event.data = d
@@ -86,11 +88,14 @@ def fire_class_handlers(event, d):
     if isinstance(event, logging.LogRecord):
         return
 
+    eid = str(event.__class__)[8:-2]
+    evt_hmap = _event_handler_map.get(eid, {})
     for name, handler in _handlers.iteritems():
-        try:
-            execute_handler(name, handler, event, d)
-        except Exception:
-            continue
+        if name in _catchall_handlers or name in evt_hmap:
+            try:
+                execute_handler(name, handler, event, d)
+            except Exception:
+                continue
 
 ui_queue = []
 @atexit.register
@@ -167,7 +172,7 @@ def fire_from_worker(event, d):
     fire_ui_handlers(event, d)
 
 noop = lambda _: None
-def register(name, handler):
+def register(name, handler, mask=[]):
     """Register an Event handler"""
 
     # already registered
@@ -192,6 +197,14 @@ def register(name, handler):
         else:
             _handlers[name] = handler
 
+        if not mask:
+            _catchall_handlers[name] = True
+        else:
+            for m in mask:
+                if _event_handler_map.get(m, None) is None:
+                    _event_handler_map[m] = {}
+                _event_handler_map[m][name] = True
+
         return Registered
 
 def remove(name, handler):
bitbake/lib/bb/parse/ast.py +13 -5
index 713bef1..3e31ba6 100644
@@ -266,9 +266,17 @@ class BBHandlerNode(AstNode):
 
     def eval(self, data):
         bbhands = data.getVar('__BBHANDLERS') or []
-        for h in self.hs:
-            bbhands.append(h)
-            data.setVarFlag(h, "handler", 1)
+        name = self.hs[0]
+        if len(self.hs) == 1:
+            bb.warn("event handler '" + name + "' does not have an event mask")
+            bbhands.append((name, None))
+        else:
+            evlist = self.hs[1:]
+            if '*' in evlist:
+                bbhands.append((name, None))
+            else:
+                bbhands.append((name, evlist))
+        data.setVarFlag(name, "handler", 1)
         data.setVar('__BBHANDLERS', bbhands)
 
 class InheritNode(AstNode):
@@ -320,8 +328,8 @@ def finalize(fn, d, variant = None):
     all_handlers = {}
     for var in d.getVar('__BBHANDLERS') or []:
         # try to add the handler
-        handler = d.getVar(var)
-        bb.event.register(var, handler)
+        (name, mask) = var
+        bb.event.register(name, d.getVar(name), mask)
 
     bb.event.fire(bb.event.RecipePreFinalise(fn), d)
 
meta/classes/base.bbclass +4 -5
index b1642a2..0e7d56f 100644
@@ -32,12 +32,11 @@ def oe_import(d):
         inject(toimport.split(".", 1)[0], imported)
 
 python oe_import_eh () {
-    if isinstance(e, bb.event.ConfigParsed):
-        oe_import(e.data)
-        e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
+    oe_import(e.data)
+    e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
 }
 
-addhandler oe_import_eh
+addhandler oe_import_eh bb.event.ConfigParsed
 
 def lsb_distro_identifier(d):
     adjust = d.getVar('LSB_DISTRO_ADJUST', True)
@@ -298,7 +297,7 @@ def buildcfg_neededvars(d):
     if pesteruser:
         bb.fatal('The following variable(s) were not set: %s\nPlease set them directly, or choose a MACHINE or DISTRO that sets them.' % ', '.join(pesteruser))
 
-addhandler base_eventhandler
+addhandler base_eventhandler bb.event.ConfigParsed bb.event.BuildStarted
 python base_eventhandler() {
     if isinstance(e, bb.event.ConfigParsed):
         e.data.setVar('BB_VERSION', bb.__version__)
meta/classes/bugzilla.bbclass +1 -1
index 006763d..c1dd966 100644
@@ -70,7 +70,7 @@ def bugzilla_add_comment(debug_file, server, args, bug_number, text):
         print >> debug_file, repr(e)
         return False
 
-addhandler bugzilla_eventhandler
+addhandler bugzilla_eventhandler bb.event.MsgNote bb.build.TaskFailed 
 python bugzilla_eventhandler() {
     import glob
     import xmlrpclib, httplib
meta/classes/buildhistory.bbclass +4 -5
index d39408b..ad3f292 100644
@@ -525,13 +525,12 @@ END
 }
 
 python buildhistory_eventhandler() {
-    if isinstance(e, bb.event.BuildCompleted):
-        if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
-            if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
-                bb.build.exec_func("buildhistory_commit", e.data)
+    if e.data.getVar('BUILDHISTORY_FEATURES', True).strip():
+        if e.data.getVar("BUILDHISTORY_COMMIT", True) == "1":
+            bb.build.exec_func("buildhistory_commit", e.data)
 }
 
-addhandler buildhistory_eventhandler
+addhandler buildhistory_eventhandler bb.event.BuildCompleted
 
 
 # FIXME this ought to be moved into the fetcher
meta/classes/buildstats.bbclass +1 -1
index e12e14f..a15d521 100644
@@ -277,5 +277,5 @@ python run_buildstats () {
         file.close()
 }
 
-addhandler run_buildstats
+addhandler run_buildstats bb.event.BuildStarted bb.event.BuildCompleted bb.build.TaskStarted bb.build.TaskSucceeded bb.build.TaskFailed
 
meta/classes/cross.bbclass +1 -4
index eaba4d1..a917d6a 100644
@@ -58,9 +58,6 @@ do_populate_sysroot[sstate-inputdirs] = "${SYSROOT_DESTDIR}/${STAGING_DIR_NATIVE
 do_populate_sysroot[stamp-extra-info] = ""
 
 python cross_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     classextend = e.data.getVar('BBCLASSEXTEND', True) or ""
     if "cross" not in classextend:
         return
@@ -72,7 +69,7 @@ python cross_virtclass_handler () {
     bb.data.setVar("OVERRIDES", e.data.getVar("OVERRIDES", False) + ":virtclass-cross", e.data)
 }
 
-addhandler cross_virtclass_handler
+addhandler cross_virtclass_handler bb.event.RecipePreFinalise
 
 do_install () {
 	oe_runmake 'DESTDIR=${D}' install
meta/classes/distrodata.bbclass +22 -26

73 lines not on this page · raw message

meta/classes/migrate_localcount.bbclass +34 -35

75 lines not on this page · raw message

meta/classes/multilib.bbclass +1 -4
index 4dbec73..bbfe082 100644
@@ -1,7 +1,4 @@
 python multilib_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     cls = e.data.getVar("BBEXTENDCURR", True)
     variant = e.data.getVar("BBEXTENDVARIANT", True)
     if cls != "multilib" or not variant:
@@ -59,7 +56,7 @@ python multilib_virtclass_handler () {
         e.data.setVar("DEFAULTTUNE", newtune)
 }
 
-addhandler multilib_virtclass_handler
+addhandler multilib_virtclass_handler bb.event.RecipePreFinalise
 
 STAGINGCC_prepend = "${BBEXTENDVARIANT}-"
 
meta/classes/multilib_global.bbclass +1 -1
index 85f2d8d..aaf0a7d 100644
@@ -42,5 +42,5 @@ python multilib_virtclass_handler_global () {
                 e.data.setVar("RPROVIDES_%s" % pkg, rprovs)
 }
 
-addhandler multilib_virtclass_handler_global
+addhandler multilib_virtclass_handler_global bb.event.RecipePreFinalise bb.event.RecipeParsed
 
meta/classes/native.bbclass +1 -4
index cd930f0..b4b3e0e 100644
@@ -104,9 +104,6 @@ CLASSOVERRIDE = "class-native"
 PATH_prepend = "${COREBASE}/scripts/native-intercept:"
 
 python native_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     classextend = e.data.getVar('BBCLASSEXTEND', True) or ""
     if "native" not in classextend:
         return
@@ -151,7 +148,7 @@ python native_virtclass_handler () {
     e.data.setVar("OVERRIDES", e.data.getVar("OVERRIDES", False) + ":virtclass-native")
 }
 
-addhandler native_virtclass_handler
+addhandler native_virtclass_handler bb.event.RecipePreFinalise
 
 do_package[noexec] = "1"
 do_packagedata[noexec] = "1"
meta/classes/nativesdk.bbclass +1 -4
index 8b689e7..3c1b71f 100644
@@ -60,9 +60,6 @@ export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${libdir}/pkgconfig"
 export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
 
 python nativesdk_virtclass_handler () {
-    if not isinstance(e, bb.event.RecipePreFinalise):
-        return
-
     pn = e.data.getVar("PN", True)
     if not pn.endswith("-nativesdk") or pn.startswith("nativesdk-"):
         return
@@ -88,6 +85,6 @@ python () {
     clsextend.map_variable("PROVIDES")
 }
 
-addhandler nativesdk_virtclass_handler
+addhandler nativesdk_virtclass_handler bb.event.RecipePreFinalise
 
 do_populate_sysroot[stamp-extra-info] = ""
meta/classes/packageinfo.bbclass +25 -26

54 lines not on this page · raw message

meta/classes/prexport.bbclass +1 -1
index 6b9d540..6949b6e 100644
@@ -54,4 +54,4 @@ python prexport_handler () {
 
 }
 
-addhandler prexport_handler
+addhandler prexport_handler bb.event.RecipeParsed bb.event.ParseStarted bb.event.ParseCompleted
meta/classes/primport.bbclass +1 -1
index 37b0d6b..685b461 100644
@@ -17,4 +17,4 @@ python primport_handler () {
         oe.prservice.prserv_check_avail(e.data)
 }
 
-addhandler primport_handler
+addhandler primport_handler bb.event.ParseCompleted bb.event.ParseStarted
meta/classes/recipe_sanity.bbclass +1 -4
index bf378ea..21f7505 100644
@@ -140,9 +140,6 @@ do_recipe_sanity_all () {
 addtask recipe_sanity_all after do_recipe_sanity
 
 python recipe_sanity_eh () {
-    if bb.event.getName(e) != "ConfigParsed":
-        return
-
     d = e.data
 
     cfgdata = {}
@@ -167,4 +164,4 @@ python recipe_sanity_eh () {
             self.setVar("__recipe_sanity_renames", renames)
     DataSmart.renameVar = myrename
 }
-addhandler recipe_sanity_eh
+addhandler recipe_sanity_eh bb.event.ConfigParsed
meta/classes/sanity.bbclass +1 -1
index 3b01acf..8648a7e 100644
@@ -662,7 +662,7 @@ def copy_data(e):
     sanity_data.finalize()
     return sanity_data
 
-addhandler check_sanity_eventhandler
+addhandler check_sanity_eventhandler bb.event.ConfigParsed bb.event.SanityCheck bb.event.NetworkTest
 python check_sanity_eventhandler() {
     if bb.event.getName(e) == "ConfigParsed" and e.data.getVar("BB_WORKERCONTEXT", True) != "1" and e.data.getVar("DISABLE_SANITY_CHECKS", True) != "1":
         sanity_data = copy_data(e)
meta/classes/tinderclient.bbclass +1 -1
index 6984efd..c186f96 100644
@@ -355,7 +355,7 @@ def tinder_do_tinder_report(event):
 
 
 # we want to be an event handler
-addhandler tinderclient_eventhandler
+addhandler tinderclient_eventhandler *
 python tinderclient_eventhandler() {
     if e.data is None or bb.event.getName(e) == "MsgNote":
         return
meta/classes/typecheck.bbclass +4 -5
index 353532d..196384c 100644
@@ -4,9 +4,8 @@
 
 python check_types() {
     import oe.types
-    if isinstance(e, bb.event.ConfigParsed):
-        for key in e.data.keys():
-            if e.data.getVarFlag(key, "type"):
-                oe.data.typed_value(key, e.data)
+    for key in e.data.keys():
+        if e.data.getVarFlag(key, "type"):
+            oe.data.typed_value(key, e.data)
 }
-addhandler check_types
+addhandler check_types bb.event.ConfigParsed
meta/conf/distro/include/csl-versions.inc +1 -3
index e8f52d2..e1d812d 100644
@@ -88,8 +88,6 @@ def csl_get_gdb_version(d):
 		return first_line.split()[-1]
 
 python csl_version_handler () {
-    if not isinstance(e, bb.event.ConfigParsed):
-        return
     d = e.data
     ld = d.createCopy()
     ld.finalize()
@@ -100,7 +98,7 @@ python csl_version_handler () {
     d.setVar('CSL_VER_KERNEL', csl_get_kernel_version(ld))
     d.setVar('CSL_VER_GDB', csl_get_gdb_version(ld))
 }
-addhandler csl_version_handler
+addhandler csl_version_handler bb.event.ConfigParsed
 
 # Ensure that any variable which includes the --sysroot (CC, CXX, etc) also
 # depends on the toolchain version
meta/conf/distro/include/tcmode-external-sourcery.inc +2 -8
index 098c724..a42c78d 100644
@@ -79,9 +79,6 @@ EXTERNAL_TOOLCHAIN_SYSROOT_CMD += "${@csl_multilib_arg(d)}"
 # to our staging toolchain bindir.
 
 python toolchain_metadata_setup () {
-    if not isinstance(e, bb.event.ConfigParsed):
-        return
-
     d = e.data
 
     l = d.createCopy()
@@ -89,18 +86,15 @@ python toolchain_metadata_setup () {
     if os.path.exists(bb.data.expand('${EXTERNAL_TOOLCHAIN}/bin/gcc', l)):
         d.setVar('TOOLCHAIN_PATH_ADD', '')
 }
-addhandler toolchain_metadata_setup
+addhandler toolchain_metadata_setup bb.event.ConfigParsed
 
 python toolchain_setup () {
-    if not isinstance(e, bb.event.BuildStarted):
-        return
-
     d = e.data
 
     if not d.getVar('TOOLCHAIN_PATH_ADD', True):
         populate_toolchain_links(d)
 }
-addhandler toolchain_setup
+addhandler toolchain_setup bb.event.BuildStarted
 
 def populate_toolchain_links(d):
     import errno
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 12 lines · Bogdan Marinescu

Add more arguments to an "addhandler" command. Each argument (after the first one, which is the name of the handler) is the name of an event class that the handler wants to be notified on. "*" is a shortcut for "listen to all events". This changes the current behaviour of bitbake, which is to broadcast all events to all listeners; instead, only the handlers that registered themselves to an event with "addhandler" will receive that event. This should improve performance, although only performance measurements will be confirm or deny this claim.
This is part of the fix for YOCTO #3812, but implements filtering only for class event handlers; the other part (events filter for UIs) will be the subject of a different patch.

Quoted 2 lines

Wouldn't it be simpler, as well as less invasive to the file format, to add an 'event' or 'events' flag to the handler which indicates what events it wishes to handle?

Signature · 1 line
Christopher Larson
#2 lore raw
Quoted 23 lines · Chris Larson

On Fri, May 31, 2013 at 7:19 AM, Bogdan Marinescu <[email protected]> wrote:
Add more arguments to an "addhandler" command. Each argument (after the
first one, which is the name of the handler) is the name of an event class
that the handler wants to be notified on. "*" is a shortcut for "listen
to all events". This changes the current behaviour of bitbake, which is
to broadcast all events to all listeners; instead, only the handlers
that registered themselves to an event with "addhandler" will receive
that event. This should improve performance, although only performance
measurements will be confirm or deny this claim. This is part of the fix for YOCTO #3812, but implements filtering only
for class event handlers; the other part (events filter for UIs) will be
the subject of a different patch.

Quoted 5 lines

Wouldn't it be simpler, as well as less invasive to the file format, to add an 'event' or 'events' flag to the handler which indicates what events it wishes to handle?

Agreed, FWIW I reworked this and merged it. Since we were messing around with the bitbake minimum version in OE anyway, it seemed a good opportunity.

Cheers,

Richard