Replies: 1 comment
-
i may got same problem ,i make a Discussions #1391 ,i use a monitor script ,find the process use more and more cpu, bug only use cpu very higher, is it ur memory full package main
import (
"encoding/csv"
"fmt"
"os"
"strconv"
"time"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/process"
)
// 进程名
var PROCESS_NAME string
// 监控间隔(秒)
const INTERVAL = 1
// 输出文件
const SYSTEM_LOG = "system_monitor.csv"
// CSV文件头
var systemHeader = []string{"Timestamp", "sysCPU (%)", "sysMemory (%)", "sysMemory (GB)", "procCPU (%)", "procMemory (%)", "procMemory (MB)", "procThreads"}
func main() {
fmt.Print("输入进程 PID: ")
fmt.Scanln(&PROCESS_NAME)
// 初始化CSV文件
file, err := os.Create(SYSTEM_LOG)
if err != nil {
fmt.Println("无法创建文件:", err)
return
}
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()
writer.Write(systemHeader)
// 将输入的进程名转换为进程ID
pid, err := strconv.Atoi(PROCESS_NAME)
if err != nil {
fmt.Println("无效的进程ID:", err)
return
}
for {
timestamp := time.Now().Format("2006-01-02 15:04:05")
// 获取系统信息
sysCPUPercent, sysMemPercent, sysMemUsedGB := getSystemInfo()
// 获取进程信息
procName, procCPUPercent, procMemPercent, procMemUsedMB, procThreads := getProcessInfo(pid)
if procCPUPercent != -1 && procMemPercent != -1 {
writer.Write([]string{
timestamp,
strconv.FormatFloat(sysCPUPercent, 'f', 2, 64),
strconv.FormatFloat(sysMemPercent, 'f', 2, 64),
strconv.FormatFloat(sysMemUsedGB, 'f', 2, 64),
strconv.FormatFloat(procCPUPercent, 'f', 2, 64),
strconv.FormatFloat(procMemPercent, 'f', 2, 64),
strconv.FormatFloat(procMemUsedMB, 'f', 2, 64),
strconv.Itoa(procThreads),
})
fmt.Printf("%s - Sys - CPU: %.2f%%, MEM: %.2f%%, MEM Used: %.2f GB, Process (%s) - CPU: %.2f%%, MEM: %.2f%%, MEM Used: %.2f MB, Threads: %d\n",
timestamp, sysCPUPercent, sysMemPercent, sysMemUsedGB, procName, procCPUPercent, procMemPercent, procMemUsedMB, procThreads)
} else {
writer.Write([]string{
timestamp,
"", "",
strconv.FormatFloat(sysCPUPercent, 'f', 2, 64),
strconv.FormatFloat(sysMemPercent, 'f', 2, 64),
strconv.FormatFloat(sysMemUsedGB, 'f', 2, 64),
"", "", "", "",
})
fmt.Printf("%s - System - CPU: %.2f%%, MEM: %.2f%%, MEM Used: %.2f GB, Process %s not found.\n",
timestamp, sysCPUPercent, sysMemPercent, sysMemUsedGB, PROCESS_NAME)
}
writer.Flush()
time.Sleep(INTERVAL * time.Second)
}
}
func getSystemInfo() (float64, float64, float64) {
cpuPercent, _ := cpu.Percent(0, false)
memInfo, _ := mem.VirtualMemory()
sysMemUsedGB := float64(memInfo.Used) / (1024 * 1024 * 1024)
return cpuPercent[0], memInfo.UsedPercent, sysMemUsedGB
}
func getProcessInfo(pid int) (string, float64, float64, float64, int) {
p, err := process.NewProcess(int32(pid))
if err != nil {
return "", -1, -1, -1, -1
}
procName, _ := p.Name()
cpuPercent, _ := p.CPUPercent()
memPercent, _ := p.MemoryPercent()
memInfo, _ := p.MemoryInfo()
procMemUsedMB := float64(memInfo.RSS) / (1024 * 1024)
procThreads, _ := p.NumThreads()
return procName, cpuPercent, float64(memPercent), procMemUsedMB, int(procThreads)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The longer czkawka runs a search for "similar videos," the more my system performance denigrates. After a few hours, it becomes nearly unusable, and takes a long time just to stop czkawka, and even once stopped, the system remains almost unusable, requiring a reboot. I see that WMI Provider and system interrupts spike wildly as this occurs, those being the apparent proximate causes of the performance degradation, and most oddly and notably nothing changes after czkawka is shut down, it seems (I haven't waited more than 20 minutes) that the system must be rebooted, it will not, at least not in any short term, return to expected operation.
It's comparing "only" 20,367 files that amount to 5.93 TB, virtually all videos and a relatively small portion of images. No other file comparison program has created such a problem.
My system is decent, the mobo is ROG STRIX B550-F GAMING, CPU is AMD Ryzen 7 5800x. Reasonable amounts of free hard drive. No other apparent issues.
Any ideas??? Thank you!
Beta Was this translation helpful? Give feedback.
All reactions