Commit 0bc27425 authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

content: Avoid integer overflow when scaling CPU time deltas.

|time_delta| can be a rather large microsecond value, multiplying
with |process_cpu_time_delta| can cause uint64 overflow.

Instead, compute a double factor from time_delta/total_delta first.

Bug: 1129004
Change-Id: I8ff9fd6a03551d1bdde29d263f76b1f5857ed3be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424192Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Auto-Submit: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809775}
parent 5470662a
......@@ -399,10 +399,11 @@ class ProcessCpuTimeTaskObserver : public base::TaskObserver {
if (time_delta > base::TimeDelta()) {
// Scale the process's cpu time by each cluster/frequency pair's
// relative proportion of execution time.
uint64_t delta_us = (process_cpu_time_delta.InMicroseconds() *
time_delta.InMicroseconds()) /
total_delta.InMicroseconds();
// relative proportion of execution time. We scale by a double value
// to avoid integer overflow in the presence of large time_delta values.
uint64_t delta_us = process_cpu_time_delta.InMicroseconds() *
(time_delta.InMicroseconds() /
static_cast<double>(total_delta.InMicroseconds()));
reporter->AddMicroseconds(frequency_mhz, delta_us);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment