v2 [PATCH 0/2] data_smart.py: Track inclusions and assignments
This revised patch now uses Python's traceback facility to assign meaningful locations (file and function, rather than line) to operations which weren't specified, and correspondingly does not specify file and line when the file name would have been the python code making the assignment; this makes the patch smaller and the output more meaningful.
As before, this is a patch to add tracking showing when and how variables got their values, and which configuration files were included from which other configuration files.
The following changes since commit 39adb5741d9eee0879d3181be505400dffc60804:
Andrei Gherzan (1):
bb/fetch2/__init__.py: Don't try to compute checksums for directories
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib seebs/tracking
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=seebs/tracking
Peter Seebach (2):
data_smart.py: Provide (optional) logging of variable modifications data_smart.py: Track configuration file inclusions
lib/bb/cooker.py | 2 + lib/bb/data.py | 65 +++++++++++++++++----- lib/bb/data_smart.py | 140 +++++++++++++++++++++++++++++++++++++-------- lib/bb/parse/__init__.py | 6 ++- lib/bb/parse/ast.py | 65 ++++++++++++---------- 5 files changed, 209 insertions(+), 69 deletions(-)
PATCH 2/2 data_smart.py: Track configuration file inclusions
This is a preliminary attempt to create a structured representation of the processing of include files. It ignores line numbers because they're meaningless. It could probably be updated to, say, distinguish between includes and requires. Output is added to bitbake -e.
--- lib/bb/data.py | 16 ++++++++++++++++ lib/bb/data_smart.py | 41 ++++++++++++++++++++++++++++++++++++++--- lib/bb/parse/__init__.py | 6 +++++- 3 files changed, 59 insertions(+), 4 deletions(-)
lib/bb/data.py +16 -0
@@ -253,10 +253,26 @@ def emit_env(o=sys.__stdout__, d = init(), all=False): isfunc = lambda key: bool(d.getVarFlag(key, "func")) keys = sorted((key for key in d.keys() if not key.startswith("__")), key=isfunc) grouped = groupby(keys, isfunc) + # Include history! + if d.tracking(): + o.write('#\n# INCLUDE HISTORY:\n#\n') + emit_history(o, d.getIncludeHistory()) + for isfunc, keys in grouped: for key in keys: emit_var(key, o, d, all and not isfunc) and o.write('\n') +def emit_history(o, h, depth = 0): + if not h: + return + for event in h: + o.write("# %*s%s" % (depth * 2, "", event[0])) + if event[1]: + o.write(" includes:\n") + emit_history(o, event[1], depth + 1) + else: + o.write("\n") + def exported_keys(d): return (key for key in d.keys() if not key.startswith('__') and d.getVarFlag(key, 'export') and
lib/bb/data_smart.py +38 -3
65 lines not on this page · raw message
lib/bb/parse/__init__.py +5 -1
@@ -88,7 +88,11 @@ def handle(fn, data, include = 0): """Call the handler that is appropriate for this file""" for h in handlers: if h['supports'](fn, data): - return h['handle'](fn, data, include) + data.includeLog(fn) + try: + return h['handle'](fn, data, include) + finally: + data.includeLogDone(fn) raise ParseError("not a BitBake file", fn) def init(fn, data):
Signature · 1 line
1.7.0.4
PATCH 1/2 data_smart.py: Provide (optional) logging of variable modifications
In reply to Peter SeebachThis is very preliminary, and probably not very good, but it provides a much-wanted feature: An explanation of how variables got their current values.
How it works:
1. We create a history dict in the data_smart object, the members of which are lists of tuples. It's three, count them, THREE unrelated data types in a single object!
2. There is an eventLog(...) function which allows recording things which happen to variables.
3. All over the place, tons of setVar and related functions are updated with two optional arguments, filename and lineno.
4. We log pretty much everything if logging is enabled.
5. You can query the history of a thing with data.getHistory(var)
Tracking must be specifically turned on. If it's not, the history object is a single empty table (cheap) and the calls to eventLog() and extra argument passing are also probably quite cheap. As a proof of concept, the showEnvironment function used by bitbake -e now uses this if available.
--- lib/bb/cooker.py | 2 + lib/bb/data.py | 49 +++++++++++++++++------- lib/bb/data_smart.py | 103 ++++++++++++++++++++++++++++++++++++++------------ lib/bb/parse/ast.py | 65 +++++++++++++++++-------------- 4 files changed, 152 insertions(+), 67 deletions(-)
lib/bb/cooker.py +2 -0
@@ -825,6 +825,8 @@ class BBCooker: def parseConfigurationFiles(self, prefiles, postfiles): data = self.configuration.data + if self.configuration.show_environment: + data.enableTracking() bb.parse.init_parser(data) # Parse files for loading *before* bitbake.conf and any includes
lib/bb/data.py +35 -14
97 lines not on this page · raw message
lib/bb/data_smart.py +79 -24
253 lines not on this page · raw message
lib/bb/parse/ast.py +36 -29
163 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Quoted 6 lines · Peter Seebach
This revised patch now uses Python's traceback facility to assign meaningful locations (file and function, rather than line) to operations which weren't specified, and correspondingly does not specify file and line when the file name would have been the python code making the assignment; this makes the patch smaller and the output more meaningful.
Quoted 7 lines
As before, this is a patch to add tracking showing when and how variables got their values, and which configuration files were included from which other configuration files.
The following changes since commit
39adb5741d9eee0879d3181be505400dffc60804:
Andrei Gherzan (1):
bb/fetch2/__init__.py: Don't try to compute checksums for directories
While these still aren't the prettiest, I think they're a lot cleaner than they were, and given the obvious value, I think we should consider merging them. Richard, thoughts?
Signature · 1 line
Christopher Larson
Quoted 3 lines · On Mon, 21 May 2012 12:54:10 -0700 Chris Larson <[email protected]> wrote:
While these still aren't the prettiest, I think they're a lot cleaner than they were, and given the obvious value, I think we should consider merging them.
The only other thing that sort of occurred to me was that it might be useful in such a case to break out the parts of finalize so the tracking of assignments and changes which occur there to be more obvious. (Say, move the _append and _override logics to their own functions.)
Not sure it's worth it, though. I suppose I could just make those setVars be (var, value, None, None, 'append') or whatever.
-s
Signature · 1 line
Listen, get this. Nobody with a good compiler needs to be justified.
Quoted 12 lines · Chris Larson
Quoted 10 lines · Peter Seebach
This revised patch now uses Python's traceback facility to assign meaningful locations (file and function, rather than line) to operations which weren't specified, and correspondingly does not specify file and line when the file name would have been the python code making the assignment; this makes the patch smaller and the output more meaningful.
As before, this is a patch to add tracking showing when and how variables got their values, and which configuration files were included from which other configuration files.
Quoted 7 lines
Quoted 3 lines
The following changes since commit
39adb5741d9eee0879d3181be505400dffc60804:
Andrei Gherzan (1):
bb/fetch2/__init__.py: Don't try to compute checksums for directoriesWhile these still aren't the prettiest, I think they're a lot cleaner than they were, and given the obvious value, I think we should consider merging them. Richard, thoughts?
I agree, I'd prefer we could find a neater way to do this but our current structure doesn't lend itself to this and this is not looking too bad.
My main concerns would be related to performance and since this defaults to disabled, it shouldn't be too bad. It also does answer an important question we do keep getting asked, namely, "how did variable X get set or Y" or "which files did Bitbake actually look at". These changes allow us to give people a way to answer those questions.
So I want to take a closer look through the patches but I'm leaning toward merging them. If we find ways to make things neater, great but this is probably as good a start as we can hope for.
Cheers,
Richard
Quoted 3 lines · On Tue, 22 May 2012 14:43:39 +0100 Richard Purdie…
So I want to take a closer look through the patches but I'm leaning toward merging them. If we find ways to make things neater, great but this is probably as good a start as we can hope for.
They need one small bug fixed (there's a missing [1] in the mods to createCopy), but apart from that I'm using them without noticeable trouble.
If these get added to bitbake, there's a related change to oe-core that might be handy, to suppress sanity checks when using this feature so you can get an explanation of what went wrong.
-s
Signature · 1 line
Listen, get this. Nobody with a good compiler needs to be justified.
Quoted 10 lines · Peter Seebach
Quoted 3 lines · On Tue, 22 May 2012 14:43:39 +0100 Richard Purdie…
So I want to take a closer look through the patches but I'm leaning toward merging them. If we find ways to make things neater, great but this is probably as good a start as we can hope for.
They need one small bug fixed (there's a missing [1] in the mods to createCopy), but apart from that I'm using them without noticeable trouble.
FWIW, I'm planning to look at this next week, am not likely to get there today.
Quoted 3 lines
If these get added to bitbake, there's a related change to oe-core that might be handy, to suppress sanity checks when using this feature so you can get an explanation of what went wrong.
I suspect a recent change to sanity.bbclass has made that obsolete...
Cheers,
Richard