Skip to content

Commit

Permalink
refactor: make stop_process_timer return duration (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev authored Jul 1, 2024
1 parent 11637d6 commit 306aace
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 4 additions & 2 deletions trin-metrics/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use ethportal_api::types::{distance::Distance, portal_wire::ProtocolId};
use prometheus_exporter::{
self,
Expand Down Expand Up @@ -104,8 +106,8 @@ impl StorageMetricsReporter {
)
}

pub fn stop_process_timer(&self, timer: DiscardOnDropHistogramTimer) {
timer.observe_duration()
pub fn stop_process_timer(&self, timer: DiscardOnDropHistogramTimer) -> Duration {
Duration::from_secs_f64(timer.stop_and_record())
}

pub fn report_content_data_storage_bytes(&self, bytes: f64) {
Expand Down
7 changes: 2 additions & 5 deletions trin-storage/src/versioned/id_indexed_v1/store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Instant;

use ethportal_api::types::distance::Distance;
use r2d2::Pool;
use r2d2_sqlite::SqliteConnectionManager;
Expand Down Expand Up @@ -466,16 +464,15 @@ impl IdIndexedV1Store {
return Ok(());
}

let pruning_start_time = Instant::now();
let delete_timer = self.metrics.start_process_timer("prune_delete");
let deleted_content_sizes = delete_query
.query_map(named_params! { ":limit": to_delete }, |row| {
row.get("content_size")
})?
.collect::<Result<Vec<u64>, rusqlite::Error>>()?;
self.metrics.stop_process_timer(delete_timer);
let pruning_duration = self.metrics.stop_process_timer(delete_timer);
self.pruning_strategy
.observe_pruning_duration(pruning_start_time.elapsed());
.observe_pruning_duration(pruning_duration);

if to_delete != deleted_content_sizes.len() as u64 {
error!(Db = %self.config.content_type,
Expand Down

0 comments on commit 306aace

Please sign in to comment.