@devries-cameron20 / t3code Mirror · read-only / commits / 6444087779
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 11:00 UTC

perf(resource-monitor): look up external process identities by PID (#31202)

Hieu Le committed Nov 15, 2026 at 09:02 UTC 64440877793d2fdb8a559347b14475b504d6f306
1 file changed +45 -10
native/resource-monitor/src/main.rs
+45 -10
@@ -463,13 +463,12 @@ impl Collector {
463 .external_processes
464 .iter()
465 .filter_map(|(pid, expected_start_time_ms)| {
466 - let (_, _, actual_start_time_ms) = rows
467 - .iter()
468 - .find(|(candidate_pid, _, _)| candidate_pid == pid)?;
469 - matches_external_identity(*actual_start_time_ms, *expected_start_time_ms).then_some(
466 + let process = self.system.process(Pid::from_u32(*pid))?;
467 + let actual_start_time_ms = process.start_time().saturating_mul(1_000);
468 + matches_external_identity(actual_start_time_ms, *expected_start_time_ms).then_some(
469 ExternalProcess {
470 pid: *pid,
472 - start_time_ms: Some(*actual_start_time_ms),
471 + start_time_ms: Some(actual_start_time_ms),
472 },
473 )
474 })
@@ -1048,10 +1047,19 @@ mod tests {
1047
1048 #[test]
1049 fn validates_external_process_start_identity() {
1051 - assert!(matches_external_identity(10_000, None));
1052 - assert!(matches_external_identity(10_000, Some(10_999)));
1053 - assert!(!matches_external_identity(10_000, Some(11_000)));
1054 - assert!(!matches_external_identity(10_000, Some(9_999)));
1050 + for (actual, expected, matches) in [
1051 + (10_000, None, true),
1052 + (10_000, Some(10_000), true),
1053 + (10_000, Some(10_999), true),
1054 + (10_000, Some(11_000), false),
1055 + (10_000, Some(9_999), false),
1056 + (0, Some(999), true),
1057 + (0, Some(1_000), false),
1058 + (u64::MAX, None, true),
1059 + (u64::MAX, Some(u64::MAX), false),
1060 + ] {
1061 + assert_eq!(matches_external_identity(actual, expected), matches);
1062 + }
1063 }
1064
1065 #[test]
@@ -1094,7 +1102,13 @@ mod tests {
1102 assert_eq!(unselected.memory(), 0);
1103 assert_eq!(unselected.virtual_memory(), 0);
1104
1097 - config.external_processes.insert(pid.as_u32(), None);
1105 + config.external_processes = [
1106 + (pid.as_u32(), Some(0)),
1107 + (u32::MAX, None),
1108 + (pid.as_u32(), None),
1109 + ]
1110 + .into_iter()
1111 + .collect();
1112 let snapshot = collector.sample(&config, None);
1113 let selected = snapshot
1114 .processes
@@ -1104,6 +1118,27 @@ mod tests {
1118 assert!(!selected.command.is_empty());
1119 assert!(selected.resident_bytes > 0);
1120 assert!(selected.start_time_ms > 0);
1121 + assert_eq!(
1122 + snapshot
1123 + .external_processes
1124 + .iter()
1125 + .map(|process| (process.pid, process.start_time_ms))
1126 + .collect::<Vec<_>>(),
1127 + vec![(pid.as_u32(), Some(selected.start_time_ms))],
1128 + );
1129 +
1130 + config.root_pid = pid.as_u32();
1131 + config.external_processes.insert(pid.as_u32(), Some(0));
1132 + let snapshot = collector.sample(&config, None);
1133 + assert!(snapshot.external_processes.is_empty());
1134 + assert_eq!(
1135 + snapshot
1136 + .processes
1137 + .iter()
1138 + .filter(|process| process.pid == pid.as_u32())
1139 + .count(),
1140 + 1,
1141 + );
1142
1143 let retained = collector
1144 .system