Reland "[battery] Add ResourceCoalitionMacTest.Busy."
This is a reland of 856342886a
The waterfall reveals that `cpu_instructions` and `cpu_cycles` are
not populated prior to macOS 10.15. This CL updates expectations
accordingly.
Original change's description:
> [battery] Add ResourceCoalitionMacTest.Busy.
>
> This test verifies that CPU instructions, CPU cycles and CPU time
> reported by `GetCoalitionResourceUsage` increase after burning CPU.
> This is a basic expectations for `GetCoalitionResourceUsage` so it
> should be tested from //components/power_metrics/. In an upcoming
> CL, this will allow removing
> //chrome/browser/performance_monitor/resource_coalition_mac_unittest.mm
> without losing tests.
>
> Bug: 1293465
> Change-Id: I7232bd6b67406600b9fc89b7f7f80ad8db47c5f1
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3437567
> Reviewed-by: Patrick Monette <pmonette@chromium.org>
> Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#967015}
Bug: 1293465
Change-Id: I5c7f1c9e3b95223e582a1d71fac093ea95bd9c03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3440717
Reviewed-by: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Francois Pierre Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/main@{#967792}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
5fceccfcbf
commit
68b7e413f8
components/power_metrics
@ -60,6 +60,7 @@ struct coalition_resource_usage {
|
||||
uint64_t cpu_ptime;
|
||||
uint64_t cpu_time_eqos_len; /* Stores the number of thread QoS types */
|
||||
uint64_t cpu_time_eqos[COALITION_NUM_THREAD_QOS_TYPES];
|
||||
// `cpu_instructions` and `cpu_cycles` are only populated on macOS 10.15+
|
||||
uint64_t cpu_instructions;
|
||||
uint64_t cpu_cycles;
|
||||
uint64_t fs_metadata_writes;
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "components/power_metrics/resource_coalition_mac.h"
|
||||
|
||||
#include "base/rand_util.h"
|
||||
#include "components/power_metrics/energy_impact_mac.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
@ -69,8 +70,46 @@ coalition_resource_usage GetTestCoalitionResourceUsage(uint32_t increment) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void BurnCPU() {
|
||||
base::TimeTicks begin = base::TimeTicks::Now();
|
||||
constexpr base::TimeDelta busy_time = base::Seconds(1);
|
||||
[[maybe_unused]] volatile double number = 1;
|
||||
while (base::TimeTicks::Now() < (begin + busy_time)) {
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
number *= base::RandDouble();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ResourceCoalitionMacTest, Busy) {
|
||||
absl::optional<uint64_t> coalition_id =
|
||||
GetProcessCoalitionId(base::GetCurrentProcId());
|
||||
ASSERT_TRUE(coalition_id.has_value());
|
||||
|
||||
std::unique_ptr<coalition_resource_usage> begin =
|
||||
GetCoalitionResourceUsage(coalition_id.value());
|
||||
BurnCPU();
|
||||
std::unique_ptr<coalition_resource_usage> end =
|
||||
GetCoalitionResourceUsage(coalition_id.value());
|
||||
|
||||
ASSERT_TRUE(begin);
|
||||
ASSERT_TRUE(end);
|
||||
|
||||
// Waterfall suggests that `cpu_instructions` and `cpu_cycles` are not
|
||||
// populated prior to macOS 10.15.
|
||||
if (@available(macOS 10.15, *)) {
|
||||
EXPECT_GT(end->cpu_instructions, begin->cpu_instructions);
|
||||
EXPECT_GT(end->cpu_cycles, begin->cpu_cycles);
|
||||
} else {
|
||||
EXPECT_EQ(0u, begin->cpu_instructions);
|
||||
EXPECT_EQ(0u, begin->cpu_cycles);
|
||||
EXPECT_EQ(0u, end->cpu_instructions);
|
||||
EXPECT_EQ(0u, end->cpu_cycles);
|
||||
}
|
||||
EXPECT_GT(end->cpu_time, begin->cpu_time);
|
||||
}
|
||||
|
||||
TEST(ResourceCoalitionMacTest, Difference) {
|
||||
coalition_resource_usage left =
|
||||
GetTestCoalitionResourceUsage(/* increment= */ 1);
|
||||
|
Reference in New Issue
Block a user