valence_core/instrumentation/
timing.rs1use std::time::Instant;
4
5use super::metrics;
6
7pub struct MutationTimer {
9 operation: &'static str,
10 start: Instant,
11}
12
13impl MutationTimer {
14 pub fn start(operation: &'static str) -> Self {
15 Self {
16 operation,
17 start: Instant::now(),
18 }
19 }
20
21 pub fn finish(self) {
22 let ms = self.start.elapsed().as_secs_f64() * 1000.0;
23 metrics::record_mutation_wall_ms(self.operation, ms);
24 }
25}
26
27pub struct QueryTimer {
28 start: Instant,
29}
30
31impl QueryTimer {
32 pub fn start(_primary_table: impl Into<String>, _query_target: impl Into<String>) -> Self {
33 Self {
34 start: Instant::now(),
35 }
36 }
37
38 pub fn elapsed_ms(&self) -> i64 {
39 self.start.elapsed().as_millis() as i64
40 }
41}