Skip to content

Commit b56672f

Browse files
committed
chore: update rustfmt & rust-toolchain
Signed-off-by: Wenxuan Zhang <[email protected]>
1 parent 43bccb6 commit b56672f

File tree

10 files changed

+99
-91
lines changed

10 files changed

+99
-91
lines changed

.rustfmt.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = ["rustfmt", "clippy", "rust-analyzer"]

rustfmt.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
edition = "2021"
2+
max_width = 120
3+
reorder_imports = true
4+
struct_lit_width = 60
5+
struct_variant_width = 60
6+
7+
# struct_field_align_threshold = 40
8+
# comment_width = 120
9+
# fn_single_line = false
10+
# imports_layout = "HorizontalVertical"
11+
# match_arm_blocks = false
12+
# overflow_delimited_expr = true
13+
# imports_granularity = "Crate"

src/collector/silent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::{
1414

1515
pub struct SilentCollector {
1616
bench_opts: BenchOpts,
17-
res_rx: UnboundedReceiver<Result<IterReport>>,
18-
cancel: CancellationToken,
17+
res_rx: UnboundedReceiver<Result<IterReport>>,
18+
cancel: CancellationToken,
1919
}
2020

2121
impl SilentCollector {

src/collector/tui.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use async_trait::async_trait;
33
use crossterm::{
44
cursor,
55
event::{Event, KeyCode, KeyEvent, KeyModifiers},
6-
terminal,
7-
ExecutableCommand,
6+
terminal, ExecutableCommand,
87
};
98
use itertools::Itertools;
109
use ratatui::{
@@ -13,8 +12,7 @@ use ratatui::{
1312
style::{Color, Style, Stylize},
1413
text::Line,
1514
widgets::{block::Title, BarChart, Block, Borders, Clear, Gauge, Padding, Paragraph},
16-
CompletedFrame,
17-
Frame,
15+
CompletedFrame, Frame,
1816
};
1917
use std::{collections::HashMap, fmt, io, time::Duration};
2018
use tokio::{
@@ -35,10 +33,10 @@ use crate::{
3533

3634
pub struct TuiCollector {
3735
pub bench_opts: BenchOpts,
38-
pub fps: u8,
39-
pub res_rx: mpsc::UnboundedReceiver<Result<IterReport>>,
40-
pub pause: watch::Sender<bool>,
41-
pub cancel: CancellationToken,
36+
pub fps: u8,
37+
pub res_rx: mpsc::UnboundedReceiver<Result<IterReport>>,
38+
pub pause: watch::Sender<bool>,
39+
pub cancel: CancellationToken,
4240
}
4341

4442
impl TuiCollector {
@@ -274,10 +272,13 @@ fn render_stats_rate(counter: &Counter, elapsed: Duration) -> Paragraph<'static>
274272
let lines = vec![
275273
Line::from(format!("{:.2} iters/s", counter.iters as f64 / secs)),
276274
Line::from(format!("{:.2} items/s", counter.items as f64 / secs)),
277-
Line::from(format!("{}/s", match (counter.bytes as f64 / secs).to_bytes() {
278-
Ok(bps) => format!("{:.2}", bps),
279-
Err(_) => "NaN B".to_string(),
280-
})),
275+
Line::from(format!(
276+
"{}/s",
277+
match (counter.bytes as f64 / secs).to_bytes() {
278+
Ok(bps) => format!("{:.2}", bps),
279+
Err(_) => "NaN B".to_string(),
280+
}
281+
)),
281282
];
282283
Paragraph::new(lines).block(Block::new().borders(Borders::NONE))
283284
}
@@ -450,9 +451,9 @@ fn render_latency_hist(frame: &mut Frame, area: Rect, hist: &LatencyHistogram, h
450451
return;
451452
}
452453
let area = Rect {
453-
x: area.x + area.width - width as u16,
454-
y: area.y,
455-
width: width as u16,
454+
x: area.x + area.width - width as u16,
455+
y: area.y,
456+
width: width as u16,
456457
height: content.len() as u16,
457458
};
458459
let content = content.into_iter().map(Line::from).collect_vec();

src/report.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ use crate::{
1111
#[derive(Debug, Clone)]
1212
pub struct IterReport {
1313
pub duration: Duration,
14-
pub status: Status,
15-
pub bytes: u64,
16-
pub items: u64,
14+
pub status: Status,
15+
pub bytes: u64,
16+
pub items: u64,
1717
}
1818

1919
pub struct BenchReport {
2020
pub concurrency: u32,
21-
pub hist: LatencyHistogram,
22-
pub stats: IterStats,
21+
pub hist: LatencyHistogram,
22+
pub stats: IterStats,
2323
pub status_dist: HashMap<Status, u64>,
24-
pub error_dist: HashMap<String, u64>,
25-
pub elapsed: Duration,
24+
pub error_dist: HashMap<String, u64>,
25+
pub elapsed: Duration,
2626
}
2727

2828
impl BenchReport {

src/reporter/json.rs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ impl BenchReporter for JsonReporter {
1313
let counter = &report.stats.counter;
1414
let summary = Summary {
1515
success_ratio: report.success_ratio(),
16-
total_time: elapsed,
17-
concurrency: report.concurrency,
16+
total_time: elapsed,
17+
concurrency: report.concurrency,
1818

1919
iters: ItersSummary {
20-
total: counter.iters,
21-
rate: counter.iters as f64 / elapsed,
20+
total: counter.iters,
21+
rate: counter.iters as f64 / elapsed,
2222
bytes_per_iter: counter.bytes.checked_div(counter.iters),
2323
},
2424

2525
items: ItemsSummary {
26-
total: counter.items,
27-
rate: counter.items as f64 / elapsed,
26+
total: counter.items,
27+
rate: counter.items as f64 / elapsed,
2828
items_per_iter: counter.items as f64 / counter.iters as f64,
2929
bytes_per_item: counter.bytes.checked_div(counter.items),
3030
},
@@ -36,19 +36,19 @@ impl BenchReporter for JsonReporter {
3636
None
3737
} else {
3838
Latency {
39-
stats: LatencyStats {
40-
min: report.hist.min().as_secs_f64(),
41-
max: report.hist.max().as_secs_f64(),
42-
mean: report.hist.mean().as_secs_f64(),
39+
stats: LatencyStats {
40+
min: report.hist.min().as_secs_f64(),
41+
max: report.hist.max().as_secs_f64(),
42+
mean: report.hist.mean().as_secs_f64(),
4343
median: report.hist.median().as_secs_f64(),
44-
stdev: report.hist.stdev().as_secs_f64(),
44+
stdev: report.hist.stdev().as_secs_f64(),
4545
},
4646
percentiles: report
4747
.hist
4848
.percentiles(PERCENTAGES)
4949
.map(|(p, v)| (format!("p{p}"), v.as_secs_f64()))
5050
.collect(),
51-
histogram: report
51+
histogram: report
5252
.hist
5353
.quantiles()
5454
.map(|(k, v)| (k.as_secs_f64().to_string(), v))
@@ -57,12 +57,15 @@ impl BenchReporter for JsonReporter {
5757
.into()
5858
};
5959

60-
serde_json::to_writer_pretty(&mut *w, &Report {
61-
summary,
62-
latency,
63-
status: report.status_dist.iter().map(|(k, &v)| (k.to_string(), v)).collect(),
64-
errors: report.error_dist.iter().map(|(k, &v)| (k.clone(), v)).collect(),
65-
})?;
60+
serde_json::to_writer_pretty(
61+
&mut *w,
62+
&Report {
63+
summary,
64+
latency,
65+
status: report.status_dist.iter().map(|(k, &v)| (k.to_string(), v)).collect(),
66+
errors: report.error_dist.iter().map(|(k, &v)| (k.clone(), v)).collect(),
67+
},
68+
)?;
6669

6770
writeln!(w)?;
6871
Ok(())
@@ -72,8 +75,8 @@ impl BenchReporter for JsonReporter {
7275
#[derive(Serialize)]
7376
struct Summary {
7477
success_ratio: f64,
75-
total_time: f64,
76-
concurrency: u32,
78+
total_time: f64,
79+
concurrency: u32,
7780

7881
iters: ItersSummary,
7982
items: ItemsSummary,
@@ -82,16 +85,16 @@ struct Summary {
8285

8386
#[derive(Serialize)]
8487
struct ItersSummary {
85-
total: u64,
86-
rate: f64,
88+
total: u64,
89+
rate: f64,
8790
#[serde(skip_serializing_if = "Option::is_none")]
8891
bytes_per_iter: Option<u64>,
8992
}
9093

9194
#[derive(Serialize)]
9295
struct ItemsSummary {
93-
total: u64,
94-
rate: f64,
96+
total: u64,
97+
rate: f64,
9598
#[serde(skip_serializing_if = "not_normal_f64")]
9699
items_per_iter: f64,
97100
#[serde(skip_serializing_if = "Option::is_none")]
@@ -101,32 +104,32 @@ struct ItemsSummary {
101104
#[derive(Serialize)]
102105
struct BytesSummary {
103106
total: u64,
104-
rate: f64,
107+
rate: f64,
105108
}
106109

107110
#[derive(Serialize)]
108111
pub struct LatencyStats {
109-
min: f64,
110-
max: f64,
111-
mean: f64,
112+
min: f64,
113+
max: f64,
114+
mean: f64,
112115
median: f64,
113-
stdev: f64,
116+
stdev: f64,
114117
}
115118

116119
#[derive(Serialize)]
117120
pub struct Latency {
118-
stats: LatencyStats,
121+
stats: LatencyStats,
119122
percentiles: BTreeMap<String, f64>,
120-
histogram: BTreeMap<String, u64>,
123+
histogram: BTreeMap<String, u64>,
121124
}
122125

123126
#[derive(Serialize)]
124127
struct Report {
125128
summary: Summary,
126129
#[serde(skip_serializing_if = "Option::is_none")]
127130
latency: Option<Latency>,
128-
status: BTreeMap<String, u64>,
129-
errors: BTreeMap<String, u64>,
131+
status: BTreeMap<String, u64>,
132+
errors: BTreeMap<String, u64>,
130133
}
131134

132135
fn not_normal_f64(v: &f64) -> bool {

src/runner.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use crate::report::IterReport;
2020

2121
#[derive(Copy, Clone, Debug)]
2222
pub struct BenchOpts {
23-
pub start: Instant,
23+
pub start: Instant,
2424
pub concurrency: u32,
25-
pub iterations: Option<u64>,
26-
pub duration: Option<Duration>,
27-
pub rate: Option<u32>, // iterations per second
25+
pub iterations: Option<u64>,
26+
pub duration: Option<Duration>,
27+
pub rate: Option<u32>, // iterations per second
2828
}
2929

3030
impl BenchOpts {
@@ -50,17 +50,17 @@ pub struct Runner<BS>
5050
where
5151
BS: BenchSuite,
5252
{
53-
suite: BS,
54-
opts: BenchOpts,
55-
res_tx: mpsc::UnboundedSender<Result<IterReport>>,
56-
pause: watch::Receiver<bool>,
57-
cancel: CancellationToken,
53+
suite: BS,
54+
opts: BenchOpts,
55+
res_tx: mpsc::UnboundedSender<Result<IterReport>>,
56+
pause: watch::Receiver<bool>,
57+
cancel: CancellationToken,
5858
counter: Arc<AtomicU64>,
5959
}
6060

6161
pub struct WorkerState {
62-
rng: StdRng,
63-
worker_id: u32,
62+
rng: StdRng,
63+
worker_id: u32,
6464
worker_seq: u64,
6565
global_seq: u64,
6666
}

src/stats/counter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::report::IterReport;
44

55
#[derive(Default, Clone, Copy, Debug)]
66
pub struct Counter {
7-
pub iters: u64,
8-
pub items: u64,
9-
pub bytes: u64,
7+
pub iters: u64,
8+
pub items: u64,
9+
pub bytes: u64,
1010
pub duration: Duration,
1111
}
1212

src/stats/window.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::IterStats;
1111

1212
pub struct RotateWindow {
1313
buckets: VecDeque<IterStats>,
14-
size: usize,
14+
size: usize,
1515
}
1616

1717
impl RotateWindow {
@@ -58,10 +58,10 @@ impl RotateWindow {
5858
}
5959

6060
pub struct RotateWindowGroup {
61-
frame: Instant,
62-
pub stats_by_sec: RotateWindow,
61+
frame: Instant,
62+
pub stats_by_sec: RotateWindow,
6363
pub stats_by_10sec: RotateWindow,
64-
pub stats_by_min: RotateWindow,
64+
pub stats_by_min: RotateWindow,
6565
pub stats_by_10min: RotateWindow,
6666
}
6767

@@ -102,11 +102,11 @@ impl RotateWindowGroup {
102102
}
103103

104104
pub struct RotateDiffWindowGroup {
105-
frame: Instant,
106-
interval: Duration,
107-
stats_last_sec: RotateWindow,
105+
frame: Instant,
106+
interval: Duration,
107+
stats_last_sec: RotateWindow,
108108
stats_last_10sec: RotateWindow,
109-
stats_last_min: RotateWindow,
109+
stats_last_min: RotateWindow,
110110
stats_last_10min: RotateWindow,
111111
}
112112

0 commit comments

Comments
 (0)