From 1df7658c1f9435daf38a3b3856bb625952fe3294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=98=89=E5=AE=9D?= Date: Wed, 7 May 2025 14:54:15 +0800 Subject: [PATCH] modify uint64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 黄嘉宝 --- .../samgr/native/source/collect/common_event_collect.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index 9573fbfd..6f6ca8b8 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -791,9 +791,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; } -- Gitee