Add 'stacks' subcommand for folded/flame-graph output (#289) - #378
Open
ChrisJr404 wants to merge 1 commit into
Open
Add 'stacks' subcommand for folded/flame-graph output (#289)#378ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
This lets non-interactive runs export the whole traversal in the folded 'collapsed' format read by flame-graph tools like inferno and Brendan Gregg's flamegraph.pl, so a disk-usage exploration can become a single shareable SVG via 'dua stacks | inferno-flamegraph > usage.svg'. Each line is an entry's path with ';' between components followed by its own size in bytes; a directory contributes only the size of its own entry since its contents are printed on their own lines, so the lines sum to the same total the other commands report. Traversal options (apparent size, ignore patterns, hard-link counting, ...) are honored as usual.
Owner
|
Can you please upload the SVG to this PR? I want to take a look. Please beware of PII. Thanks so much. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
stackssubcommand that prints the whole traversal as folded stacks, so aduarun can be turned into a disk-usage flame graph without leaving the tool. This implements the request in #289.The folded (a.k.a. "collapsed") format is what flame-graph tools like inferno and Brendan Gregg's
flamegraph.plread on stdin: one line per entry, its path with;between components, a space, and its size in bytes. That makes the usual pipe work:A couple of design notes:
files.pldoes), every entry gets a line carrying its own size: a directory contributes just the size of its directory entry, because the bytes it contains already show up on the lines of the things inside it. That avoids double-counting when the flame-graph tool sums a stack against its parents, and it means the folded lines sum to exactly the same total the other commands report — I added a test that checks this against a fresh traversal. Zero-sized entries are left out since they add nothing to a graph.--apparent-size,--ignore-from,--count-hard-links, threads, and so on). Hard links are counted once by default, as elsewhere.;frame separator and any control characters replaced with_so a single odd filename can't corrupt the line-based format.I went with a subcommand rather than a flag on
aggregatebecause the folded output needs the full in-memory tree, whichaggregatedoesn't build — but I'm happy to reshape the surface (name, flag vs. subcommand) if you'd prefer something else.Example output:
Testing: added four unit tests in
src/stacks.rscovering the nested-file layout, the sum-equals-total invariant, a single-file input, and;-in-name sanitization.cargo testis green (77 tests),cargo +nightly fmt --checkis clean, andcargo +nightly clippyproduces no new warnings from this change. Also smoke-tested by hand thatdua stacks -Aanddua aggregate -A --format bytesreport the same total, and that the output pipes cleanly.