Skip to content

Commit 1c47f73

Browse files
committed
feat: add parsing time
1 parent 4294f53 commit 1c47f73

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tcping"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
authors = ["lvillis<[email protected]>"]
55
edition = "2021"
66
description = "A tool for testing native-to-target port latency, using Rust."

src/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ struct Summary {
6060
min_duration_ms: f64,
6161
avg_duration_ms: f64,
6262
max_duration_ms: f64,
63+
resolve_time_ms: f64,
6364
}
6465

6566
fn main() {
6667
let args = Args::parse();
6768

69+
let resolve_start = Instant::now();
70+
6871
// Validate and resolve the address
6972
let addr = match args.address.to_socket_addrs() {
7073
Ok(mut addrs) => match addrs.next() {
@@ -80,6 +83,8 @@ fn main() {
8083
}
8184
};
8285

86+
let resolve_duration = resolve_start.elapsed().as_micros() as f64 / 1000.0;
87+
8388
// Validate the port
8489
if addr.port() == 0 {
8590
eprintln!("Error: Invalid port number");
@@ -101,6 +106,7 @@ fn main() {
101106
}
102107
if args.output_mode == OutputMode::Normal {
103108
println!();
109+
println!("Resolved address in {:.4} ms", resolve_duration);
104110
}
105111

106112
let mut successful_pings = 0;
@@ -237,6 +243,7 @@ fn main() {
237243
} else {
238244
0.0
239245
},
246+
resolve_time_ms: resolve_duration,
240247
};
241248

242249
println!("\n--- {} tcping statistics ---", addr);
@@ -250,6 +257,7 @@ fn main() {
250257
summary.min_duration_ms, summary.avg_duration_ms, summary.max_duration_ms
251258
);
252259
}
260+
println!("Address resolved in {:.4} ms", summary.resolve_time_ms);
253261
println!();
254262
} else if args.output_mode == OutputMode::Json {
255263
let summary = Summary {
@@ -272,13 +280,14 @@ fn main() {
272280
} else {
273281
0.0
274282
},
283+
resolve_time_ms: resolve_duration,
275284
};
276285
let json = serde_json::to_string(&summary).unwrap();
277286
println!("{}", json);
278287
} else if args.output_mode == OutputMode::Csv {
279-
println!("address,total_probes,successful_probes,packet_loss,min_rtt,avg_rtt,max_rtt");
288+
println!("address,total_probes,successful_probes,packet_loss,min_rtt,avg_rtt,max_rtt,resolve_time_ms");
280289
println!(
281-
"{},{},{},{:.2},{:.4},{:.4},{:.4}",
290+
"{},{},{},{:.2},{:.4},{:.4},{:.4},{:.4}",
282291
addr,
283292
total_attempts,
284293
successful_pings,
@@ -289,7 +298,8 @@ fn main() {
289298
} else {
290299
0.0
291300
},
292-
if successful_pings > 0 { max_duration } else { 0.0 }
301+
if successful_pings > 0 { max_duration } else { 0.0 },
302+
resolve_duration
293303
);
294304
}
295305
}

0 commit comments

Comments
 (0)