Commit cb2914f5 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Switch a couple places from trunc/floor to round.

It looks like rounding would reduce overall error in these spots.

Bug: none
Change-Id: I473aa9dac00e454ae2ec344bf554928ce9236a27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2345287Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Commit-Queue: Frank Liberato <liberato@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796725}
parent 448e5e21
......@@ -20,6 +20,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/trace_event/trace_event.h"
#include "media/cast/constants.h"
......@@ -414,8 +415,8 @@ int AdaptiveCongestionControl::GetBitrate(base::TimeTicks playout_time,
empty_buffer_fraction = std::min(empty_buffer_fraction, 1.0);
empty_buffer_fraction = std::max(empty_buffer_fraction, 0.0);
int bits_per_second = static_cast<int>(
safe_bitrate * empty_buffer_fraction / kTargetEmptyBufferFraction);
int bits_per_second = base::ClampRound(safe_bitrate * empty_buffer_fraction /
kTargetEmptyBufferFraction);
VLOG(3) << " FBR:" << (bits_per_second / 1E6)
<< " EBF:" << empty_buffer_fraction
<< " SBR:" << (safe_bitrate / 1E6);
......
......@@ -16,6 +16,7 @@
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
......@@ -1225,7 +1226,7 @@ static int CalculateBitrate(AVFormatContext* format_context,
// larger than ~1073GB.
double bytes = filesize_in_bytes;
double duration_us = duration.InMicroseconds();
return bytes * 8000000.0 / duration_us;
return base::ClampRound(bytes * 8000000.0 / duration_us);
}
void FFmpegDemuxer::OnOpenContextDone(bool result) {
......
......@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/frame/local_frame_ukm_aggregator.h"
#include "base/format_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/time/default_tick_clock.h"
#include "cc/metrics/begin_main_frame_metrics.h"
......@@ -336,8 +337,8 @@ void LocalFrameUkmAggregator::RecordEndOfFrameMetrics(
}
for (auto& record : main_frame_percentage_records_) {
unsigned percentage =
(unsigned)floor(record.interval_duration.InMicrosecondsF() * 100.0 /
auto percentage = base::ClampRound<base::HistogramBase::Sample>(
record.interval_duration.InMicrosecondsF() * 100.0 /
duration.InMicrosecondsF());
record.uma_counters_per_bucket[bucket_index]->Count(percentage);
}
......@@ -390,9 +391,9 @@ void LocalFrameUkmAggregator::UpdateSample(
for (unsigned i = 0; i < static_cast<unsigned>(kCount); ++i) {
current_sample_.sub_metrics_durations[i] =
absolute_metric_records_[i].interval_duration;
current_sample_.sub_metric_percentages[i] = static_cast<unsigned>(floor(
current_sample_.sub_metric_percentages[i] = base::ClampRound<unsigned>(
main_frame_percentage_records_[i].interval_duration.InMicrosecondsF() *
100.0 / primary_metric_in_microseconds));
100.0 / primary_metric_in_microseconds);
}
current_sample_.trackers = trackers;
}
......
......@@ -61,7 +61,7 @@ class LocalFrameUkmAggregatorTest : public testing::Test {
void VerifyUpdateEntry(unsigned index,
unsigned expected_primary_metric,
unsigned expected_sub_metric,
unsigned expected_percentage,
float expected_percentage,
unsigned expected_reasons,
bool expected_before_fcp) {
auto entries = recorder().GetEntriesByName("Blink.UpdateTime");
......@@ -84,7 +84,7 @@ class LocalFrameUkmAggregatorTest : public testing::Test {
entry, GetPercentageMetricName(i)));
const int64_t* metric_percentage = ukm::TestUkmRecorder::GetEntryMetric(
entry, GetPercentageMetricName(i));
EXPECT_NEAR(*metric_percentage, expected_percentage, 0.001);
EXPECT_NEAR(*metric_percentage, expected_percentage, 0.5);
}
EXPECT_TRUE(
ukm::TestUkmRecorder::EntryHasMetric(entry, "MainFrameIsBeforeFCP"));
......@@ -185,7 +185,7 @@ TEST_F(LocalFrameUkmAggregatorTest, FirstFrameIsRecorded) {
millisecond_for_step * LocalFrameUkmAggregator::kCount;
float expected_sub_metric = millisecond_for_step;
float expected_percentage =
floor(100.0 / static_cast<float>(LocalFrameUkmAggregator::kCount));
100.0 / static_cast<float>(LocalFrameUkmAggregator::kCount);
VerifyUpdateEntry(0u, expected_primary_metric, expected_sub_metric,
expected_percentage, 12, true);
......@@ -214,7 +214,7 @@ TEST_F(LocalFrameUkmAggregatorTest, PreAndPostFCPAreRecorded) {
millisecond_per_step * LocalFrameUkmAggregator::kCount;
float expected_sub_metric = millisecond_per_step;
float expected_percentage =
floor(100.0 / static_cast<float>(LocalFrameUkmAggregator::kCount));
100.0 / static_cast<float>(LocalFrameUkmAggregator::kCount);
VerifyUpdateEntry(0u, expected_primary_metric, expected_sub_metric,
expected_percentage, 4, true);
......@@ -237,8 +237,8 @@ TEST_F(LocalFrameUkmAggregatorTest, PreAndPostFCPAreRecorded) {
// been recorded.
EXPECT_EQ(recorder().entries_count(), 3u);
expected_percentage = floor(millisecond_per_step * 100.0 /
static_cast<float>(millisecond_per_frame));
expected_percentage =
millisecond_per_step * 100.0 / static_cast<float>(millisecond_per_frame);
VerifyUpdateEntry(1u, millisecond_per_frame, millisecond_per_step,
expected_percentage, 4, false);
}
......
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