Update metrics
This commit is contained in:
parent
842fc933ef
commit
c7106fcfab
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "async-cpupool"
|
||||
description = "A simple async threadpool for CPU-bound tasks"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/safe-async/async-cpupool"
|
||||
|
@ -14,9 +14,9 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
flume = "0.11.0"
|
||||
metrics = "0.21.1"
|
||||
metrics = "0.22.0"
|
||||
tracing = "0.1.40"
|
||||
|
||||
[dev-dependencies]
|
||||
smol = "1.3.0"
|
||||
smol = "2.0.0"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -598,7 +598,8 @@ struct MetricsGuard {
|
|||
impl MetricsGuard {
|
||||
fn guard(name: &'static str, id: u64) -> Self {
|
||||
tracing::trace!("Starting {name}-{id}");
|
||||
metrics::increment_counter!(format!("async-cpupool.{name}.launched"), "id" => id.to_string());
|
||||
metrics::counter!(format!("async-cpupool.{name}.launched"), "id" => id.to_string())
|
||||
.increment(1);
|
||||
|
||||
MetricsGuard {
|
||||
name,
|
||||
|
@ -615,8 +616,8 @@ impl MetricsGuard {
|
|||
|
||||
impl Drop for MetricsGuard {
|
||||
fn drop(&mut self) {
|
||||
metrics::increment_counter!(format!("async-cpupool.{}.closed", self.name), "clean" => (!self.armed).to_string(), "id" => self.id.to_string());
|
||||
metrics::histogram!(format!("async-cpupool.{}.duration", self.name), self.start.elapsed().as_secs_f64(), "clean" => (!self.armed).to_string(), "id" => self.id.to_string());
|
||||
metrics::counter!(format!("async-cpupool.{}.closed", self.name), "clean" => (!self.armed).to_string(), "id" => self.id.to_string()).increment(1);
|
||||
metrics::histogram!(format!("async-cpupool.{}.duration", self.name), "clean" => (!self.armed).to_string(), "id" => self.id.to_string()).record(self.start.elapsed().as_secs_f64());
|
||||
tracing::trace!("Stopping {}-{}", self.name, self.id);
|
||||
}
|
||||
}
|
||||
|
@ -644,14 +645,15 @@ fn run(
|
|||
|
||||
fn invoke_send_fn(name: &'static str, id: u64, send_fn: SendFn) {
|
||||
let start = Instant::now();
|
||||
metrics::increment_counter!(format!("async-cpupool.{name}.operation.start"), "id" => id.to_string());
|
||||
metrics::counter!(format!("async-cpupool.{name}.operation.start"), "id" => id.to_string())
|
||||
.increment(1);
|
||||
|
||||
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || {
|
||||
(send_fn)();
|
||||
}));
|
||||
|
||||
metrics::increment_counter!(format!("async-cpupool.{name}.operation.end"), "complete" => res.is_ok().to_string(), "id" => id.to_string());
|
||||
metrics::histogram!(format!("async-cpupool.{name}.operation.duration"), start.elapsed().as_secs_f64(), "complete" => res.is_ok().to_string(), "id" => id.to_string());
|
||||
metrics::counter!(format!("async-cpupool.{name}.operation.end"), "complete" => res.is_ok().to_string(), "id" => id.to_string()).increment(1);
|
||||
metrics::histogram!(format!("async-cpupool.{name}.operation.duration"), "complete" => res.is_ok().to_string(), "id" => id.to_string()).record(start.elapsed().as_secs_f64());
|
||||
|
||||
if let Err(e) = res {
|
||||
tracing::trace!("panic in spawned task: {e:?}");
|
||||
|
|
Loading…
Reference in a new issue