-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add Client::plot_config + relevant types + example #125
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use rand::Rng; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
use tracy_client::{Client, PlotConfiguration, PlotFormat, PlotLineStyle, PlotName}; | ||
|
||
// Plots you know statically can be defined freely like so | ||
const PLOT_PLAYER_COUNT: PlotName = tracy_client::plot_name!("Player Count"); | ||
const PLOT_DISK_SPACE: PlotName = tracy_client::plot_name!("Disk Space"); | ||
|
||
pub fn main() { | ||
let client = Client::start(); | ||
let mut rng = rand::thread_rng(); | ||
|
||
// Anything at runtime needs to be created via PlotName | ||
let bandwidth = PlotName::new_leak("Bandwidth".to_string()); | ||
|
||
// You can configure how plots display, this only needs to be done once | ||
client.plot_config( | ||
PLOT_DISK_SPACE, | ||
PlotConfiguration::default() | ||
.format(PlotFormat::Memory) | ||
.fill(false), | ||
); | ||
client.plot_config( | ||
bandwidth, | ||
PlotConfiguration::default() | ||
.format(PlotFormat::Percentage) | ||
.color(Some(0xFF0000)) | ||
.line_style(PlotLineStyle::Stepped), | ||
); | ||
|
||
for _ in 0..50 { | ||
// You don't need to constantly send a value! | ||
if rng.gen_bool(0.75) { | ||
client.plot(PLOT_PLAYER_COUNT, rng.gen_range(0..10) as f64); | ||
} | ||
|
||
client.plot(PLOT_DISK_SPACE, rng.gen_range(0..1000000) as f64); | ||
client.plot(bandwidth, rng.gen_range(0..100) as f64); | ||
|
||
sleep(Duration::from_millis(20)); | ||
} | ||
} |
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
Oops, something went wrong.
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.
Worth adding a code example here just for constructing the type and changing a field or two. I found it to be pretty common for people to struggle to figure out how to construct stuff, when the construction is not a
fn new()
(even if it is as simple as usingdefault()
instead.) A plain example would help with that.