diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index 278798000355dc6fff60c6d81aad6233e2d80a1e..0a9707ab6b9e7f1a859f96f145f3ed0019f60f27 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -789,9 +789,10 @@ float CommonEventCollect::GetCpuUsage(const char* file, uint32_t interval) return CPU_LOAD_INVALID; } - uint64_t totalDelta = total - totalPre; - uint64_t idleDelta = idle - idlePre; - if (totalDelta == 0) { + constexpr uint64_t MAX = std::numeric_limits::max(); + uint64_t totalDelta = (total >= totalPre) ? (total - totalPre) : (MAX - totalPre + total); + uint64_t idleDelta = (idle >= idlePre) ? (idle - idlePre) : (MAX - idlePre + idle); + if (totalDelta == 0 || totalDelta < idleDelta) { return CPU_LOAD_INVALID; }