Skip to content

Commit 11d5ef1

Browse files
committed
Merge branch 'utpilla/Fix-CI-For-Windows' of https://github.com/utpilla/opentelemetry-rust into utpilla/Fix-CI-For-Windows
2 parents 56cd513 + 0ac8be9 commit 11d5ef1

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

stress/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ tracing = { workspace = true, features = ["std"]}
4141
tracing-core = { workspace = true }
4242
tracing-subscriber = { workspace = true, features = ["registry", "std"] }
4343
num-format = "0.4.4"
44+
sysinfo = { version = "0.30.12", optional = true }
45+
46+
[features]
47+
stats = ["sysinfo"]

stress/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ Throughput: 3,905,200 iterations/sec
3636
Throughput: 4,106,600 iterations/sec
3737
Throughput: 5,075,400 iterations/sec
3838
```
39+
40+
## Feature flags
41+
42+
"stats" - Prints memory and CPU usage. Has slight impact on throughput.
43+
44+
```sh
45+
cargo run --release --bin metrics --feature=stats
46+
```

stress/src/throughput.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
33
use std::sync::Arc;
44
use std::thread;
55
use std::time::{Duration, Instant};
6+
#[cfg(feature = "stats")]
7+
use sysinfo::{Pid, System};
68

79
const SLIDING_WINDOW_SIZE: u64 = 2; // In seconds
810
const BATCH_SIZE: u64 = 1000;
@@ -27,7 +29,7 @@ where
2729
})
2830
.expect("Error setting Ctrl-C handler");
2931
let num_threads = num_cpus::get();
30-
println!("Number of threads: {}", num_threads);
32+
println!("Number of threads: {}\n", num_threads);
3133
let mut handles = Vec::with_capacity(num_threads);
3234
let func_arc = Arc::new(func);
3335
let mut worker_stats_vec: Vec<WorkerStats> = Vec::new();
@@ -42,6 +44,12 @@ where
4244
let mut start_time = Instant::now();
4345
let mut end_time = start_time;
4446
let mut total_count_old: u64 = 0;
47+
48+
#[cfg(feature = "stats")]
49+
let pid = Pid::from(std::process::id() as usize);
50+
#[cfg(feature = "stats")]
51+
let mut system = System::new_all();
52+
4553
loop {
4654
let elapsed = end_time.duration_since(start_time).as_secs();
4755
if elapsed >= SLIDING_WINDOW_SIZE {
@@ -56,6 +64,26 @@ where
5664
"Throughput: {} iterations/sec",
5765
throughput.to_formatted_string(&Locale::en)
5866
);
67+
68+
#[cfg(feature = "stats")]
69+
{
70+
system.refresh_all();
71+
if let Some(process) = system.process(pid) {
72+
println!(
73+
"Memory usage: {:.2} MB",
74+
process.memory() as f64 / (1024.0 * 1024.0)
75+
);
76+
println!("CPU usage: {}%", process.cpu_usage() / num_threads as f32);
77+
println!(
78+
"Virtual memory usage: {:.2} MB",
79+
process.virtual_memory() as f64 / (1024.0 * 1024.0)
80+
);
81+
} else {
82+
println!("Process not found");
83+
}
84+
}
85+
86+
println!("\n");
5987
start_time = Instant::now();
6088
}
6189

0 commit comments

Comments
 (0)