From 67825725c9b4710d2353cff15e135f9a03642189 Mon Sep 17 00:00:00 2001 From: Kunle Li <1041593558@qq.com> Date: Tue, 30 Apr 2024 20:45:55 -0400 Subject: [PATCH] feat: print output in table --- Cargo.lock | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/benchmark.rs | 49 ++++++++++++++++++++++------- 3 files changed, 119 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a2ef41..bb4a89e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -551,6 +551,7 @@ dependencies = [ "istziio-client", "log", "parquet", + "prettytable", "reqwest", "rocket", "thiserror", @@ -688,12 +689,39 @@ dependencies = [ "syn", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "either" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -1267,6 +1295,16 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.5.0", + "libc", +] + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -1694,6 +1732,20 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettytable" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46480520d1b77c9a3482d39939fcf96831537a250ec62d4fd8fbdf8e0302e781" +dependencies = [ + "csv", + "encode_unicode", + "is-terminal", + "lazy_static", + "term", + "unicode-width", +] + [[package]] name = "proc-macro2" version = "1.0.81" @@ -1764,6 +1816,17 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "ref-cast" version = "1.0.22" @@ -2244,6 +2307,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + [[package]] name = "termcolor" version = "1.4.1" @@ -2577,6 +2651,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" + [[package]] name = "unicode-xid" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index f0c623d..7f62863 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ rocket = { version = "0.5.0", features = ["json"] } reqwest = { version = "0.11", features = ["stream", "json"] } csv = "1.3.0" istziio-client = "0.1.6" +prettytable = "0.10.0" diff --git a/src/benchmark.rs b/src/benchmark.rs index 09896f3..bdc06fd 100644 --- a/src/benchmark.rs +++ b/src/benchmark.rs @@ -1,4 +1,5 @@ use istziio_client::client_api::{StorageClient, StorageRequest}; +use prettytable::{Cell, Row, Table}; use std::error::Error; use std::path::PathBuf; use std::thread::sleep; @@ -53,10 +54,6 @@ pub async fn run_trace( StorageRequest::Table(id) => id, _ => panic!("Invalid request type"), }; - println!( - "Trace {} sends request for table {} at timestamp {}", - i, table_id, trace.timestamp - ); let client_start = Instant::now(); let res = client.request_data(trace.request).await; @@ -69,21 +66,51 @@ pub async fn run_trace( total_num_rows += rb.num_rows(); } let client_duration = client_start.elapsed(); - println!( - "Trace {} gets {} rows from the client, latency is {:?}", - i, total_num_rows, client_duration - ); - tx.send(client_duration).await.unwrap(); + tx.send(( + i, + table_id, + total_num_rows, + trace.timestamp, + client_duration, + )) + .await + .unwrap(); }); } // Collect and print client latencies let mut duration_sum = Duration::new(0, 0); + let mut rows = Vec::new(); for _ in 0..request_num { - let client_duration = rx.recv().await.unwrap(); - duration_sum += client_duration; + let tuple = rx.recv().await.unwrap(); + rows.push(tuple); + duration_sum += tuple.4; + } + + // Sort rows based on the first element of the tuple + rows.sort_by(|a, b| a.0.cmp(&b.0)); + + // Construct a table to print the results + let mut table = Table::new(); + table.add_row(Row::new(vec![ + Cell::new("Trace ID"), + Cell::new("File ID"), + Cell::new("Num Rows"), + Cell::new("Arrival Time"), + Cell::new("Wait Time"), + ])); + + for row in rows { + table.add_row(Row::new(vec![ + Cell::new(&row.0.to_string()), + Cell::new(&row.1.to_string()), + Cell::new(&row.2.to_string()), + Cell::new(&row.3.to_string()), + Cell::new(&row.4.as_millis().to_string()), + ])); } let avg_duration = duration_sum.div_f32(request_num as f32); + table.printstd(); println!("Average duration: {:?}", avg_duration); }