aboutsummaryrefslogtreecommitdiff
path: root/cpp/watchdog
diff options
context:
space:
mode:
authorJahdiel Alvarez <jahdiel@google.com>2021-10-14 19:38:35 +0000
committerJahdiel Alvarez <jahdiel@google.com>2021-10-21 01:22:43 +0000
commita4de67f1a1f0e433bd0341964be4d2a24f388762 (patch)
tree142f3e87a5006d1e2b6e2437320a7961c24709f7 /cpp/watchdog
parent6d7c3fa7ec22d9c2d945a6441bd5a308cbee1d55 (diff)
downloadCar-a4de67f1a1f0e433bd0341964be4d2a24f388762.tar.gz
Watchdog detects multiple resource overuses during consecutive polls.
- Added forgivenWriteBytes fields to PackageIoOveruseStats in order to sync the forgivenWriteBytes calculated in watchdog daemon to CarService. - Watchdog daemon attributes the number of overuses proportional to the number of times an app/service exceeds the threshold in between polls. Test: atest libwatchdog_test CarWatchdogServiceUnitTest CtsCarTestCases:CarWatchdogDaemonTest CtsCarTestCases:CarWatchdogManagerTest Bug: 195328834 Merged-In: Ifc3e223a95675189126093056e8c5c0192c17c46 Change-Id: Ifc3e223a95675189126093056e8c5c0192c17c46
Diffstat (limited to 'cpp/watchdog')
-rw-r--r--cpp/watchdog/aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.aidl12
-rw-r--r--cpp/watchdog/server/src/IoOveruseMonitor.cpp57
-rw-r--r--cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp143
3 files changed, 170 insertions, 42 deletions
diff --git a/cpp/watchdog/aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.aidl b/cpp/watchdog/aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.aidl
index 8f3a143e7e..ac9e140381 100644
--- a/cpp/watchdog/aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.aidl
+++ b/cpp/watchdog/aidl/android/automotive/watchdog/internal/PackageIoOveruseStats.aidl
@@ -17,6 +17,7 @@
package android.automotive.watchdog.internal;
import android.automotive.watchdog.IoOveruseStats;
+import android.automotive.watchdog.PerStateBytes;
/**
* Structure that describes the I/O overuse stats for a package.
@@ -32,8 +33,13 @@ parcelable PackageIoOveruseStats {
*/
boolean shouldNotify;
- /**
- * I/O overuse stats for the package.
- */
+ /**
+ * Written bytes that are forgiven as they are accounted towards overuse.
+ */
+ PerStateBytes forgivenWriteBytes;
+
+ /**
+ * I/O overuse stats for the package.
+ */
IoOveruseStats ioOveruseStats;
}
diff --git a/cpp/watchdog/server/src/IoOveruseMonitor.cpp b/cpp/watchdog/server/src/IoOveruseMonitor.cpp
index 9d40f8ba50..1164a2a45d 100644
--- a/cpp/watchdog/server/src/IoOveruseMonitor.cpp
+++ b/cpp/watchdog/server/src/IoOveruseMonitor.cpp
@@ -59,6 +59,8 @@ using ::android::base::Result;
using ::android::base::WriteStringToFd;
using ::android::binder::Status;
+constexpr int64_t kMaxInt32 = std::numeric_limits<int32_t>::max();
+constexpr int64_t kMaxInt64 = std::numeric_limits<int64_t>::max();
// Minimum written bytes to sync the stats with the Watchdog service.
constexpr int64_t kMinSyncWrittenBytes = 100 * 1024;
// Minimum percentage of threshold to warn killable applications.
@@ -80,10 +82,8 @@ std::string uniquePackageIdStr(const PackageIdentifier& id) {
PerStateBytes sum(const PerStateBytes& lhs, const PerStateBytes& rhs) {
const auto sum = [](const int64_t& l, const int64_t& r) -> int64_t {
- return (std::numeric_limits<int64_t>::max() - l) > r ? (l + r)
- : std::numeric_limits<int64_t>::max();
+ return (kMaxInt64 - l) > r ? (l + r) : kMaxInt64;
};
-
PerStateBytes result;
result.foregroundBytes = sum(lhs.foregroundBytes, rhs.foregroundBytes);
result.backgroundBytes = sum(lhs.backgroundBytes, rhs.backgroundBytes);
@@ -116,13 +116,39 @@ std::tuple<int64_t, int64_t> calculateStartAndDuration(struct tm currentTm) {
int64_t totalPerStateBytes(PerStateBytes perStateBytes) {
const auto sum = [](const int64_t& l, const int64_t& r) -> int64_t {
- return std::numeric_limits<int64_t>::max() - l > r ? (l + r)
- : std::numeric_limits<int64_t>::max();
+ return kMaxInt64 - l > r ? (l + r) : kMaxInt64;
};
return sum(perStateBytes.foregroundBytes,
sum(perStateBytes.backgroundBytes, perStateBytes.garageModeBytes));
}
+std::tuple<int32_t, PerStateBytes> calculateOveruseAndForgivenBytes(PerStateBytes writtenBytes,
+ PerStateBytes threshold) {
+ const auto div = [](const int64_t& l, const int64_t& r) -> int32_t {
+ return r > 0 ? (l / r) : 1;
+ };
+ const auto mul = [](const int32_t& l, const int32_t& r) -> int32_t {
+ if (l == 0 || r == 0) {
+ return 0;
+ }
+ return (kMaxInt32 / r) > l ? (l * r) : kMaxInt32;
+ };
+ const auto sum = [](const int32_t& l, const int32_t& r) -> int32_t {
+ return (kMaxInt32 - l) > r ? (l + r) : kMaxInt32;
+ };
+ int32_t foregroundOveruses = div(writtenBytes.foregroundBytes, threshold.foregroundBytes);
+ int32_t backgroundOveruses = div(writtenBytes.backgroundBytes, threshold.backgroundBytes);
+ int32_t garageModeOveruses = div(writtenBytes.garageModeBytes, threshold.garageModeBytes);
+ int32_t totalOveruses = sum(foregroundOveruses, sum(backgroundOveruses, garageModeOveruses));
+
+ PerStateBytes forgivenWriteBytes;
+ forgivenWriteBytes.foregroundBytes = mul(foregroundOveruses, threshold.foregroundBytes);
+ forgivenWriteBytes.backgroundBytes = mul(backgroundOveruses, threshold.backgroundBytes);
+ forgivenWriteBytes.garageModeBytes = mul(garageModeOveruses, threshold.garageModeBytes);
+
+ return std::make_tuple(totalOveruses, forgivenWriteBytes);
+}
+
} // namespace
std::tuple<int64_t, int64_t> calculateStartAndDuration(const time_t& currentTime) {
@@ -251,15 +277,23 @@ Result<void> IoOveruseMonitor::onPeriodicCollection(
const auto threshold = mIoOveruseConfigs->fetchThreshold(dailyIoUsage->packageInfo);
+ const auto deltaWrittenBytes =
+ diff(dailyIoUsage->writtenBytes, dailyIoUsage->forgivenWriteBytes);
+ const auto [currentOveruses, forgivenWriteBytes] =
+ calculateOveruseAndForgivenBytes(deltaWrittenBytes, threshold);
+ dailyIoUsage->totalOveruses += currentOveruses;
+ dailyIoUsage->forgivenWriteBytes =
+ sum(dailyIoUsage->forgivenWriteBytes, forgivenWriteBytes);
+
PackageIoOveruseStats stats;
stats.uid = curUidStats.packageInfo.packageIdentifier.uid;
stats.shouldNotify = false;
+ stats.forgivenWriteBytes = dailyIoUsage->forgivenWriteBytes;
stats.ioOveruseStats.startTime = startTime;
stats.ioOveruseStats.durationInSeconds = durationInSeconds;
stats.ioOveruseStats.writtenBytes = dailyIoUsage->writtenBytes;
stats.ioOveruseStats.totalOveruses = dailyIoUsage->totalOveruses;
- stats.ioOveruseStats.remainingWriteBytes =
- diff(threshold, diff(dailyIoUsage->writtenBytes, dailyIoUsage->forgivenWriteBytes));
+ stats.ioOveruseStats.remainingWriteBytes = diff(threshold, deltaWrittenBytes);
stats.ioOveruseStats.killableOnOveruse =
mIoOveruseConfigs->isSafeToKill(dailyIoUsage->packageInfo);
@@ -274,14 +308,7 @@ Result<void> IoOveruseMonitor::onPeriodicCollection(
bool shouldSyncWatchdogService =
(totalPerStateBytes(dailyIoUsage->writtenBytes) -
dailyIoUsage->lastSyncedWrittenBytes) >= mMinSyncWrittenBytes;
- if (remainingWriteBytes.foregroundBytes == 0 || remainingWriteBytes.backgroundBytes == 0 ||
- remainingWriteBytes.garageModeBytes == 0) {
- stats.ioOveruseStats.totalOveruses = ++dailyIoUsage->totalOveruses;
- /*
- * Reset counters as the package may be disabled/killed by the watchdog service.
- * NOTE: If this logic is updated, update watchdog service side logic as well.
- */
- dailyIoUsage->forgivenWriteBytes = dailyIoUsage->writtenBytes;
+ if (currentOveruses > 0) {
dailyIoUsage->isPackageWarned = false;
/*
* Send notifications for native service I/O overuses as well because system listeners
diff --git a/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp b/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp
index f4dad98ef7..c1dd4f7d56 100644
--- a/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp
+++ b/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp
@@ -111,11 +111,12 @@ ResourceOveruseStats constructResourceOveruseStats(IoOveruseStats ioOveruseStats
PackageIoOveruseStats constructPackageIoOveruseStats(
const int32_t uid, const bool shouldNotify, const bool isKillable,
- const PerStateBytes& remaining, const PerStateBytes& written, const int totalOveruses,
- const int64_t startTime, const int64_t durationInSeconds) {
+ const PerStateBytes& remaining, const PerStateBytes& written, const PerStateBytes& forgiven,
+ const int totalOveruses, const int64_t startTime, const int64_t durationInSeconds) {
PackageIoOveruseStats stats;
stats.uid = uid;
stats.shouldNotify = shouldNotify;
+ stats.forgivenWriteBytes = forgiven;
stats.ioOveruseStats = constructIoOveruseStats(isKillable, remaining, written, totalOveruses,
startTime, durationInSeconds);
@@ -331,22 +332,25 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollection) {
mMockUidStatsCollector, nullptr));
std::vector<PackageIoOveruseStats> expectedIoOveruseStats =
- {constructPackageIoOveruseStats(/*uid*=*/1001000, /*shouldNotify=*/false,
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/false,
/*isKillable=*/false, /*remaining=*/
constructPerStateBytes(10'000, 20'000, 100'000),
/*written=*/constructPerStateBytes(70'000, 20'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
- constructPackageIoOveruseStats(/*uid*=*/1112345, /*shouldNotify=*/false,
+ constructPackageIoOveruseStats(/*uid=*/1112345, /*shouldNotify=*/false,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(35'000, 15'000, 100'000),
/*written=*/constructPerStateBytes(35'000, 15'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
// Exceeds threshold.
- constructPackageIoOveruseStats(/*uid*=*/1212345, /*shouldNotify=*/true,
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/true,
/*isKillable=*/true,
/*remaining=*/
constructPerStateBytes(0, 10'000, 100'000),
/*written=*/constructPerStateBytes(70'000, 20'000, 0),
+ /*forgiven=*/constructPerStateBytes(70'000, 0, 0),
/*totalOveruses=*/1, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
@@ -378,26 +382,29 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollection) {
<< "\nActual: " << actualOverusingNativeStats.toString();
expectedIoOveruseStats =
- {constructPackageIoOveruseStats(/*uid*=*/1001000, /*shouldNotify=*/true,
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/true,
/*isKillable=*/false, /*remaining=*/
constructPerStateBytes(0, 20'000, 100'000),
/*written=*/constructPerStateBytes(100'000, 20'000, 0),
+ /*forgiven=*/constructPerStateBytes(80'000, 0, 0),
/*totalOveruses=*/1, startTime, durationInSeconds),
// Exceeds warn threshold percentage.
- constructPackageIoOveruseStats(/*uid*=*/1113999, /*shouldNotify=*/true,
+ constructPackageIoOveruseStats(/*uid=*/1113999, /*shouldNotify=*/true,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(10'000, 5'000, 100'000),
/*written=*/constructPerStateBytes(60'000, 25'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
/*
* Exceeds threshold.
* The package was forgiven on previous overuse so the remaining bytes should only
* reflect the bytes written after the forgiven bytes.
*/
- constructPackageIoOveruseStats(/*uid*=*/1212345, /*shouldNotify=*/true,
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/true,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(50'000, 0, 100'000),
/*written=*/constructPerStateBytes(90'000, 50'000, 0),
+ /*forgiven=*/constructPerStateBytes(70'000, 30'000, 0),
/*totalOveruses=*/2, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
@@ -422,20 +429,23 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollection) {
const auto [nextDayStartTime, nextDayDuration] = calculateStartAndDuration(currentTime);
expectedIoOveruseStats =
- {constructPackageIoOveruseStats(/*uid*=*/1001000, /*shouldNotify=*/false,
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/false,
/*isKillable=*/false, /*remaining=*/
constructPerStateBytes(2'000, 2'000, 100'000),
/*written=*/constructPerStateBytes(78'000, 38'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, nextDayStartTime, nextDayDuration),
- constructPackageIoOveruseStats(/*uid*=*/1113999, /*shouldNotify=*/false,
+ constructPackageIoOveruseStats(/*uid=*/1113999, /*shouldNotify=*/false,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(15'000, 7'000, 100'000),
/*written=*/constructPerStateBytes(55'000, 23'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, nextDayStartTime, nextDayDuration),
- constructPackageIoOveruseStats(/*uid*=*/1212345, /*shouldNotify=*/false,
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/false,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(15'000, 7'000, 100'000),
/*written=*/constructPerStateBytes(55'000, 23'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, nextDayStartTime,
nextDayDuration)};
@@ -484,22 +494,25 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithGarageMode) {
<< "\nActual: " << actualOverusingNativeStats.toString();
const std::vector<PackageIoOveruseStats> expectedIoOveruseStats =
- {constructPackageIoOveruseStats(/*uid*=*/1001000, /*shouldNotify=*/true,
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/true,
/*isKillable=*/false, /*remaining=*/
constructPerStateBytes(80'000, 40'000, 0),
/*written=*/constructPerStateBytes(0, 0, 130'000),
+ /*forgiven=*/constructPerStateBytes(0, 0, 100'000),
/*totalOveruses=*/1, startTime, durationInSeconds),
- constructPackageIoOveruseStats(/*uid*=*/1112345, /*shouldNotify=*/false,
+ constructPackageIoOveruseStats(/*uid=*/1112345, /*shouldNotify=*/false,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(70'000, 30'000, 50'000),
/*written=*/constructPerStateBytes(0, 0, 50'000),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
// Exceeds threshold.
- constructPackageIoOveruseStats(/*uid*=*/1212345, /*shouldNotify=*/true,
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/true,
/*isKillable=*/true,
/*remaining=*/
constructPerStateBytes(70'000, 30'000, 0),
/*written=*/constructPerStateBytes(0, 0, 110'000),
+ /*forgiven=*/constructPerStateBytes(0, 0, 100'000),
/*totalOveruses=*/1, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
@@ -524,6 +537,76 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithZeroWriteBytes) {
mMockUidStatsCollector, nullptr));
}
+TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithExtremeOveruse) {
+ EXPECT_CALL(*mMockUidStatsCollector, deltaStats())
+ .WillOnce(Return(
+ constructUidStats({{1001000, {/*fgWrBytes=*/190'000, /*bgWrBytes=*/42'000}},
+ {1212345, {/*fgWrBytes=*/90'000, /*bgWrBytes=*/90'000}}})));
+
+ time_t currentTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
+ const auto [startTime, durationInSeconds] = calculateStartAndDuration(currentTime);
+
+ std::vector<PackageIoOveruseStats> actualPackageIoOveruseStats;
+ EXPECT_CALL(*mMockWatchdogServiceHelper, latestIoOveruseStats(_))
+ .WillOnce(DoAll(SaveArg<0>(&actualPackageIoOveruseStats), Return(Status::ok())));
+
+ ASSERT_RESULT_OK(mIoOveruseMonitor->onPeriodicCollection(currentTime, SystemState::NORMAL_MODE,
+ mMockUidStatsCollector, nullptr));
+
+ std::vector<PackageIoOveruseStats> expectedPackageIoOveruseStats =
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/true,
+ /*isKillable=*/false, /*remaining=*/
+ constructPerStateBytes(0, 0, 100'000),
+ /*written=*/constructPerStateBytes(190'000, 42'000, 0),
+ /*forgiven=*/constructPerStateBytes(160'000, 40'000, 0),
+ /*totalOveruses=*/3, startTime, durationInSeconds),
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/true,
+ /*isKillable=*/true, /*remaining=*/
+ constructPerStateBytes(0, 0, 100'000),
+ /*written=*/constructPerStateBytes(90'000, 90'000, 0),
+ /*forgiven=*/constructPerStateBytes(70'000, 90'000, 0),
+ /*totalOveruses=*/4, startTime, durationInSeconds)};
+ EXPECT_THAT(actualPackageIoOveruseStats,
+ UnorderedElementsAreArray(expectedPackageIoOveruseStats))
+ << "Expected: " << toString(expectedPackageIoOveruseStats)
+ << "\nActual: " << toString(actualPackageIoOveruseStats);
+}
+
+TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithExtremeOveruseInGarageMode) {
+ EXPECT_CALL(*mMockUidStatsCollector, deltaStats())
+ .WillOnce(Return(
+ constructUidStats({{1001000, {/*fgWrBytes=*/190'000, /*bgWrBytes=*/42'000}},
+ {1212345, {/*fgWrBytes=*/90'000, /*bgWrBytes=*/90'000}}})));
+
+ time_t currentTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
+ const auto [startTime, durationInSeconds] = calculateStartAndDuration(currentTime);
+
+ std::vector<PackageIoOveruseStats> actualPackageIoOveruseStats;
+ EXPECT_CALL(*mMockWatchdogServiceHelper, latestIoOveruseStats(_))
+ .WillOnce(DoAll(SaveArg<0>(&actualPackageIoOveruseStats), Return(Status::ok())));
+
+ ASSERT_RESULT_OK(mIoOveruseMonitor->onPeriodicCollection(currentTime, SystemState::GARAGE_MODE,
+ mMockUidStatsCollector, nullptr));
+
+ std::vector<PackageIoOveruseStats> expectedPackageIoOveruseStats =
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/true,
+ /*isKillable=*/false, /*remaining=*/
+ constructPerStateBytes(80'000, 40'000, 0),
+ /*written=*/constructPerStateBytes(0, 0, 232'000),
+ /*forgiven=*/constructPerStateBytes(0, 0, 200'000),
+ /*totalOveruses=*/2, startTime, durationInSeconds),
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/true,
+ /*isKillable=*/true, /*remaining=*/
+ constructPerStateBytes(70'000, 30'000, 0),
+ /*written=*/constructPerStateBytes(0, 0, 180'000),
+ /*forgiven=*/constructPerStateBytes(0, 0, 100'000),
+ /*totalOveruses=*/1, startTime, durationInSeconds)};
+ EXPECT_THAT(actualPackageIoOveruseStats,
+ UnorderedElementsAreArray(expectedPackageIoOveruseStats))
+ << "Expected: " << toString(expectedPackageIoOveruseStats)
+ << "\nActual: " << toString(actualPackageIoOveruseStats);
+}
+
TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithSmallWrittenBytes) {
/*
* UID 1212345 current written bytes < |KTestMinSyncWrittenBytes| so the UID's stats are not
@@ -547,21 +630,24 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithSmallWrittenBytes) {
mMockUidStatsCollector, nullptr));
std::vector<PackageIoOveruseStats> expectedIoOveruseStats =
- {constructPackageIoOveruseStats(/*uid*=*/1001000, /*shouldNotify=*/false,
+ {constructPackageIoOveruseStats(/*uid=*/1001000, /*shouldNotify=*/false,
/*isKillable=*/false, /*remaining=*/
constructPerStateBytes(20'800, 40'000, 100'000),
/*written=*/
constructPerStateBytes(59'200, 0, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
- constructPackageIoOveruseStats(/*uid*=*/1112345, /*shouldNotify=*/true,
+ constructPackageIoOveruseStats(/*uid=*/1112345, /*shouldNotify=*/true,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(70'000, 4'800, 100'000),
/*written=*/constructPerStateBytes(0, 25'200, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
- constructPackageIoOveruseStats(/*uid*=*/1312345, /*shouldNotify=*/false,
+ constructPackageIoOveruseStats(/*uid=*/1312345, /*shouldNotify=*/false,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(18'800, 30'000, 100'000),
/*written=*/constructPerStateBytes(51'200, 0, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
@@ -593,20 +679,24 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithSmallWrittenBytes) {
mMockUidStatsCollector, nullptr));
expectedIoOveruseStats =
- {constructPackageIoOveruseStats(/*uid*=*/1112345, /*shouldNotify=*/true,
+ {constructPackageIoOveruseStats(/*uid=*/1112345, /*shouldNotify=*/true,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(70'000, 0, 100'000),
/*written=*/constructPerStateBytes(0, 30'100, 0),
+ /*forgiven=*/
+ constructPerStateBytes(0, 30'000, 0),
/*totalOveruses=*/1, startTime, durationInSeconds),
- constructPackageIoOveruseStats(/*uid*=*/1212345, /*shouldNotify=*/false,
+ constructPackageIoOveruseStats(/*uid=*/1212345, /*shouldNotify=*/false,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(65'000, 29'400, 100'000),
/*written=*/constructPerStateBytes(5'000, 600, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
- constructPackageIoOveruseStats(/*uid*=*/1312345, /*shouldNotify=*/true,
+ constructPackageIoOveruseStats(/*uid=*/1312345, /*shouldNotify=*/true,
/*isKillable=*/true, /*remaining=*/
constructPerStateBytes(13'900, 30'000, 100'000),
/*written=*/constructPerStateBytes(56'100, 0, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
@@ -666,11 +756,13 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithPrevBootStats) {
/*uid*=*/1001000, /*shouldNotify=*/false, /*isKillable=*/false,
/*remaining=*/constructPerStateBytes(10'000, 20'000, 100'000),
/*written=*/constructPerStateBytes(70'000, 20'000, 0),
+ /*forgiven=*/constructPerStateBytes(0, 0, 0),
/*totalOveruses=*/0, startTime, durationInSeconds),
constructPackageIoOveruseStats(
/*uid*=*/1112345, /*shouldNotify=*/true, /*isKillable=*/true,
/*remaining=*/constructPerStateBytes(5'000, 0, 80'000),
/*written=*/constructPerStateBytes(135'000, 100'000, 120'000),
+ /*forgiven=*/constructPerStateBytes(70'000, 90'000, 100'000),
/*totalOveruses=*/4, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
@@ -690,14 +782,16 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithPrevBootStats) {
expectedIoOveruseStats = {constructPackageIoOveruseStats(
/*uid*=*/1112345, /*shouldNotify=*/true, /*isKillable=*/true,
- /*remaining=*/constructPerStateBytes(70'000, 30'000, 0),
+ /*remaining=*/constructPerStateBytes(5'000, 20'000, 0),
/*written=*/constructPerStateBytes(135'000, 100'000, 230'000),
+ /*forgiven=*/constructPerStateBytes(70'000, 90'000, 200'000),
/*totalOveruses=*/5, startTime, durationInSeconds),
constructPackageIoOveruseStats(
/*uid*=*/1245678, /*shouldNotify=*/true, /*isKillable=*/true,
/*remaining=*/constructPerStateBytes(10'000, 5'000, 0),
/*written=*/constructPerStateBytes(50'000, 40'000, 75'000),
- /*totalOveruses=*/7, startTime, durationInSeconds)};
+ /*forgiven=*/constructPerStateBytes(30'000, 30'000, 70'000),
+ /*totalOveruses=*/10, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
<< "\nActual: " << toString(actualIoOveruseStats);
@@ -740,7 +834,8 @@ TEST_F(IoOveruseMonitorTest, TestOnPeriodicCollectionWithErrorFetchingPrevBootSt
/*uid*=*/1112345, /*shouldNotify=*/true, /*isKillable=*/true,
/*remaining=*/constructPerStateBytes(5'000, 0, 80'000),
/*written=*/constructPerStateBytes(135'000, 140'000, 120'000),
- /*totalOveruses=*/4, startTime, durationInSeconds)};
+ /*forgiven=*/constructPerStateBytes(70'000, 120'000, 100'000),
+ /*totalOveruses=*/5, startTime, durationInSeconds)};
EXPECT_THAT(actualIoOveruseStats, UnorderedElementsAreArray(expectedIoOveruseStats))
<< "Expected: " << toString(expectedIoOveruseStats)
<< "\nActual: " << toString(actualIoOveruseStats);
@@ -878,7 +973,7 @@ TEST_F(IoOveruseMonitorTest, TestGetIoOveruseStats) {
const auto expected =
constructIoOveruseStats(/*isKillable=*/false,
/*remaining=*/
- constructPerStateBytes(80'000, 40'000, 100'000),
+ constructPerStateBytes(70'000, 20'000, 100'000),
/*written=*/
constructPerStateBytes(90'000, 20'000, 0),
/*totalOveruses=*/1, startTime, durationInSeconds);