#![allow(dead_code)]
#[cfg(not(any(
feature = "profile-with-optick",
feature = "profile-with-puffin",
feature = "profile-with-superluminal",
feature = "profile-with-tracing",
feature = "profile-with-tracy",
)))]
fn main() {
panic!("No profiler feature flags were enabled. Since this is an example, this is probably a mistake.");
}
#[cfg(any(
feature = "profile-with-optick",
feature = "profile-with-puffin",
feature = "profile-with-superluminal",
feature = "profile-with-tracing",
feature = "profile-with-tracy",
))]
fn main() {
#[cfg(feature = "profile-with-tracy")]
tracy_client::Client::start();
profiling::register_thread!("Main Thread");
#[cfg(feature = "profile-with-tracing")]
{
use tracing_subscriber::layer::SubscriberExt;
tracing::subscriber::set_global_default(
tracing_subscriber::registry().with(tracing_tracy::TracyLayer::new()),
)
.unwrap();
}
#[cfg(feature = "profile-with-puffin")]
profiling::puffin::set_scopes_on(true);
println!("Starting loop, profiler can now be attached");
#[cfg(not(any(feature = "profile-with-optick")))]
{
profiling::scope!("Outer scope");
burn_time(5);
profiling::scope!("Inner scope");
burn_time(5);
}
#[cfg(not(any(feature = "profile-with-puffin", feature = "profile-with-tracing")))]
#[cfg(not(any(feature = "profile-with-optick")))]
{
let scope_name = String::from("Some scope name");
profiling::scope!(&scope_name);
burn_time(5);
let another_scope_name = String::from("Another scope name");
let some_data = String::from("Some data");
profiling::scope!(&another_scope_name, &some_data);
burn_time(5);
}
loop {
profiling::scope!("Main Thread");
some_function();
some_other_function(10);
println!("frame complete");
profiling::finish_frame!();
}
}
fn burn_time(millis: u128) {
let start_time = std::time::Instant::now();
loop {
if (std::time::Instant::now() - start_time).as_millis() > millis {
break;
}
}
}
#[profiling::function]
fn some_function() {
burn_time(5);
}
fn some_other_function(iterations: usize) {
profiling::scope!("some_other_function");
burn_time(5);
{
profiling::scope!("do iterations");
for i in 0..iterations {
profiling::scope!(
"some_inner_function_that_sleeps",
format!("other data {}", i).as_str()
);
#[cfg(feature = "profile-with-optick")]
profiling::optick::tag!("extra_data", "MORE DATA");
some_inner_function(i);
burn_time(1);
}
}
}
#[profiling::function]
fn some_inner_function(_iteration_index: usize) {
burn_time(10);
}