Skip to content

Commit f470aaf

Browse files
committed
Add memory metrics to console api.
1 parent b4e8430 commit f470aaf

File tree

6 files changed

+32
-6
lines changed

6 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
### Fixed
88

9+
# 0.1.29
10+
11+
### Added
12+
- Added memory statistics to the console api.
13+
914
# 0.1.28
1015

1116
### Changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sha2 = "0.10"
1818
pin-project-lite = "0.2"
1919
bincode = "2.0.0-rc.3"
2020
pingora-timeout = "0.2"
21+
memory-stats = "1.2"
2122
smallvec = "1.13"
2223
arc-swap = "1.7"
2324
bytes = { version = "1.0", default-features = false }
@@ -32,8 +33,8 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
3233
tracing-subscriber = "0.3"
3334
dashmap = "6.0.1"
3435

35-
hydra-macros = { version = "0.1.28", path = "./hydra-macros" }
36-
hydra = { version = "0.1.28", path = "./hydra", default-features = false }
36+
hydra-macros = { version = "0.1.29", path = "./hydra-macros" }
37+
hydra = { version = "0.1.29", path = "./hydra", default-features = false }
3738

3839
[profile.release]
3940
lto = "fat"

hydra-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hydra-macros"
3-
version = "0.1.28"
3+
version = "0.1.29"
44
edition = "2021"
55
license.workspace = true
66
repository.workspace = true

hydra-websockets/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hydra-websockets"
3-
version = "0.1.28"
3+
version = "0.1.29"
44
edition = "2021"
55
readme = "./README.md"
66
license.workspace = true

hydra/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hydra"
3-
version = "0.1.28"
3+
version = "0.1.29"
44
edition = "2021"
55
readme.workspace = true
66
license.workspace = true
@@ -13,7 +13,7 @@ description.workspace = true
1313
default = ["macros", "tracing"]
1414
tracing = ["dep:tracing", "dep:tracing-subscriber"]
1515
macros = ["dep:hydra-macros"]
16-
console = []
16+
console = ["dep:memory-stats"]
1717

1818
[dependencies]
1919
flume.workspace = true
@@ -37,3 +37,5 @@ hydra-macros = { workspace = true, optional = true }
3737

3838
tracing = { workspace = true, optional = true }
3939
tracing-subscriber = { workspace = true, optional = true }
40+
41+
memory-stats = { workspace = true, optional = true }

hydra/src/runtime_info.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,38 @@ pub struct RuntimeInfo {
1616
pub worker_threads: usize,
1717
/// The number of processes currently running.
1818
pub processes: usize,
19+
/// The "physical" memory used by this process, in bytes.
20+
/// This corresponds to the following
21+
/// metric on each platform:
22+
/// - **Linux, Android, MacOS, iOS**: Resident Set Size.
23+
/// - **Windows**: Working Set.
24+
pub physical_memory: usize,
25+
/// The "virtual" memory used by this process, in bytes.
26+
/// This corresponds to the following
27+
/// metric on each platform:
28+
/// - **Linux, Android, MacOS, iOS**: Virtual Size.
29+
/// - **Windows**: Pagefile Usage.
30+
pub virtual_memory: usize,
1931
}
2032

2133
impl RuntimeInfo {
2234
/// Constructs and loads [RuntimeInfo] data, must be called from within the runtime.
2335
pub(super) fn load() -> Self {
2436
let runtime = Handle::current();
2537

38+
let (physical_memory, virtual_memory) = memory_stats::memory_stats()
39+
.map(|stats| (stats.physical_mem, stats.virtual_mem))
40+
.unwrap_or_default();
41+
2642
Self {
2743
system_version: String::from(env!("CARGO_PKG_VERSION")),
2844
logical_cpus: std::thread::available_parallelism()
2945
.map(|cpus| cpus.get())
3046
.unwrap_or_default(),
3147
worker_threads: runtime.metrics().num_workers(),
3248
processes: process_len(),
49+
physical_memory,
50+
virtual_memory,
3351
}
3452
}
3553
}

0 commit comments

Comments
 (0)