mdickinson / refcycle

Support for displaying and analyzing reference graphs of Python objects.
Apache License 2.0
15 stars 1 forks source link

Source components' descendants #44

Open rkern opened 10 years ago

rkern commented 10 years ago

I'd love to be able to export a .dot file from an ObjectGraph that contains a subgraph of a garbage snapshot that contains just a specified source component and its descendants (to a configurable number of generations). With the source component subgraph highlighted in red, of course.

g = refcycle.garbage()
sources = g.source_components()
subgraph = g.subgraph_descendants(sources[0], generations=5)
subgraph.write_to_dot('garbage.dot', highlight_subgraph=sources[0])
mdickinson commented 10 years ago

Does the "number of generations" here refer to depth in the original graph or depth in the graph of strongly connected components? That is, with generations=1, would you want to get all the complete components reachable from the source component, or just the nodes of the original graph reachable from the source component in a single step?

mdickinson commented 10 years ago

in red, of course

Of course!

rkern commented 10 years ago

Generations of nodes. I imagine subgraph_descendants() as agnostic to the nature of the subgraph it is looking at. For that matter, a more general method would just take an iterable of nodes, but all of my actual use cases involve subgraphs.

rkern commented 10 years ago

If you want to highlight all of the non-source SCCs in blue, that would be cool, too. ;-)