MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / cpu_percent

Function cpu_percent

packages/server/src/performance.rs:688–709  ·  view source on GitHub ↗
(
    raw: &RawPerformanceSample,
    previous: Option<&RawCounterSnapshot>,
    current: &RawCounterSnapshot,
)

Source from the content-addressed store, hash-verified

686}
687
688fn cpu_percent(
689 raw: &RawPerformanceSample,
690 previous: Option<&RawCounterSnapshot>,
691 current: &RawCounterSnapshot,
692) -> f64 {
693 let Some(previous) = previous else {
694 return raw.ps_cpu_percent.max(0.0);
695 };
696 let (Some(previous_cpu), Some(current_cpu)) = (previous.cpu_time_ns, current.cpu_time_ns)
697 else {
698 return raw.ps_cpu_percent.max(0.0);
699 };
700 let wall_ns = current
701 .sampled_at
702 .saturating_duration_since(previous.sampled_at)
703 .as_nanos() as f64;
704 if wall_ns <= 0.0 {
705 return raw.ps_cpu_percent.max(0.0);
706 }
707 let cpu_ns = current_cpu.saturating_sub(previous_cpu) as f64;
708 round_one_decimal((cpu_ns / wall_ns) * 100.0)
709}
710
711fn rate_per_second(
712 previous_value: Option<u64>,

Callers 1

merge_samplesMethod · 0.85

Calls 2

round_one_decimalFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected