Skip to main content

web_faith/
stats.rs

1//! Request counters.
2
3use std::sync::atomic::{AtomicU64, Ordering};
4
5/// The live counters, shared with every response the agent produces: a body finishing
6/// settles two of them.
7#[derive(Debug, Default)]
8pub(crate) struct InnerAgentStats {
9	pub requests_sent: AtomicU64,
10	pub responses_received: AtomicU64,
11	pub bodies_started: AtomicU64,
12	pub bodies_finished: AtomicU64,
13}
14
15impl InnerAgentStats {
16	pub fn snapshot(&self) -> AgentStats {
17		AgentStats {
18			requests_sent: self.requests_sent.load(Ordering::Relaxed),
19			responses_received: self.responses_received.load(Ordering::Relaxed),
20			bodies_started: self.bodies_started.load(Ordering::Relaxed),
21			bodies_finished: self.bodies_finished.load(Ordering::Relaxed),
22		}
23	}
24}
25
26/// Statistics gathered by the agent.
27///
28/// A snapshot taken when [`Agent::stats`](crate::Agent::stats) is called; it does not update live.
29#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
30#[non_exhaustive]
31pub struct AgentStats {
32	/// Requests that have gone out.
33	pub requests_sent: u64,
34	/// Responses whose headers have come back.
35	pub responses_received: u64,
36	/// Response body streams that have been started. Reading a body starts one.
37	pub bodies_started: u64,
38	/// Response body streams read to the end. The gap against `bodies_started` is how many bodies
39	/// are holding a connection open.
40	pub bodies_finished: u64,
41}