mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 06:18:59 +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
Notes:
sideshowbarker
2024-07-18 08:46:58 +09:00
Author: https://github.com/tomuta
Commit: 7e77a2ec40
Pull-request: https://github.com/SerenityOS/serenity/pull/8749
Issue: https://github.com/SerenityOS/serenity/issues/6473
17 changed files with 132 additions and 83 deletions
|
@ -406,10 +406,10 @@ private:
|
|||
ProcFSOverallProcesses();
|
||||
virtual bool output(KBufferBuilder& builder) override
|
||||
{
|
||||
JsonArraySerializer array { builder };
|
||||
JsonObjectSerializer<KBufferBuilder> json { builder };
|
||||
|
||||
// Keep this in sync with CProcessStatistics.
|
||||
auto build_process = [&](const Process& process) {
|
||||
auto build_process = [&](JsonArraySerializer<KBufferBuilder>& array, const Process& process) {
|
||||
auto process_object = array.add_object();
|
||||
|
||||
if (process.is_user_process()) {
|
||||
|
@ -488,11 +488,19 @@ private:
|
|||
};
|
||||
|
||||
ScopedSpinLock lock(g_scheduler_lock);
|
||||
auto processes = Process::all_processes();
|
||||
build_process(*Scheduler::colonel());
|
||||
for (auto& process : processes)
|
||||
build_process(process);
|
||||
array.finish();
|
||||
{
|
||||
{
|
||||
auto array = json.add_array("processes");
|
||||
auto processes = Process::all_processes();
|
||||
build_process(array, *Scheduler::colonel());
|
||||
for (auto& process : processes)
|
||||
build_process(array, process);
|
||||
}
|
||||
|
||||
auto total_ticks_scheduled = Scheduler::get_total_ticks_scheduled();
|
||||
json.add("total_ticks", total_ticks_scheduled.total);
|
||||
json.add("total_ticks_kernel", total_ticks_scheduled.total_kernel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue