diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-23 15:55:21 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-08-23 17:29:54 +0100 |
commit | 25e410b743be45f7ed57457c1d3cd2066652085b (patch) | |
tree | 51035c334025e08e2500912026e97014e81803cd /bitbake | |
parent | 9f0f799c461fb67e7c03304216253ca9bf899680 (diff) | |
download | poky-25e410b743be45f7ed57457c1d3cd2066652085b.tar.gz |
bitbake: event/msg: Add primitive server side UI log record filtering
Currently one of the bigger bottlenecks in bitbake is passing all the
log messages over IPC to the UI. This is worthwhile if the UI is going
to use them, pointless otherwise. The memory resident bitbake suffers
from this performance issue particularly badly.
This patch filters the log events on the server side with the global
log levels and hence reduces the traffic. This speeds up parsing
(18.5s down to 17s) and bitbake general command overhead is reduced
(7.3s for a NOP to 6.2s).
What isn't added here is general event filtering or the ability to
change the log levels once set. Provision is made for adding this
in a follow up patch though.
(Bitbake rev: 1bf0e88f57ba0bca62532e81d0d62cf88e2abcbb)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/event.py | 25 | ||||
-rw-r--r-- | bitbake/lib/bb/msg.py | 7 |
2 files changed, 30 insertions, 2 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index ba25d38d89..8ffd2c3e18 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py | |||
@@ -63,6 +63,7 @@ def clean_class_handlers(): | |||
63 | # Internal | 63 | # Internal |
64 | _handlers = clean_class_handlers() | 64 | _handlers = clean_class_handlers() |
65 | _ui_handlers = {} | 65 | _ui_handlers = {} |
66 | _ui_logfilters = {} | ||
66 | _ui_handler_seq = 0 | 67 | _ui_handler_seq = 0 |
67 | _event_handler_map = {} | 68 | _event_handler_map = {} |
68 | _catchall_handlers = {} | 69 | _catchall_handlers = {} |
@@ -135,6 +136,8 @@ def fire_ui_handlers(event, d): | |||
135 | for h in _ui_handlers: | 136 | for h in _ui_handlers: |
136 | #print "Sending event %s" % event | 137 | #print "Sending event %s" % event |
137 | try: | 138 | try: |
139 | if not _ui_logfilters[h].filter(event): | ||
140 | continue | ||
138 | # We use pickle here since it better handles object instances | 141 | # We use pickle here since it better handles object instances |
139 | # which xmlrpc's marshaller does not. Events *must* be serializable | 142 | # which xmlrpc's marshaller does not. Events *must* be serializable |
140 | # by pickle. | 143 | # by pickle. |
@@ -207,6 +210,8 @@ def remove(name, handler): | |||
207 | def register_UIHhandler(handler): | 210 | def register_UIHhandler(handler): |
208 | bb.event._ui_handler_seq = bb.event._ui_handler_seq + 1 | 211 | bb.event._ui_handler_seq = bb.event._ui_handler_seq + 1 |
209 | _ui_handlers[_ui_handler_seq] = handler | 212 | _ui_handlers[_ui_handler_seq] = handler |
213 | level, debug_domains = bb.msg.constructLogOptions() | ||
214 | _ui_logfilters[_ui_handler_seq] = UIEventFilter(level, debug_domains) | ||
210 | return _ui_handler_seq | 215 | return _ui_handler_seq |
211 | 216 | ||
212 | def unregister_UIHhandler(handlerNum): | 217 | def unregister_UIHhandler(handlerNum): |
@@ -214,6 +219,26 @@ def unregister_UIHhandler(handlerNum): | |||
214 | del _ui_handlers[handlerNum] | 219 | del _ui_handlers[handlerNum] |
215 | return | 220 | return |
216 | 221 | ||
222 | # Class to allow filtering of events and specific filtering of LogRecords *before* we put them over the IPC | ||
223 | class UIEventFilter(object): | ||
224 | def __init__(self, level, debug_domains): | ||
225 | self.update(None, level, debug_domains) | ||
226 | |||
227 | def update(self, eventmask, level, debug_domains): | ||
228 | self.eventmask = None | ||
229 | self.stdlevel = level | ||
230 | self.debug_domains = debug_domains | ||
231 | |||
232 | def filter(self, event): | ||
233 | if isinstance(event, logging.LogRecord): | ||
234 | if event.levelno >= self.stdlevel: | ||
235 | return True | ||
236 | if event.name in self.debug_domains and event.levelno >= self.debug_domains[event.name]: | ||
237 | return True | ||
238 | return False | ||
239 | # Implement other event masking here on self.eventmask | ||
240 | return True | ||
241 | |||
217 | def getName(e): | 242 | def getName(e): |
218 | """Returns the name of a class or class instance""" | 243 | """Returns the name of a class or class instance""" |
219 | if getattr(e, "__name__", None) == None: | 244 | if getattr(e, "__name__", None) == None: |
diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py index e70daee92f..59769707e0 100644 --- a/bitbake/lib/bb/msg.py +++ b/bitbake/lib/bb/msg.py | |||
@@ -146,8 +146,7 @@ def init_msgconfig(verbose, debug, debug_domains = []): | |||
146 | bb.msg.loggerVerboseLogs = True | 146 | bb.msg.loggerVerboseLogs = True |
147 | bb.msg.loggerDefaultDomains = debug_domains | 147 | bb.msg.loggerDefaultDomains = debug_domains |
148 | 148 | ||
149 | def addDefaultlogFilter(handler): | 149 | def constructLogOptions(): |
150 | |||
151 | debug = loggerDefaultDebugLevel | 150 | debug = loggerDefaultDebugLevel |
152 | verbose = loggerDefaultVerbose | 151 | verbose = loggerDefaultVerbose |
153 | domains = loggerDefaultDomains | 152 | domains = loggerDefaultDomains |
@@ -163,6 +162,10 @@ def addDefaultlogFilter(handler): | |||
163 | for (domainarg, iterator) in groupby(domains): | 162 | for (domainarg, iterator) in groupby(domains): |
164 | dlevel = len(tuple(iterator)) | 163 | dlevel = len(tuple(iterator)) |
165 | debug_domains["BitBake.%s" % domainarg] = logging.DEBUG - dlevel + 1 | 164 | debug_domains["BitBake.%s" % domainarg] = logging.DEBUG - dlevel + 1 |
165 | return level, debug_domains | ||
166 | |||
167 | def addDefaultlogFilter(handler): | ||
168 | level, debug_domains = constructLogOptions() | ||
166 | 169 | ||
167 | BBLogFilter(handler, level, debug_domains) | 170 | BBLogFilter(handler, level, debug_domains) |
168 | 171 | ||