mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 07:54:58 +00:00
Everywhere: Improve CPU usage calculation
As threads come and go, we can't simply account for how many time slices the threads at any given point may have been using. We need to also account for threads that have since disappeared. This means we also need to track how many time slices we have expired globally. However, because this doesn't account for context switches outside of the system timer tick values may still be under-reported. To solve this we will need to track more accurate time information on each context switch. This also fixes top's cpu usage calculation which was still based on the number of context switches. Fixes #6473
This commit is contained in:
parent
ef85c4f747
commit
7e77a2ec40
17 changed files with 132 additions and 83 deletions
|
@ -16,11 +16,11 @@ static int pid_of(const String& process_name, bool single_shot, bool omit_pid, p
|
|||
{
|
||||
bool displayed_at_least_one = false;
|
||||
|
||||
auto processes = Core::ProcessStatisticsReader::get_all();
|
||||
if (!processes.has_value())
|
||||
auto all_processes = Core::ProcessStatisticsReader::get_all();
|
||||
if (!all_processes.has_value())
|
||||
return 1;
|
||||
|
||||
for (auto& it : processes.value()) {
|
||||
for (auto& it : all_processes.value().processes) {
|
||||
if (it.name == process_name) {
|
||||
if (!omit_pid || it.pid != pid) {
|
||||
out(displayed_at_least_one ? " {}" : "{}", it.pid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue