Tidy up library interface for flamegraph (and collapse?)
- Dominant language
- Rust
- Stars
- 2.2k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
If we want other projects, like @koute's [nperf](https://github.com/nokia/nperf), to [start using](https://www.reddit.com/r/rust/comments/ak6s89/porting_flamegraph_to_rust_video/ef6h7il/) inferno to draw their flame graphs (and perhaps even to do the collapsing), we need to provide an external interface that isn't just a purely line-based textual one like the ones used internally between `perf script`, `stackcollapse-perf`, and `flamegraph.pl`. Specifically, we'll want an interface that is typed, and where all (most?) of the parsing is done by the caller. I'm imagining something like:
```rust
mod flamegraph {
struct StackCount {
stack: S,
count: usize,
}
fn from_samples(o: Opts, samples: I, writer: W) ->
where
I: IntoIterator,
I::Item: Into>,
S: Iterator,
W: Write
{
}
}
```
`from_samples` would require that the input is given in sorted order (see #28), and then write a flame graph output to `writer`. The existing code that does parsing would call from_samples with an iterator created from the lines iterator, mapped something like this:
```rust
lines.map(|line| {
let (stack, nsamples) = ...;
StackCount {
count: nsamples,
stack: stack.split(';'),
}
})
```
@koute: what do you think of an interface roughly like the above? You think that's an iterator that `nperf` could easily produce? What would be a good interface for `collapse` (if that's even something you might consider using)?
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the existing line-based flow between perf script, stackcollapse-perf, and flamegraph.pl, along with the proposed from_samples entry point and the requirements from #28. Determine the typed external interface and whether collapse should be included, then validate that nperf could produce the proposed iterator and that the library can write the flame graph output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100