-
Notifications
You must be signed in to change notification settings - Fork 29
/
basic.rs
60 lines (47 loc) · 1.51 KB
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
extern crate pyroscope;
use pyroscope::{PyroscopeAgent, Result};
use pyroscope_pprofrs::{pprof_backend, PprofConfig};
use std::hash::{Hash, Hasher};
fn hash_rounds(n: u64) -> u64 {
let hash_str = "Some string to hash";
let mut default_hasher = std::collections::hash_map::DefaultHasher::new();
for _ in 0..n {
for _ in 0..1000 {
default_hasher.write(hash_str.as_bytes());
}
hash_str.hash(&mut default_hasher);
}
n
}
fn main() -> Result<()> {
let agent = PyroscopeAgent::builder("http://localhost:4040", "example.basic")
.backend(pprof_backend(PprofConfig::new().sample_rate(100)))
.tags([("TagA", "ValueA"), ("TagB", "ValueB")].to_vec())
.build()?;
// Show start time
let start = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
println!("Start Time: {}", start);
// Start Agent
let agent_running = agent.start()?;
let _result = hash_rounds(300_000);
// Show stop time
let stop = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
println!("Stop Time: {}", stop);
// Stop Agent
let agent_ready = agent_running.stop()?;
// Shutdown the Agent
agent_ready.shutdown();
// Show program exit time
let exit = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
println!("Exit Time: {}", exit);
Ok(())
}