feat: v3.26.157 诊断页 Windows 分进程内存拆解(工作集+私有提交);取消 30% LOD 档只留 15% 占位
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 39s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 39s
This commit is contained in:
1 parent
e9581e52a6
commit
2f9590bcc7
8 files changed
+103
-11
No files matched your search
@@ -398,8 +398,92 @@ fn parse_footprint(pid: u32) -> Option<serde_json::Value> {
|
||||
Some(serde_json::json!({ "pid": pid, "footprintMB": phys, "top": top }))
|
||||
}
|
||||
|
||||
/// Windows:按进程给出工作集 + 私有提交(诊断页「内存拆解」用)。
|
||||
/// 只归拢「本进程 + 它的子进程树」;WebView2 的渲染/GPU/工具进程都叫 msedgewebview2.exe,
|
||||
/// 角色只能分到进程名,具体分工看 PID 与数值(可与任务管理器逐条对照)。
|
||||
#[cfg(windows)]
|
||||
fn windows_mem_breakdown(root: u32) -> serde_json::Value {
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE};
|
||||
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
|
||||
CreateToolhelp32Snapshot, Process32FirstW, Process32NextW, PROCESSENTRY32W, TH32CS_SNAPPROCESS,
|
||||
};
|
||||
use windows_sys::Win32::System::ProcessStatus::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX};
|
||||
use windows_sys::Win32::System::Threading::{OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION, PROCESS_VM_READ};
|
||||
|
||||
let mut pairs: Vec<(u32, u32, String)> = Vec::new();
|
||||
unsafe {
|
||||
let snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if snap != INVALID_HANDLE_VALUE {
|
||||
let mut e: PROCESSENTRY32W = std::mem::zeroed();
|
||||
e.dwSize = std::mem::size_of::<PROCESSENTRY32W>() as u32;
|
||||
if Process32FirstW(snap, &mut e) != 0 {
|
||||
loop {
|
||||
let end = e.szExeFile.iter().position(|c| *c == 0).unwrap_or(e.szExeFile.len());
|
||||
let name = String::from_utf16_lossy(&e.szExeFile[..end]);
|
||||
pairs.push((e.th32ProcessID, e.th32ParentProcessID, name));
|
||||
e.dwSize = std::mem::size_of::<PROCESSENTRY32W>() as u32;
|
||||
if Process32NextW(snap, &mut e) == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(snap);
|
||||
}
|
||||
}
|
||||
|
||||
let mut tree: Vec<u32> = vec![root];
|
||||
let mut i = 0;
|
||||
while i < tree.len() {
|
||||
let cur = tree[i];
|
||||
for (p, pp, _) in pairs.iter() {
|
||||
if *pp == cur && !tree.contains(p) {
|
||||
tree.push(*p);
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
let mut rows: Vec<serde_json::Value> = Vec::new();
|
||||
let mut total: u64 = 0;
|
||||
for p in tree.iter() {
|
||||
let h = unsafe { OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, 0, *p) };
|
||||
if h == 0 {
|
||||
continue;
|
||||
}
|
||||
let mut pmc: PROCESS_MEMORY_COUNTERS_EX = unsafe { std::mem::zeroed() };
|
||||
pmc.cb = std::mem::size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32;
|
||||
let ok = unsafe { GetProcessMemoryInfo(h, &mut pmc as *mut _ as *mut _, pmc.cb) } != 0;
|
||||
unsafe { CloseHandle(h) };
|
||||
if !ok {
|
||||
continue;
|
||||
}
|
||||
let ws = (pmc.WorkingSetSize as u64) / 1048576;
|
||||
let priv_mb = (pmc.PrivateUsage as u64) / 1048576;
|
||||
total += ws;
|
||||
let name = pairs.iter().find(|(id, _, _)| id == p).map(|(_, _, n)| n.clone()).unwrap_or_default();
|
||||
let role = if *p == root {
|
||||
"宿主".to_string()
|
||||
} else if name.to_lowercase().contains("msedgewebview2") {
|
||||
"WebView2".to_string()
|
||||
} else if name.is_empty() {
|
||||
"子进程".to_string()
|
||||
} else {
|
||||
name
|
||||
};
|
||||
rows.push(serde_json::json!({ "role": role, "pid": p, "footprintMB": ws, "privMB": priv_mb }));
|
||||
}
|
||||
rows.sort_by_key(|v| std::cmp::Reverse(v["footprintMB"].as_u64().unwrap_or(0)));
|
||||
serde_json::json!({ "ok": true, "kind": "workingset", "totalMB": total, "procs": rows })
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn app_memory_breakdown() -> Result<serde_json::Value, String> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
return Ok(windows_mem_breakdown(std::process::id()));
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
let pid = std::process::id();
|
||||
let mut procs: Vec<serde_json::Value> = Vec::new();
|
||||
@@ -448,6 +532,7 @@ async fn app_memory_breakdown() -> Result<serde_json::Value, String> {
|
||||
})
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
}
|
||||
|
||||
/// 本进程及其全部子进程的常驻内存合计(MB)。
|
||||
|
||||
Reference in new issue
Block a user