gopsutil
gopsutil copied to clipboard
get boot time each time cost too much cpu
i use process.NewProcess(pid) 1000 processes per second but common.BootTimeWithContext() runs every time,it depends on syscall.Syscall, it's blocked maybe there's some way I don't know to cache the Process.starttime? thx~
We can't cache host.BootTime as it can jump if time gets adjusted (like with ntpd)
Tested on a Raspberry Pi
pi@raspberrypi:~ $ grep btime /proc/stat
btime 1621271964
pi@raspberrypi:~ $ sudo systemctl disable systemd-timesyncd
pi@raspberrypi:~ $ sudo systemctl stop systemd-timesyncd
pi@raspberrypi:~ $ sudo systemctl disable fake-hwclock.service
pi@raspberrypi:~ $ sudo systemctl stop fake-hwclock.service
pi@raspberrypi:~ $ sudo reboot
# after reboot
pi@raspberrypi:~ $ grep btime /proc/stat
btime 1550139115
pi@raspberrypi:~ $ sudo systemctl enable systemd-timesyncd
pi@raspberrypi:~ $ sudo systemctl start systemd-timesyncd
pi@raspberrypi:~ $ grep btime /proc/stat
btime 1621272415
# btime jumped
See also #857/#837
Thanks for your response, I think you are right can i skip the step getting boot time , It's bit of a waste of time
Because this method has a lock I can't reduce the CPU even with concurrency
Meet the same question. "process.NewProcessWithContext()" blocked in my situation when using pprof to monitor go routine stacks. And I found another problem, "process.NewProcessWithContext()" seems not using context (1th param) as a timeout control threshold. Then block may happen.