use pyroscope::backend::jemalloc::jemalloc_backend;
use pyroscope::pyroscope::PyroscopeAgentBuilder;
use std::time::Duration;
#[global_allocator]
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let agent = PyroscopeAgentBuilder::new(
"http://localhost:4040",
"example.jemalloc",
100,
"pyroscope-rs",
env!("CARGO_PKG_VERSION"),
jemalloc_backend(),
)
.tags(vec![("env", "dev")])
.build()?;
let agent_running = agent.start()?;
let start = std::time::Instant::now();
let mut iteration = 0u64;
while start.elapsed() < Duration::from_secs(30) {
for i in 0..100 {
let size = 1024 * (1 + (iteration as usize + i) % 1024);
let v: Vec<u8> = vec![0u8; size];
std::hint::black_box(&v);
}
iteration += 1;
}
eprintln!("Completed {} iterations", iteration);
let agent_ready = agent_running.stop()?;
agent_ready.shutdown();
Ok(())
}