-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update readmes for flame and error #695
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c2f7dd2
update readmes for flame and error
yaahc e975c8c
remove rustdoc specific shit
yaahc 50752db
some tweeks
yaahc 255a02a
Update tracing-error/README.md
yaahc e4d404c
address comments
yaahc eb8ae34
Apply suggestions from code review
yaahc 1f3fc34
mention TracedError first
yaahc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# tracing-flame | ||
|
||
A [tracing] [`Layer`][`FlameLayer`] for generating a folded stack trace for generating flamegraphs | ||
and flamecharts with [`inferno`] | ||
|
||
[![Crates.io][crates-badge]][crates-url] | ||
[![Documentation][docs-badge]][docs-url] | ||
[![Documentation (master)][docs-master-badge]][docs-master-url] | ||
[![MIT licensed][mit-badge]][mit-url] | ||
[![Build Status][actions-badge]][actions-url] | ||
[![Discord chat][discord-badge]][discord-url] | ||
![maintenance status][maint-badge] | ||
|
||
[Documentation][docs-url] | [Chat][discord-url] | ||
|
||
# Overview | ||
|
||
[`tracing`] is a framework for instrumenting Rust programs to collect | ||
scoped, structured, and async-aware diagnostics. `tracing-flame` provides helpers | ||
for consuming `tracing` instrumentation that can later be visualized as a | ||
flamegraph/flamechart. Flamegraphs/flamecharts are useful for identifying performance | ||
bottlenecks in an application. For more details, see Brendan Gregg's [post] | ||
on flamegraphs. | ||
|
||
[post]: http://www.brendangregg.com/flamegraphs.html | ||
|
||
## Usage | ||
|
||
This crate is meant to be used in a two step process: | ||
|
||
1. Capture textual representation of the spans that are entered and exited | ||
with [`FlameLayer`]. | ||
2. Feed the textual representation into `inferno-flamegraph` to generate the | ||
flamegraph or flamechart. | ||
|
||
*Note*: when using a buffered writer as the writer for a `FlameLayer`, it is necessary to | ||
ensure that the buffer has been flushed before the data is passed into | ||
[`inferno-flamegraph`]. For more details on how to flush the internal writer | ||
of the `FlameLayer`, see the docs for [`FlushGuard`]. | ||
|
||
## Layer Setup | ||
|
||
```rust | ||
use std::{fs::File, io::BufWriter}; | ||
use tracing_flame::FlameLayer; | ||
use tracing_subscriber::{registry::Registry, prelude::*, fmt}; | ||
|
||
fn setup_global_subscriber() -> impl Drop { | ||
let fmt_layer = fmt::Layer::default(); | ||
|
||
let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap(); | ||
|
||
tracing_subscriber::registry() | ||
.with(fmt_layer) | ||
.with(flame_layer) | ||
.init(). | ||
_guard | ||
} | ||
|
||
// your code here .. | ||
``` | ||
|
||
As an alternative, you can provide _any_ type that implements `std::io::Write` to | ||
`FlameLayer::new`. | ||
|
||
## Generating the Image | ||
|
||
To convert the textual representation of a flamegraph to a visual one, first install `inferno`: | ||
|
||
```console | ||
cargo install inferno | ||
``` | ||
|
||
Then, pass the file created by `FlameLayer` into `inferno-flamegraph`: | ||
|
||
```console | ||
# flamegraph | ||
cat tracing.folded | inferno-flamegraph > tracing-flamegraph.svg | ||
|
||
# flamechart | ||
cat tracing.folded | inferno-flamegraph --flamechart > tracing-flamechart.svg | ||
``` | ||
|
||
## Differences between `flamegraph`s and `flamechart`s | ||
|
||
By default, `inferno-flamegraph` creates flamegraphs. Flamegraphs operate by | ||
that collapsing identical stack frames and sorting them on the frame's names. | ||
|
||
This behavior is great for multithreaded programs and long-running programs | ||
where the same frames occur _many_ times, for short durations, because it reduces | ||
noise in the graph and gives the reader a better idea of the | ||
overall time spent in each part of the application. | ||
|
||
However, it is sometimes desirable to preserve the _exact_ ordering of events | ||
as they were emitted by `tracing-flame`, so that it is clear when each | ||
span is entered relative to others and get an accurate visual trace of | ||
the execution of your program. This representation is best created with a | ||
_flamechart_, which _does not_ sort or collapse identical stack frames. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT license](LICENSE). | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally submitted | ||
for inclusion in Tracing by you, shall be licensed as MIT, without any additional | ||
terms or conditions. | ||
|
||
[`inferno`]: https://docs.rs/inferno | ||
[`FlameLayer`]: https://docs.rs/tracing-flame/*/tracing_flame/struct.FlameLayer.html | ||
[`FlushGuard`]: https://docs.rs/tracing-flame/*/tracing_flame/struct.FlushGuard.html | ||
[`inferno-flamegraph`]: https://docs.rs/inferno/0.9.5/inferno/index.html#producing-a-flame-graph | ||
[`tracing`]: https://github.com/tokio-rs/tracing/tree/master/tracing | ||
[crates-badge]: https://img.shields.io/crates/v/tracing-flame.svg | ||
[crates-url]: https://crates.io/crates/tracing-flame | ||
[docs-badge]: https://docs.rs/tracing-flame/badge.svg | ||
[docs-url]: https://docs.rs/tracing-flame/0.2.4 | ||
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue | ||
[docs-master-url]: https://tracing-rs.netlify.com/tracing_flame | ||
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg | ||
[mit-url]: LICENSE | ||
[actions-badge]: https://github.com/tokio-rs/tracing/workflows/CI/badge.svg | ||
[actions-url]:https://github.com/tokio-rs/tracing/actions?query=workflow%3ACI | ||
[discord-badge]: https://img.shields.io/discord/500028886025895936?logo=discord&label=discord&logoColor=white | ||
[discord-url]: https://discord.gg/EeF3cQw | ||
[maint-badge]: https://img.shields.io/badge/maintenance-experimental-blue.svg |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't strictly
inferno
-specific; it emits theperf
output format, right? so technically any flamegraph tool that expects that can use this crate's output.i'm not sure if this is worth stating here though, for the sake of brevity...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think its the same format that perf emits, my understanding is that with perf normally you take the output and pass it through another script that folds the stack traces, and then you pass the folded representation into the flamegraph generating scripts. With
tracing-flame
we skip straight to emitting a folded representation. I think it might be cool to investigate if we can emit perf's exact format so we can be compatible with more tools, but I think it would be the same as writing a script to fake a bunch of stack traces that reproduce the folded repr, so for now I don't think we should bother with it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is the folded output produced by
flamegraph
,inferno
, and some newer eBPF perf tracing tools.perf
's output (by which you're probably referring toperf script
's output) is probably not something we want to mirror. The collapsed output is decently standard, enough so that eBPF also produces the same thing.