first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -11,10 +11,10 @@ use ordered_float::OrderedFloat;
|
||||
use serde::Serialize;
|
||||
use sysinfo::ProcessesToUpdate;
|
||||
|
||||
use crate::{
|
||||
send_telemetry_from_app_ctx, send_telemetry_sync_from_ctx, server::telemetry,
|
||||
system::memory_footprint, terminal::TerminalView, TelemetryEvent,
|
||||
};
|
||||
use crate::server::telemetry;
|
||||
use crate::system::memory_footprint;
|
||||
use crate::terminal::TerminalView;
|
||||
use crate::{send_telemetry_from_app_ctx, send_telemetry_sync_from_ctx, TelemetryEvent};
|
||||
|
||||
/// The threshold at which we emit a memory usage warning.
|
||||
const MEMORY_USAGE_WARNING_THRESHOLD: Option<Byte> = byte_unit::Byte::GIGABYTE.multiply(10);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use byte_unit::Byte;
|
||||
|
||||
use crate::{terminal::model::test_utils::TestBlockBuilder, test_util::mock_blockgrid};
|
||||
|
||||
use super::*;
|
||||
use crate::terminal::model::test_utils::TestBlockBuilder;
|
||||
use crate::test_util::mock_blockgrid;
|
||||
|
||||
#[test]
|
||||
fn test_memory_usage_stats_construction() {
|
||||
|
||||
@@ -151,13 +151,43 @@ mod platform {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// FreeBSD
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
mod platform {
|
||||
/// FreeBSD has no `/proc/self/status` by default (linprocfs is optional and
|
||||
/// rarely mounted), so we use `getrusage(RUSAGE_SELF)`. `ru_maxrss` is
|
||||
/// reported in kilobytes and represents the maximum resident set size, not
|
||||
/// the current value, but it's the closest portable signal we have without
|
||||
/// pulling in `kvm`/`sysctl(KERN_PROC_PID)` plumbing for one telemetry
|
||||
/// number.
|
||||
pub fn memory_footprint_bytes() -> u64 {
|
||||
let mut usage: libc::rusage = unsafe { std::mem::zeroed() };
|
||||
if unsafe { libc::getrusage(libc::RUSAGE_SELF, &mut usage) } != 0 {
|
||||
return 0;
|
||||
}
|
||||
(usage.ru_maxrss as u64).saturating_mul(1024)
|
||||
}
|
||||
|
||||
pub fn memory_breakdown() -> serde_json::Value {
|
||||
let mut usage: libc::rusage = unsafe { std::mem::zeroed() };
|
||||
if unsafe { libc::getrusage(libc::RUSAGE_SELF, &mut usage) } != 0 {
|
||||
return serde_json::json!({});
|
||||
}
|
||||
serde_json::json!({
|
||||
"ru_maxrss": (usage.ru_maxrss as u64).saturating_mul(1024),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Windows
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod platform {
|
||||
use std::mem;
|
||||
|
||||
use windows::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
|
||||
use windows::Win32::System::Threading::GetCurrentProcess;
|
||||
|
||||
Reference in New Issue
Block a user