tokio_quiche/http3/
stats.rs1use std::sync::atomic::AtomicI64;
28use std::sync::atomic::AtomicU64;
29use std::sync::atomic::Ordering;
30
31use crossbeam::atomic::AtomicCell;
32use datagram_socket::StreamClosureKind;
33
34#[derive(Debug)]
37pub struct H3AuditStats {
38 stream_id: u64,
40 downstream_bytes_sent: AtomicU64,
42 downstream_bytes_recvd: AtomicU64,
44 recvd_stop_sending_error_code: AtomicI64,
48 recvd_reset_stream_error_code: AtomicI64,
52 sent_stop_sending_error_code: AtomicI64,
56 sent_reset_stream_error_code: AtomicI64,
60 recvd_stream_fin: AtomicCell<StreamClosureKind>,
62 sent_stream_fin: AtomicCell<StreamClosureKind>,
64}
65
66impl H3AuditStats {
67 pub fn new(stream_id: u64) -> Self {
68 Self {
69 stream_id,
70 downstream_bytes_sent: AtomicU64::new(0),
71 downstream_bytes_recvd: AtomicU64::new(0),
72 recvd_stop_sending_error_code: AtomicI64::new(-1),
73 recvd_reset_stream_error_code: AtomicI64::new(-1),
74 sent_stop_sending_error_code: AtomicI64::new(-1),
75 sent_reset_stream_error_code: AtomicI64::new(-1),
76 recvd_stream_fin: AtomicCell::new(StreamClosureKind::None),
77 sent_stream_fin: AtomicCell::new(StreamClosureKind::None),
78 }
79 }
80
81 #[inline]
83 pub fn stream_id(&self) -> u64 {
84 self.stream_id
85 }
86
87 #[inline]
89 pub fn downstream_bytes_sent(&self) -> u64 {
90 self.downstream_bytes_sent.load(Ordering::SeqCst)
91 }
92
93 #[inline]
95 pub fn downstream_bytes_recvd(&self) -> u64 {
96 self.downstream_bytes_recvd.load(Ordering::SeqCst)
97 }
98
99 #[inline]
103 pub fn recvd_stop_sending_error_code(&self) -> i64 {
104 self.recvd_stop_sending_error_code.load(Ordering::SeqCst)
105 }
106
107 #[inline]
111 pub fn recvd_reset_stream_error_code(&self) -> i64 {
112 self.recvd_reset_stream_error_code.load(Ordering::SeqCst)
113 }
114
115 #[inline]
119 pub fn sent_stop_sending_error_code(&self) -> i64 {
120 self.sent_stop_sending_error_code.load(Ordering::SeqCst)
121 }
122
123 #[inline]
127 pub fn sent_reset_stream_error_code(&self) -> i64 {
128 self.sent_reset_stream_error_code.load(Ordering::SeqCst)
129 }
130
131 #[inline]
133 pub fn recvd_stream_fin(&self) -> StreamClosureKind {
134 self.recvd_stream_fin.load()
135 }
136
137 #[inline]
139 pub fn sent_stream_fin(&self) -> StreamClosureKind {
140 self.sent_stream_fin.load()
141 }
142
143 #[inline]
144 pub fn add_downstream_bytes_sent(&self, bytes_sent: u64) {
145 self.downstream_bytes_sent
146 .fetch_add(bytes_sent, Ordering::SeqCst);
147 }
148
149 #[inline]
150 pub fn add_downstream_bytes_recvd(&self, bytes_recvd: u64) {
151 self.downstream_bytes_recvd
152 .fetch_add(bytes_recvd, Ordering::SeqCst);
153 }
154
155 #[inline]
156 pub fn set_recvd_stop_sending_error_code(
157 &self, recvd_stop_sending_error_code: i64,
158 ) {
159 self.recvd_stop_sending_error_code
160 .store(recvd_stop_sending_error_code, Ordering::SeqCst);
161 }
162
163 #[inline]
164 pub fn set_recvd_reset_stream_error_code(
165 &self, recvd_reset_stream_error_code: i64,
166 ) {
167 self.recvd_reset_stream_error_code
168 .store(recvd_reset_stream_error_code, Ordering::SeqCst);
169 }
170
171 #[inline]
172 pub fn set_sent_stop_sending_error_code(
173 &self, sent_stop_sending_error_code: i64,
174 ) {
175 self.sent_stop_sending_error_code
176 .store(sent_stop_sending_error_code, Ordering::SeqCst);
177 }
178
179 #[inline]
180 pub fn set_sent_reset_stream_error_code(
181 &self, sent_reset_stream_error_code: i64,
182 ) {
183 self.sent_reset_stream_error_code
184 .store(sent_reset_stream_error_code, Ordering::SeqCst);
185 }
186
187 #[inline]
188 pub fn set_recvd_stream_fin(&self, recvd_stream_fin: StreamClosureKind) {
189 self.recvd_stream_fin.store(recvd_stream_fin);
190 }
191
192 #[inline]
193 pub fn set_sent_stream_fin(&self, sent_stream_fin: StreamClosureKind) {
194 self.sent_stream_fin.store(sent_stream_fin);
195 }
196}