-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memory and flops stats to NodeTelemetry (#1358)
Co-authored-by: duc-nx <>
- Loading branch information
Showing
5 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::process; | ||
use sysinfo::System; | ||
|
||
// We encode the memory usage to i32 type at client | ||
pub fn bytes_to_mb_i32(bytes: u64) -> i32 { | ||
// Convert to MB with 3 decimal places of precision | ||
// Multiply by 1000 to preserve 3 decimal places | ||
((bytes as f64 * 1000.0) / 1_048_576.0).round() as i32 | ||
} | ||
|
||
// At server, we decode the memory usage from i32 to f32 to get correct memory usage | ||
#[allow(dead_code)] | ||
pub fn mb_i32_to_f32(mb: i32) -> f32 { | ||
// Convert back to f32, dividing by 1000 to get the correct value | ||
(mb as f32) / 1000.0 | ||
} | ||
|
||
pub fn get_memory_info() -> (i32, i32) { | ||
let mut system = System::new_all(); | ||
system.refresh_all(); | ||
|
||
let current_pid = process::id(); | ||
let current_process = system | ||
.process(sysinfo::Pid::from(current_pid as usize)) | ||
.expect("Failed to get current process"); | ||
|
||
let program_memory = current_process.memory(); | ||
let total_memory = system.total_memory(); | ||
|
||
( | ||
bytes_to_mb_i32(program_memory), | ||
bytes_to_mb_i32(total_memory), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters