mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-29 12:49:05 +00:00
LibWebView: Avoid CPU% precision loss by doing the float cast later
After some uptime the total_time_scheduled can get too big for accurate float subtraction. It's better to do the subtraction in u64 and use float only for the division later on.
This commit is contained in:
parent
c5c5e52c24
commit
bf6e3e5e28
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/skyrising
Commit: bf6e3e5e28
Pull-request: https://github.com/SerenityOS/serenity/pull/23833
1 changed files with 2 additions and 2 deletions
|
@ -39,7 +39,7 @@ ErrorOr<void> update_process_statistics(ProcessStatistics& statistics)
|
|||
return Error::from_string_literal("Failed to parse /proc/stat");
|
||||
|
||||
u64 const total_time_scheduled = user_time + system_time + idle_time + irq_time + softirq_time;
|
||||
float const total_time_scheduled_diff = static_cast<float>(total_time_scheduled) - statistics.total_time_scheduled;
|
||||
float const total_time_scheduled_diff = total_time_scheduled - statistics.total_time_scheduled;
|
||||
statistics.total_time_scheduled = total_time_scheduled;
|
||||
|
||||
for (auto& process : statistics.processes) {
|
||||
|
@ -63,7 +63,7 @@ ErrorOr<void> update_process_statistics(ProcessStatistics& statistics)
|
|||
process.memory_usage_bytes = rss * page_size;
|
||||
|
||||
u64 const time_process = utime + stime;
|
||||
float const time_scheduled_diff = static_cast<float>(time_process) - process.time_spent_in_process;
|
||||
float const time_scheduled_diff = time_process - process.time_spent_in_process;
|
||||
process.time_spent_in_process = time_process;
|
||||
|
||||
process.cpu_percent = 0.0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue