Skip to content

Commit a4ef2b3

Browse files
committed
Remove stupid Timer
1 parent 782044a commit a4ef2b3

5 files changed

Lines changed: 29 additions & 60 deletions

File tree

kernel/src/engine/default/filesystem.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::sync::Arc;
2+
use std::time::Instant;
23

34
use bytes::Bytes;
45
use delta_kernel_derive::internal_api;
@@ -10,14 +11,14 @@ use url::Url;
1011

1112
use super::UrlExt;
1213
use crate::engine::default::executor::TaskExecutor;
13-
use crate::metrics::{MetricEvent, MetricsReporter, Timer};
14+
use crate::metrics::{MetricEvent, MetricsReporter};
1415
use crate::{DeltaResult, Error, FileMeta, FileSlice, StorageHandler};
1516

1617
/// Iterator wrapper that emits metrics when exhausted
1718
struct ListMetricsIterator<I> {
1819
inner: I,
1920
reporter: Option<Arc<dyn MetricsReporter>>,
20-
timer: Timer,
21+
start: Instant,
2122
count: u64,
2223
metrics_emitted: bool,
2324
}
@@ -37,7 +38,7 @@ impl<I: Iterator<Item = DeltaResult<FileMeta>>> Iterator for ListMetricsIterator
3738
if !self.metrics_emitted {
3839
self.reporter.as_ref().inspect(|r| {
3940
r.report(MetricEvent::StorageListCompleted {
40-
duration: self.timer.elapsed(),
41+
duration: self.start.elapsed(),
4142
num_files: self.count,
4243
});
4344
});
@@ -53,7 +54,7 @@ impl<I: Iterator<Item = DeltaResult<FileMeta>>> Iterator for ListMetricsIterator
5354
struct ReadMetricsIterator<I> {
5455
inner: I,
5556
reporter: Option<Arc<dyn MetricsReporter>>,
56-
timer: Timer,
57+
start: Instant,
5758
num_files: u64,
5859
bytes_read: u64,
5960
metrics_emitted: bool,
@@ -74,7 +75,7 @@ impl<I: Iterator<Item = DeltaResult<Bytes>>> Iterator for ReadMetricsIterator<I>
7475
if !self.metrics_emitted {
7576
self.reporter.as_ref().inspect(|r| {
7677
r.report(MetricEvent::StorageReadCompleted {
77-
duration: self.timer.elapsed(),
78+
duration: self.start.elapsed(),
7879
num_files: self.num_files,
7980
bytes_read: self.bytes_read,
8081
});
@@ -187,7 +188,7 @@ impl<E: TaskExecutor> StorageHandler for ObjectStoreStorageHandler<E> {
187188
}
188189
});
189190

190-
let timer = Timer::new();
191+
let start = Instant::now();
191192
let reporter = self.reporter.clone();
192193

193194
if !has_ordered_listing {
@@ -198,7 +199,7 @@ impl<E: TaskExecutor> StorageHandler for ObjectStoreStorageHandler<E> {
198199
let num_files = fms.len() as u64;
199200
reporter.as_ref().inspect(|r| {
200201
r.report(MetricEvent::StorageListCompleted {
201-
duration: timer.elapsed(),
202+
duration: start.elapsed(),
202203
num_files,
203204
});
204205
});
@@ -208,7 +209,7 @@ impl<E: TaskExecutor> StorageHandler for ObjectStoreStorageHandler<E> {
208209
Ok(Box::new(ListMetricsIterator {
209210
inner: receiver.into_iter(),
210211
reporter,
211-
timer,
212+
start,
212213
count: 0,
213214
metrics_emitted: false,
214215
}))
@@ -276,15 +277,15 @@ impl<E: TaskExecutor> StorageHandler for ObjectStoreStorageHandler<E> {
276277
Ok(Box::new(ReadMetricsIterator {
277278
inner: receiver.into_iter(),
278279
reporter: self.reporter.clone(),
279-
timer: Timer::new(),
280+
start: Instant::now(),
280281
num_files,
281282
bytes_read: 0,
282283
metrics_emitted: false,
283284
}))
284285
}
285286

286287
fn copy_atomic(&self, src: &Url, dest: &Url) -> DeltaResult<()> {
287-
let timer = Timer::new();
288+
let start = Instant::now();
288289
let src_path = Path::from_url_path(src.path())?;
289290
let dest_path = Path::from_url_path(dest.path())?;
290291
let dest_path_str = dest_path.to_string();
@@ -310,7 +311,7 @@ impl<E: TaskExecutor> StorageHandler for ObjectStoreStorageHandler<E> {
310311

311312
self.reporter.as_ref().inspect(|r| {
312313
r.report(MetricEvent::StorageCopyCompleted {
313-
duration: timer.elapsed(),
314+
duration: start.elapsed(),
314315
});
315316
});
316317

kernel/src/metrics/events.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Metric event types and utilities.
22
33
use std::fmt;
4-
use std::time::{Duration, Instant};
4+
use std::time::Duration;
55
use uuid::Uuid;
66

77
/// Unique identifier for a metrics operation.
@@ -158,38 +158,3 @@ impl fmt::Display for MetricEvent {
158158
}
159159
}
160160
}
161-
162-
/// A simple timer for tracking operation durations.
163-
///
164-
/// # Example
165-
/// ```
166-
/// use delta_kernel::metrics::Timer;
167-
///
168-
/// let timer = Timer::new();
169-
/// // ... do work ...
170-
/// let duration = timer.elapsed();
171-
/// ```
172-
#[derive(Debug)]
173-
pub struct Timer {
174-
start: Instant,
175-
}
176-
177-
impl Timer {
178-
/// Create a new timer that starts immediately.
179-
pub fn new() -> Self {
180-
Self {
181-
start: Instant::now(),
182-
}
183-
}
184-
185-
/// Get the elapsed time as a Duration since this timer was created.
186-
pub fn elapsed(&self) -> Duration {
187-
self.start.elapsed()
188-
}
189-
}
190-
191-
impl Default for Timer {
192-
fn default() -> Self {
193-
Self::new()
194-
}
195-
}

kernel/src/metrics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@
7373
mod events;
7474
mod reporter;
7575

76-
pub use events::{MetricEvent, MetricId, Timer};
76+
pub use events::{MetricEvent, MetricId};
7777
pub use reporter::MetricsReporter;

kernel/src/snapshot.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! has schema etc.)
33
44
use std::sync::Arc;
5+
use std::time::Instant;
56

67
use crate::action_reconciliation::calculate_transaction_expiration_timestamp;
78
use crate::actions::domain_metadata::domain_metadata_configuration;
@@ -11,7 +12,7 @@ use crate::checkpoint::CheckpointWriter;
1112
use crate::committer::Committer;
1213
use crate::listed_log_files::ListedLogFiles;
1314
use crate::log_segment::LogSegment;
14-
use crate::metrics::{MetricEvent, MetricId, Timer};
15+
use crate::metrics::{MetricEvent, MetricId};
1516
use crate::path::ParsedLogPath;
1617
use crate::scan::ScanBuilder;
1718
use crate::schema::SchemaRef;
@@ -266,15 +267,15 @@ impl Snapshot {
266267
) -> DeltaResult<Self> {
267268
let operation_id = operation_id.unwrap_or_default();
268269
let reporter = engine.get_metrics_reporter();
269-
let timer = Timer::new();
270+
let start = Instant::now();
270271

271272
let result = {
272273
let (metadata, protocol) = log_segment.read_metadata(engine)?;
273274

274275
reporter.as_ref().inspect(|r| {
275276
r.report(MetricEvent::ProtocolMetadataLoaded {
276277
operation_id,
277-
duration: timer.elapsed(),
278+
duration: start.elapsed(),
278279
});
279280
});
280281

@@ -293,7 +294,7 @@ impl Snapshot {
293294
r.report(MetricEvent::SnapshotCompleted {
294295
operation_id,
295296
version: snapshot.version(),
296-
total_duration: timer.elapsed(),
297+
total_duration: start.elapsed(),
297298
});
298299
});
299300
Ok(snapshot)
@@ -302,7 +303,7 @@ impl Snapshot {
302303
reporter.as_ref().inspect(|r| {
303304
r.report(MetricEvent::SnapshotFailed {
304305
operation_id,
305-
duration: timer.elapsed(),
306+
duration: start.elapsed(),
306307
});
307308
});
308309
Err(e)

kernel/src/snapshot/builder.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Builder for creating [`Snapshot`] instances.
2+
use std::time::Instant;
3+
24
use crate::log_path::LogPath;
35
use crate::log_segment::LogSegment;
4-
use crate::metrics::{MetricEvent, MetricId, Timer};
6+
use crate::metrics::{MetricEvent, MetricId};
57
use crate::snapshot::SnapshotRef;
68
use crate::{DeltaResult, Engine, Error, Snapshot, Version};
79

@@ -106,7 +108,7 @@ impl SnapshotBuilder {
106108
});
107109

108110
if let Some(table_root) = self.table_root {
109-
let timer = Timer::new();
111+
let start = Instant::now();
110112
let log_segment_result = LogSegment::for_snapshot(
111113
engine.storage_handler().as_ref(),
112114
table_root.join("_delta_log/")?,
@@ -116,7 +118,7 @@ impl SnapshotBuilder {
116118

117119
let log_segment = match log_segment_result {
118120
Ok(seg) => {
119-
let duration = timer.elapsed();
121+
let duration = start.elapsed();
120122
reporter.as_ref().inspect(|r| {
121123
r.report(MetricEvent::LogSegmentLoaded {
122124
operation_id,
@@ -132,7 +134,7 @@ impl SnapshotBuilder {
132134
reporter.as_ref().inspect(|r| {
133135
r.report(MetricEvent::SnapshotFailed {
134136
operation_id,
135-
duration: timer.elapsed(),
137+
duration: start.elapsed(),
136138
});
137139
});
138140
return Err(e);
@@ -153,7 +155,7 @@ impl SnapshotBuilder {
153155
)
154156
})?;
155157

156-
let timer = Timer::new();
158+
let start = Instant::now();
157159
let result = Snapshot::try_new_from(existing_snapshot, log_tail, engine, self.version);
158160

159161
match result {
@@ -162,7 +164,7 @@ impl SnapshotBuilder {
162164
r.report(MetricEvent::SnapshotCompleted {
163165
operation_id,
164166
version: snapshot.version(),
165-
total_duration: timer.elapsed(),
167+
total_duration: start.elapsed(),
166168
});
167169
});
168170
Ok(snapshot)
@@ -171,7 +173,7 @@ impl SnapshotBuilder {
171173
reporter.as_ref().inspect(|r| {
172174
r.report(MetricEvent::SnapshotFailed {
173175
operation_id,
174-
duration: timer.elapsed(),
176+
duration: start.elapsed(),
175177
});
176178
});
177179
Err(e)

0 commit comments

Comments
 (0)