1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use serde::{Deserialize, Serialize};
use std::{io::Error, path::Path};
use tokio::{
fs::File,
io::{AsyncWriteExt, BufWriter},
sync::mpsc,
};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct LinkDump {
pub present: bool,
pub link_id: u128,
pub unconfirmed: bool,
pub tx_idle: bool,
pub tx_pending: bool,
pub tx_flushing: bool,
pub tx_flushed: bool,
pub tx_ack_queue: usize,
pub txed_unacked_data: usize,
pub txed_unacked_data_limit: usize,
pub txed_unacked_data_limit_increased_consecutively: usize,
pub total_sent: u64,
pub total_recved: u64,
pub roundtrip: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnDump {
pub conn_id: u128,
pub runtime: f32,
pub txed_unacked: usize,
pub txed_unconsumed: usize,
pub txed_unconsumable: usize,
pub send_buffer: u32,
pub remote_receive_buffer: u32,
pub resend_queue: usize,
pub rxed_reliable_size: usize,
pub rxed_reliable_consumed_since_last_ack: usize,
pub link0: LinkDump,
pub link1: LinkDump,
pub link2: LinkDump,
pub link3: LinkDump,
pub link4: LinkDump,
pub link5: LinkDump,
pub link6: LinkDump,
pub link7: LinkDump,
pub link8: LinkDump,
pub link9: LinkDump,
}
pub async fn dump_to_json_line_file(
path: impl AsRef<Path>, mut rx: mpsc::Receiver<ConnDump>,
) -> Result<(), Error> {
let file = File::create(path).await?;
let mut writer = BufWriter::new(file);
while let Some(dump) = rx.recv().await {
let line = serde_json::to_vec(&dump).unwrap();
writer.write_all(&line).await?;
writer.write_u8(b'\n').await?;
}
writer.flush().await?;
Ok(())
}