#![allow(dead_code)]
#[cfg(not(any(
feature = "profile-with-puffin",
feature = "profile-with-tracy",
feature = "profile-with-optick"
)))]
fn main() {
panic!("No profiler feature flags were enabled. Since this is an example, this is probably a mistake.");
}
#[cfg(any(
feature = "profile-with-puffin",
feature = "profile-with-tracy",
feature = "profile-with-optick"
))]
fn main() {
profiling::register_thread!("Main Thread");
#[cfg(feature = "profile-with-tracy")]
{
use tracing_subscriber::layer::SubscriberExt;
tracing::subscriber::set_global_default(
tracing_subscriber::registry().with(tracing_tracy::TracyLayer::new()),
)
.unwrap();
}
#[cfg(feature = "profile-with-puffin")]
puffin::set_scopes_on(true);
println!("Starting loop, profiler can now be attached");
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")]
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);
}