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

Misc. cleanup.

* Inline temps
* constexpr
* Format
* Shorten code
* Avoid unnecessary precision loss
* Improve naming
* Narrow scope

Bug: none
Change-Id: I457b636ca926654fb01e34f2d201e547d9070265
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359005Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798745}
parent 85a39162
......@@ -35,10 +35,9 @@ bool IsTimeDeltaWithinJitter(const base::TimeDelta& base_time_delta,
if (base_time_delta.is_zero())
return jittered_time_delta.is_zero();
base::TimeDelta difference =
const base::TimeDelta difference =
(jittered_time_delta - base_time_delta).magnitude();
double percentage_of_base = difference / base_time_delta;
return percentage_of_base < max_jitter_ratio;
return (difference / base_time_delta) < max_jitter_ratio;
}
// Test harness for the SyncSchedulerImpl to create MockOneShotTimers.
......
......@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/numerics/safe_conversions.h"
#include "base/optional.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
......@@ -77,24 +78,20 @@ double GetRandomMultiplier(const std::string& host) {
unsigned long RoundRtt(const std::string& host,
const base::Optional<base::TimeDelta>& rtt) {
// Limit the size of the buckets and the maximum reported value to reduce
// fingerprinting.
static const base::TimeDelta kGranularity =
base::TimeDelta::FromMilliseconds(50);
static const base::TimeDelta kMaxRtt = base::TimeDelta::FromSeconds(3);
if (!rtt.has_value()) {
// RTT is unavailable. So, return the fastest value.
return 0;
}
base::TimeDelta modified_rtt = rtt.value();
modified_rtt *= GetRandomMultiplier(host);
modified_rtt = std::min(modified_rtt, kMaxRtt);
DCHECK_LE(base::TimeDelta(), modified_rtt);
DCHECK_GE(kMaxRtt, modified_rtt);
// Limit the maximum reported value and the granularity to reduce
// fingerprinting.
constexpr base::TimeDelta kMaxRtt = base::TimeDelta::FromSeconds(3);
constexpr base::TimeDelta kGranularity =
base::TimeDelta::FromMilliseconds(50);
const base::TimeDelta modified_rtt =
std::min(rtt.value() * GetRandomMultiplier(host), kMaxRtt);
DCHECK_GE(modified_rtt, base::TimeDelta());
return modified_rtt.RoundToMultiple(kGranularity).InMilliseconds();
}
......
......@@ -413,14 +413,10 @@ class Requester : public DiscreteTimeSimulation::Actor {
}
void PerformAction() override {
TimeDelta effective_delay = time_between_requests_;
TimeDelta current_jitter = TimeDelta::FromMilliseconds(
request_jitter_.InMilliseconds() * base::RandDouble());
if (base::RandInt(0, 1)) {
effective_delay -= current_jitter;
} else {
effective_delay += current_jitter;
}
const TimeDelta current_jitter = request_jitter_ * base::RandDouble();
const TimeDelta effective_delay =
time_between_requests_ +
(base::RandInt(0, 1) ? -current_jitter : current_jitter);
if (throttler_entry_->ImplGetTimeNow() - time_of_last_attempt_ >
effective_delay) {
......@@ -438,12 +434,10 @@ class Requester : public DiscreteTimeSimulation::Actor {
}
time_of_last_success_ = throttler_entry_->ImplGetTimeNow();
last_attempt_was_failure_ = false;
} else {
if (results_)
} else if (results_) {
results_->AddFailure();
last_attempt_was_failure_ = true;
}
last_attempt_was_failure_ = status_code != 200;
} else {
if (results_)
results_->AddBlocked();
......
......@@ -90,7 +90,7 @@ bool FlingTracker::TrackMovement(base::TimeDelta time_elapsed,
return false;
}
float time_elapsed_ms = time_elapsed.InMilliseconds();
float time_elapsed_ms = time_elapsed.InMillisecondsF();
if (time_elapsed_ms > fling_duration_) {
StopFling();
......
......@@ -29,7 +29,7 @@ namespace {
static const auto kTimeLimit = base::TimeDelta::FromSeconds(2);
static const int kNumWarmupRuns = 20;
static const int kTimeCheckInterval = 10;
static const int kNumRunsPerTimeRecord = 10;
enum class UseSingleSharedQuadState { YES, NO };
......@@ -73,13 +73,12 @@ class VizSerializationPerfTest : public testing::Test {
message.payload(), message.payload_num_bytes(), &compositor_frame);
}
base::TimeTicks start = base::TimeTicks::Now();
base::TimeTicks end = start + kTimeLimit;
base::TimeTicks now = start;
base::TimeTicks now = base::TimeTicks::Now();
base::TimeTicks end = now + kTimeLimit;
base::TimeDelta min_time;
size_t count = 0;
while (start < end) {
for (int i = 0; i < kTimeCheckInterval; ++i) {
for (base::TimeTicks start = now; start < end; start = now) {
for (int i = 0; i < kNumRunsPerTimeRecord; ++i) {
CompositorFrame compositor_frame;
mojom::CompositorFrame::Deserialize(
message.payload(), message.payload_num_bytes(), &compositor_frame);
......@@ -91,12 +90,11 @@ class VizSerializationPerfTest : public testing::Test {
if (now - start < min_time || min_time.is_zero())
min_time = now - start;
start = now;
}
auto reporter = SetUpReporter(story, single_sqs);
reporter.AddResult(kMetricStructDeserializationTimeUs,
min_time.InMicrosecondsF() / kTimeCheckInterval);
min_time.InMicrosecondsF() / kNumRunsPerTimeRecord);
reporter.AddResult(kMetricStructDeserializationThroughputRunsPerS,
count * kTimeLimit.ToHz());
}
......@@ -110,13 +108,12 @@ class VizSerializationPerfTest : public testing::Test {
mojom::CompositorFrame::SerializeAsMessage(&frame);
}
base::TimeTicks start = base::TimeTicks::Now();
base::TimeTicks end = start + kTimeLimit;
base::TimeTicks now = start;
base::TimeTicks now = base::TimeTicks::Now();
base::TimeTicks end = now + kTimeLimit;
base::TimeDelta min_time;
size_t count = 0;
while (start < end) {
for (int i = 0; i < kTimeCheckInterval; ++i) {
for (base::TimeTicks start = now; start < end; start = now) {
for (int i = 0; i < kNumRunsPerTimeRecord; ++i) {
mojo::Message message =
mojom::CompositorFrame::SerializeAsMessage(&frame);
now = base::TimeTicks::Now();
......@@ -127,14 +124,13 @@ class VizSerializationPerfTest : public testing::Test {
if (now - start < min_time || min_time.is_zero())
min_time = now - start;
start = now;
}
auto reporter = SetUpReporter(story, single_sqs);
reporter.AddResult(kMetricStructSerializationTimeUs,
min_time.InMicrosecondsF() / kTimeCheckInterval);
min_time.InMicrosecondsF() / kNumRunsPerTimeRecord);
reporter.AddResult(kMetricStructSerializationThroughputRunsPerS,
count * kTimeLimit.ToHz());
count / kTimeLimit.InSecondsF());
}
static void RunComplexCompositorFrameTest(const std::string& story) {
......
......@@ -51,12 +51,10 @@ std::string DurationLogMessage(const char* prefix,
const base::TimeTicks& tick,
const base::TimeTicks& tock,
int size) {
base::TimeDelta delta = tock - tick;
double mb_per_second = size * delta.ToHz() / 1e6;
std::string message =
base::StringPrintf("%s %d = %.0fus (%.02fMB/s)", prefix, size,
const base::TimeDelta delta = tock - tick;
const double mb_per_second = size * delta.ToHz() / 1'000'000;
return base::StringPrintf("%s %d = %.0fus (%.02fMB/s)", prefix, size,
delta.InMicrosecondsF(), mb_per_second);
return message;
}
// Returns {write_us, read_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