tpchgen_cli/
statistics.rs1use log::{debug, info};
4use std::time::Instant;
5
6#[derive(Clone, Debug)]
10pub struct WriteStatistics {
11 start: Instant,
13 num_chunks: usize,
15 chunk_label: String,
16 num_bytes: usize,
18}
19
20impl WriteStatistics {
21 pub fn new(chunk_label: impl Into<String>) -> Self {
23 Self {
24 start: Instant::now(),
25 num_chunks: 0,
26 chunk_label: chunk_label.into(),
27 num_bytes: 0,
28 }
29 }
30
31 pub fn increment_chunks(&mut self, num_chunks: usize) {
33 self.num_chunks += num_chunks;
34 }
35
36 pub fn increment_bytes(&mut self, num_bytes: usize) {
38 self.num_bytes += num_bytes;
39 }
40}
41
42impl Drop for WriteStatistics {
43 fn drop(&mut self) {
44 let duration = self.start.elapsed();
45 let mb_per_chunk = self.num_bytes as f64 / (1024.0 * 1024.0) / self.num_chunks as f64;
46 let bytes_per_second = (self.num_bytes as f64 / duration.as_secs_f64()) as u64;
47 let gb_per_second = bytes_per_second as f64 / (1024.0 * 1024.0 * 1024.0);
48 let gb = self.num_bytes as f64 / (1024.0 * 1024.0 * 1024.0);
49
50 info!("Created {gb:.02} GB in {duration:?} ({gb_per_second:.02} GB/sec)");
51 debug!(
52 "Wrote {} bytes in {} {} {mb_per_chunk:.02} MB/{}",
53 self.num_bytes, self.num_chunks, self.chunk_label, self.chunk_label
54 );
55 }
56}