diff options
author | Lakshman Annadorai <lakshmana@google.com> | 2021-04-29 13:51:50 -0700 |
---|---|---|
committer | Lakshman Annadorai <lakshmana@google.com> | 2021-04-29 14:01:55 -0700 |
commit | ac888d6652c1f13653b6708529cae464857bb960 (patch) | |
tree | 171d91bfb1fc0d9dcc4646e935261b880dc1e4ec /cpp/watchdog | |
parent | 69e56e8fbc2f2368764f4d6ede79759ce07a78d8 (diff) | |
download | Car-ac888d6652c1f13653b6708529cae464857bb960.tar.gz |
Replace uint64_t with int64_t as bytes datatype in daemon.
int64_t has space to represent the 8 exabytes, which is a very large
value.
Test: atest libwatchdog_test
Bug: 186784050
Change-Id: I312b5ae04e9bbdf0831206f586ea9c4c6818a306
Diffstat (limited to 'cpp/watchdog')
-rw-r--r-- | cpp/watchdog/server/src/IoOveruseConfigs.h | 6 | ||||
-rw-r--r-- | cpp/watchdog/server/src/IoOveruseMonitor.cpp | 21 | ||||
-rw-r--r-- | cpp/watchdog/server/src/IoPerfCollection.cpp | 4 | ||||
-rw-r--r-- | cpp/watchdog/server/src/IoPerfCollection.h | 6 | ||||
-rw-r--r-- | cpp/watchdog/server/src/UidIoStats.cpp | 19 | ||||
-rw-r--r-- | cpp/watchdog/server/src/UidIoStats.h | 18 | ||||
-rw-r--r-- | cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp | 2 |
7 files changed, 38 insertions, 38 deletions
diff --git a/cpp/watchdog/server/src/IoOveruseConfigs.h b/cpp/watchdog/server/src/IoOveruseConfigs.h index cd80a95d15..e0a24355c3 100644 --- a/cpp/watchdog/server/src/IoOveruseConfigs.h +++ b/cpp/watchdog/server/src/IoOveruseConfigs.h @@ -42,9 +42,9 @@ inline const android::automotive::watchdog::internal::PerStateIoOveruseThreshold defaultThreshold() { android::automotive::watchdog::internal::PerStateIoOveruseThreshold threshold; threshold.name = kDefaultThresholdName; - threshold.perStateWriteBytes.foregroundBytes = std::numeric_limits<uint64_t>::max(); - threshold.perStateWriteBytes.backgroundBytes = std::numeric_limits<uint64_t>::max(); - threshold.perStateWriteBytes.garageModeBytes = std::numeric_limits<uint64_t>::max(); + threshold.perStateWriteBytes.foregroundBytes = std::numeric_limits<int64_t>::max(); + threshold.perStateWriteBytes.backgroundBytes = std::numeric_limits<int64_t>::max(); + threshold.perStateWriteBytes.garageModeBytes = std::numeric_limits<int64_t>::max(); return threshold; } diff --git a/cpp/watchdog/server/src/IoOveruseMonitor.cpp b/cpp/watchdog/server/src/IoOveruseMonitor.cpp index 080b284728..c724d57f83 100644 --- a/cpp/watchdog/server/src/IoOveruseMonitor.cpp +++ b/cpp/watchdog/server/src/IoOveruseMonitor.cpp @@ -48,7 +48,7 @@ using ::android::base::Result; using ::android::binder::Status; // Minimum written bytes to sync the stats with the Watchdog service. -constexpr uint64_t kMinSyncWrittenBytes = 100 * 1024; +constexpr int64_t kMinSyncWrittenBytes = 100 * 1024; // Minimum percentage of threshold to warn killable applications. constexpr double kDefaultIoOveruseWarnPercentage = 80; // Maximum numer of system-wide stats (from periodic monitoring) to cache. @@ -61,7 +61,7 @@ std::string uniquePackageIdStr(const PackageIdentifier& id) { } PerStateBytes diff(const PerStateBytes& lhs, const PerStateBytes& rhs) { - const auto sub = [](const uint64_t& l, const uint64_t& r) -> uint64_t { + const auto sub = [](const int64_t& l, const int64_t& r) -> int64_t { return l >= r ? (l - r) : 0; }; PerStateBytes result; @@ -83,10 +83,10 @@ std::tuple<int64_t, int64_t> calculateStartAndDuration(struct tm currentTm) { return std::make_tuple(startTime, currentEpochSeconds - startTime); } -uint64_t totalPerStateBytes(PerStateBytes perStateBytes) { - const auto sum = [](const uint64_t& l, const uint64_t& r) -> uint64_t { - return std::numeric_limits<uint64_t>::max() - l > r ? (l + r) - : std::numeric_limits<uint64_t>::max(); +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 sum(perStateBytes.foregroundBytes, sum(perStateBytes.backgroundBytes, perStateBytes.garageModeBytes)); @@ -351,7 +351,7 @@ Result<void> IoOveruseMonitor::onPeriodicMonitor( {.pollDurationInSecs = difftime(time, mLastSystemWideIoMonitorTime), .bytesInKib = diskStats.numKibWritten}); for (const auto& threshold : mIoOveruseConfigs->systemWideAlertThresholds()) { - uint64_t accountedWrittenKib = 0; + int64_t accountedWrittenKib = 0; double accountedDurationInSecs = 0; size_t accountedPolls = 0; for (auto rit = mSystemWideWrittenBytes.rbegin(); rit != mSystemWideWrittenBytes.rend(); @@ -564,10 +564,9 @@ IoOveruseMonitor::UserPackageIoUsage& IoOveruseMonitor::UserPackageIoUsage::oper if (id() == r.id()) { packageInfo = r.packageInfo; } - const auto sum = [](const uint64_t& l, const uint64_t& r) -> uint64_t { - return (std::numeric_limits<uint64_t>::max() - l) > r - ? (l + r) - : std::numeric_limits<uint64_t>::max(); + 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(); }; writtenBytes.foregroundBytes = sum(writtenBytes.foregroundBytes, r.writtenBytes.foregroundBytes); diff --git a/cpp/watchdog/server/src/IoPerfCollection.cpp b/cpp/watchdog/server/src/IoPerfCollection.cpp index 22dc45f3ed..08c1daa2bc 100644 --- a/cpp/watchdog/server/src/IoPerfCollection.cpp +++ b/cpp/watchdog/server/src/IoPerfCollection.cpp @@ -161,7 +161,7 @@ std::string toString(const UidIoPerfData& data) { for (const auto& stat : data.topNReads) { StringAppendF(&buffer, "%" PRIu32 ", %s", stat.userId, stat.packageName.c_str()); for (int i = 0; i < UID_STATES; ++i) { - StringAppendF(&buffer, ", %" PRIu64 ", %.2f%%, %" PRIu64 ", %.2f%%", stat.bytes[i], + StringAppendF(&buffer, ", %" PRIi64 ", %.2f%%, %" PRIi64 ", %.2f%%", stat.bytes[i], percentage(stat.bytes[i], data.total[READ_BYTES][i]), stat.fsync[i], percentage(stat.fsync[i], data.total[FSYNC_COUNT][i])); } @@ -177,7 +177,7 @@ std::string toString(const UidIoPerfData& data) { for (const auto& stat : data.topNWrites) { StringAppendF(&buffer, "%" PRIu32 ", %s", stat.userId, stat.packageName.c_str()); for (int i = 0; i < UID_STATES; ++i) { - StringAppendF(&buffer, ", %" PRIu64 ", %.2f%%, %" PRIu64 ", %.2f%%", stat.bytes[i], + StringAppendF(&buffer, ", %" PRIi64 ", %.2f%%, %" PRIi64 ", %.2f%%", stat.bytes[i], percentage(stat.bytes[i], data.total[WRITE_BYTES][i]), stat.fsync[i], percentage(stat.fsync[i], data.total[FSYNC_COUNT][i])); } diff --git a/cpp/watchdog/server/src/IoPerfCollection.h b/cpp/watchdog/server/src/IoPerfCollection.h index e86320fff9..1c40d00fed 100644 --- a/cpp/watchdog/server/src/IoPerfCollection.h +++ b/cpp/watchdog/server/src/IoPerfCollection.h @@ -49,12 +49,12 @@ struct UidIoPerfData { struct Stats { userid_t userId = 0; std::string packageName; - uint64_t bytes[UID_STATES]; - uint64_t fsync[UID_STATES]; + int64_t bytes[UID_STATES]; + int64_t fsync[UID_STATES]; }; std::vector<Stats> topNReads = {}; std::vector<Stats> topNWrites = {}; - uint64_t total[METRIC_TYPES][UID_STATES] = {{0}}; + int64_t total[METRIC_TYPES][UID_STATES] = {{0}}; }; std::string toString(const UidIoPerfData& perfData); diff --git a/cpp/watchdog/server/src/UidIoStats.cpp b/cpp/watchdog/server/src/UidIoStats.cpp index ce7b351d57..e88693aded 100644 --- a/cpp/watchdog/server/src/UidIoStats.cpp +++ b/cpp/watchdog/server/src/UidIoStats.cpp @@ -36,6 +36,7 @@ namespace automotive { namespace watchdog { using ::android::base::Error; +using ::android::base::ParseInt; using ::android::base::ParseUint; using ::android::base::ReadFileToString; using ::android::base::Result; @@ -47,19 +48,19 @@ namespace { bool parseUidIoStats(const std::string& data, UidIoUsage* usage) { std::vector<std::string> fields = Split(data, " "); if (fields.size() < 11 || !ParseUint(fields[0], &usage->uid) || - !ParseUint(fields[3], &usage->ios.metrics[READ_BYTES][FOREGROUND]) || - !ParseUint(fields[4], &usage->ios.metrics[WRITE_BYTES][FOREGROUND]) || - !ParseUint(fields[7], &usage->ios.metrics[READ_BYTES][BACKGROUND]) || - !ParseUint(fields[8], &usage->ios.metrics[WRITE_BYTES][BACKGROUND]) || - !ParseUint(fields[9], &usage->ios.metrics[FSYNC_COUNT][FOREGROUND]) || - !ParseUint(fields[10], &usage->ios.metrics[FSYNC_COUNT][BACKGROUND])) { + !ParseInt(fields[3], &usage->ios.metrics[READ_BYTES][FOREGROUND]) || + !ParseInt(fields[4], &usage->ios.metrics[WRITE_BYTES][FOREGROUND]) || + !ParseInt(fields[7], &usage->ios.metrics[READ_BYTES][BACKGROUND]) || + !ParseInt(fields[8], &usage->ios.metrics[WRITE_BYTES][BACKGROUND]) || + !ParseInt(fields[9], &usage->ios.metrics[FSYNC_COUNT][FOREGROUND]) || + !ParseInt(fields[10], &usage->ios.metrics[FSYNC_COUNT][BACKGROUND])) { ALOGW("Invalid uid I/O stats: \"%s\"", data.c_str()); return false; } return true; } -uint64_t maybeDiff(uint64_t lhs, uint64_t rhs) { +int64_t maybeDiff(int64_t lhs, int64_t rhs) { return lhs > rhs ? lhs - rhs : 0; } @@ -93,8 +94,8 @@ bool IoUsage::isZero() const { } std::string IoUsage::toString() const { - return StringPrintf("FgRdBytes:%" PRIu64 " BgRdBytes:%" PRIu64 " FgWrBytes:%" PRIu64 - " BgWrBytes:%" PRIu64 " FgFsync:%" PRIu64 " BgFsync:%" PRIu64, + return StringPrintf("FgRdBytes:%" PRIi64 " BgRdBytes:%" PRIi64 " FgWrBytes:%" PRIi64 + " BgWrBytes:%" PRIi64 " FgFsync:%" PRIi64 " BgFsync:%" PRIi64, metrics[READ_BYTES][FOREGROUND], metrics[READ_BYTES][BACKGROUND], metrics[WRITE_BYTES][FOREGROUND], metrics[WRITE_BYTES][BACKGROUND], metrics[FSYNC_COUNT][FOREGROUND], metrics[FSYNC_COUNT][BACKGROUND]); diff --git a/cpp/watchdog/server/src/UidIoStats.h b/cpp/watchdog/server/src/UidIoStats.h index 3cc6a76dcb..b3257f81e6 100644 --- a/cpp/watchdog/server/src/UidIoStats.h +++ b/cpp/watchdog/server/src/UidIoStats.h @@ -49,8 +49,8 @@ enum MetricType { class IoUsage { public: IoUsage() : metrics{{0}} {}; - IoUsage(uint64_t fgRdBytes, uint64_t bgRdBytes, uint64_t fgWrBytes, uint64_t bgWrBytes, - uint64_t fgFsync, uint64_t bgFsync) { + IoUsage(int64_t fgRdBytes, int64_t bgRdBytes, int64_t fgWrBytes, int64_t bgWrBytes, + int64_t fgFsync, int64_t bgFsync) { metrics[READ_BYTES][FOREGROUND] = fgRdBytes; metrics[READ_BYTES][BACKGROUND] = bgRdBytes; metrics[WRITE_BYTES][FOREGROUND] = fgWrBytes; @@ -62,23 +62,23 @@ public: bool operator==(const IoUsage& usage) const { return memcmp(&metrics, &usage.metrics, sizeof(metrics)) == 0; } - uint64_t sumReadBytes() const { + int64_t sumReadBytes() const { const auto& [fgBytes, bgBytes] = std::tuple(metrics[READ_BYTES][FOREGROUND], metrics[READ_BYTES][BACKGROUND]); - return (std::numeric_limits<uint64_t>::max() - fgBytes) > bgBytes + return (std::numeric_limits<int64_t>::max() - fgBytes) > bgBytes ? (fgBytes + bgBytes) - : std::numeric_limits<uint64_t>::max(); + : std::numeric_limits<int64_t>::max(); } - uint64_t sumWriteBytes() const { + int64_t sumWriteBytes() const { const auto& [fgBytes, bgBytes] = std::tuple(metrics[WRITE_BYTES][FOREGROUND], metrics[WRITE_BYTES][BACKGROUND]); - return (std::numeric_limits<uint64_t>::max() - fgBytes) > bgBytes + return (std::numeric_limits<int64_t>::max() - fgBytes) > bgBytes ? (fgBytes + bgBytes) - : std::numeric_limits<uint64_t>::max(); + : std::numeric_limits<int64_t>::max(); } bool isZero() const; std::string toString() const; - uint64_t metrics[METRIC_TYPES][UID_STATES]; + int64_t metrics[METRIC_TYPES][UID_STATES]; }; struct UidIoUsage { diff --git a/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp b/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp index 4ee94eb38c..89dd263a1e 100644 --- a/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp +++ b/cpp/watchdog/server/tests/IoOveruseMonitorTest.cpp @@ -31,7 +31,7 @@ namespace automotive { namespace watchdog { constexpr size_t kTestMonitorBufferSize = 3; -constexpr uint64_t KTestMinSyncWrittenBytes = 5'000; +constexpr int64_t KTestMinSyncWrittenBytes = 5'000; constexpr double kTestIoOveruseWarnPercentage = 80; constexpr std::chrono::seconds kTestMonitorInterval = 5s; |