Skip to main content

paper_client/
status.rs

1/*
2 * Copyright (c) Kia Shakiba
3 *
4 * This source code is licensed under the GNU AGPLv3 license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8use crate::policy::PaperPolicy;
9
10#[derive(Debug)]
11pub struct Status {
12	pid: u32,
13
14	max_size:    u64,
15	used_size:   u64,
16	num_objects: u64,
17
18	rss: u64,
19	hwm: u64,
20
21	total_gets: u64,
22	total_sets: u64,
23	total_dels: u64,
24
25	miss_ratio: f64,
26
27	policies:       Vec<PaperPolicy>,
28	policy:         PaperPolicy,
29	is_auto_policy: bool,
30
31	uptime: u64,
32}
33
34impl Status {
35	/// Creates a new instance of the cache's status.
36	#[allow(clippy::too_many_arguments)]
37	#[must_use]
38	pub fn new(
39		pid: u32,
40
41		max_size: u64,
42		used_size: u64,
43		num_objects: u64,
44
45		rss: u64,
46		hwm: u64,
47
48		total_gets: u64,
49		total_sets: u64,
50		total_dels: u64,
51
52		miss_ratio: f64,
53
54		policies: Vec<PaperPolicy>,
55		policy: PaperPolicy,
56		is_auto_policy: bool,
57
58		uptime: u64,
59	) -> Self {
60		Status {
61			pid,
62
63			max_size,
64			used_size,
65			num_objects,
66
67			rss,
68			hwm,
69
70			total_gets,
71			total_sets,
72			total_dels,
73
74			miss_ratio,
75
76			policies,
77			policy,
78			is_auto_policy,
79
80			uptime,
81		}
82	}
83
84	/// Returns the cache's PID.
85	#[must_use]
86	pub fn pid(&self) -> u32 {
87		self.pid
88	}
89
90	/// Returns the cache's maximum size in bytes.
91	#[must_use]
92	pub fn max_size(&self) -> u64 {
93		self.max_size
94	}
95
96	/// Returns the cache's used size in bytes.
97	#[must_use]
98	pub fn used_size(&self) -> u64 {
99		self.used_size
100	}
101
102	/// Returns the number of objects in the cache.
103	#[must_use]
104	pub fn num_objects(&self) -> u64 {
105		self.num_objects
106	}
107
108	/// Returns the cache's resident set size.
109	#[must_use]
110	pub fn rss(&self) -> u64 {
111		self.rss
112	}
113
114	/// Returns the cache's resident set size high water mark.
115	#[must_use]
116	pub fn hwm(&self) -> u64 {
117		self.hwm
118	}
119
120	/// Returns the cache's total number of gets.
121	#[must_use]
122	pub fn total_gets(&self) -> u64 {
123		self.total_gets
124	}
125
126	/// Returns the cache's total number of sets.
127	#[must_use]
128	pub fn total_sets(&self) -> u64 {
129		self.total_sets
130	}
131
132	/// Returns the cache's total number of dels.
133	#[must_use]
134	pub fn total_dels(&self) -> u64 {
135		self.total_dels
136	}
137
138	/// Returns the cache's miss ratio.
139	#[must_use]
140	pub fn miss_ratio(&self) -> f64 {
141		self.miss_ratio
142	}
143
144	/// Returns the cache's configured eviction policies.
145	#[must_use]
146	pub fn policies(&self) -> &[PaperPolicy] {
147		&self.policies
148	}
149
150	/// Returns the cache's eviction policy.
151	#[must_use]
152	pub fn policy(&self) -> &PaperPolicy {
153		&self.policy
154	}
155
156	/// Returns `true` if the cache is configured to the [`PaperPolicy::Auto`]
157	/// eviction policy.
158	#[must_use]
159	pub fn is_auto_policy(&self) -> bool {
160		self.is_auto_policy
161	}
162
163	/// Returns the cache's uptime.
164	#[must_use]
165	pub fn uptime(&self) -> u64 {
166		self.uptime
167	}
168}