From 3821518a479a5651d8d790541d7ea2db0dfe120b Mon Sep 17 00:00:00 2001 From: gaozhichao Date: Fri, 24 Jan 2025 15:14:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[add]=20=E6=97=B6=E9=97=B4=E6=97=B6?= =?UTF-8?q?=E5=8C=BA=E5=A2=9E=E5=8A=A0=E6=89=93=E7=82=B9=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaozhichao --- hisysevent.yaml | 45 ++++++++++-- services/dfx/include/time_sysevent.h | 33 ++++++++- services/dfx/src/time_sysevent.cpp | 92 +++++++++++++++++++++++-- services/ipc/stub/time_service_stub.cpp | 1 + services/time/src/ntp_update_time.cpp | 1 + services/time/src/sntp_client.cpp | 3 + services/time/src/time_zone_info.cpp | 2 + services/time_system_ability.cpp | 3 + services/time_system_ability.h | 1 + services/timer/include/timer_manager.h | 2 +- services/timer/include/timer_proxy.h | 1 + services/timer/src/timer_manager.cpp | 30 ++++++-- services/timer/src/timer_proxy.cpp | 39 +++++++---- 13 files changed, 220 insertions(+), 33 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index 5a8c6b1f..ca97d3e8 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -14,9 +14,44 @@ domain: TIME MISC_TIME_STATISTIC_REPORT: - __BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: trigger timer report} - CALLER_PID: {type: INT32, desc: the process id} - CALLER_UID: {type: INT32, desc: the user id} + __BASE: {type: STATISTIC, level: CRITICAL, tag: PowerStats, desc: trigger timer report, preserve: true} TIMER_TYPE: {type: INT32, desc: the timer type} TRIGGER_TIME: {type: INT64, desc: the trigger time} - INTERVAL: {type: INT32, desc: the interval time} \ No newline at end of file + CALLER_UID: {type: INT32, desc: the user id} + INTERVAL: {type: INT32, desc: the interval time} + CALLER_PID: {type: INT32, desc: the process id} + BUNDLE_OR_PROCESS_NAME: {type: STRING, desc: the trigger bundle or process name} + TIMER_SIZE: {type: INT32, desc: Number of trigger with the same timestamp} + +ALARM_COUNT: +__BASE: {type: STATISTIC, level: CRITICAL, desc: Timer quantity statistics, preserve: true} +TIMER_NUM: {type: INT32, desc: timer number} +TOP_UID: {type: INT32, arrsize: 5, desc: The top five UID with the highest timer quantity} +TOP_NUM: {type: INT32, arrsize: 5, desc: The top five timer quantity} +TOP_STRATED_NUM: {type: INT32, arrsize: 5, desc: The number of timers started under the top five UID with the highest quantity} + +BEHAVIOR_TIME: +__BASE: {type: BEHAVIOR, level: CRITICAL, desc: time or timezone behavior, preserve: true} +EVENT_CODE: {type: INT32, desc: event code} +CALLER_UID: {type: INT32, desc: caller uid} +CALLER_NAME: {type: STRING, desc: caller bundle name or process name} +ORIGINAL_TIME: {type: STRING, desc: original time or timezone} +SET_TIME: {type: STRING, desc: set time or timezone} +NTP_TIME: {type: INT64, desc: NTP time} + +BEHAVIOR_TIMER: +__BASE: {type: BEHAVIOR, level: CRITICAL, desc: timer behavior, preserve: true} +EVENT_CODE: {type: INT32, desc: event code} +TIMER_ID: {type: UINT32, desc: timer id} +TRIGGER_TIME: {type: INT64, desc: trigger time} +CALLER_UID: {type: INT32, desc: caller uid} +CALLER_NAME: {type: STRING, desc: caller bundle or process name} +INTERVAL: {type: UINT32, desc: trigger interval} + +FUNC_FAULT: +__BASE: {type: FAULT, level: CRITICAL, desc: Time fault error, preserve: true} +EVENT_CODE: {type: INT32, desc: event code} +ERR_CODE: {type: INT32, desc: error code or system error} +CALLER_UID: {type: INT32, desc: caller uid} +CALLER_NAME: {type: STRING, desc: caller bundle name or process name} +EXTRA: {type: STRING, desc: extra infomation} \ No newline at end of file diff --git a/services/dfx/include/time_sysevent.h b/services/dfx/include/time_sysevent.h index 99fb9af3..2d32a92e 100644 --- a/services/dfx/include/time_sysevent.h +++ b/services/dfx/include/time_sysevent.h @@ -21,7 +21,38 @@ namespace OHOS { namespace MiscServices { -void StatisticReporter(int32_t callerPid, int32_t size, std::shared_ptr timer); +constexpr int32_t START_TIMER_OFFSET = 0x00000000; +constexpr int32_t TRIGGER_TIMER_OFFSET = 0x00000100; +constexpr int32_t TIMER_COUNT_OFFSET = 0x00000200; +constexpr int32_t MODIFY_TIME_OFFSET = 0x01000000; +constexpr int32_t EXACT_OFFSET = 4; + +enum ReportEventCode : int32_t { + RTC_WAKEUP_EXACT_TIMER_START = START_TIMER_OFFSET, + RTC_NONWAKEUP_EXACT_TIMER_START, + REALTIME_WAKEUP_EXACT_TIMER_START, + REALTIME_NONWAKEUP_EXACT_TIMER_START, + RTC_WAKEUP_NONEXACT_TIMER_START, + RTC_NONWAKEUP_NONEXACT_TIMER_START, + REALTIME_WAKEUP_NONEXACT_TIMER_START, + REALTIME_NONWAKEUP_NONEXACT_TIMER_START, + RTC_WAKEUP_EXACT_TIMER_TRIGGER = TRIGGER_TIMER_OFFSET, + RTC_NONWAKEUP_EXACT_TIMER_TRIGGER, + REALTIME_WAKEUP_EXACT_TIMER_TRIGGER, + REALTIME_NONWAKEUP_EXACT_TIMER_TRIGGER, + RTC_WAKEUP_NONEXACT_TIMER_TRIGGER, + RTC_NONWAKEUP_NONEXACT_TIMER_TRIGGER, + REALTIME_WAKEUP_NONEXACT_TIMER_TRIGGER, + REALTIME_NONWAKEUP_NONEXACT_TIMER_TRIGGER, + TIMER_COUNT_REPORT = TIMER_COUNT_OFFSET, + SET_TIME = MODIFY_TIME_OFFSET, + NTP_REFRESH, + SET_TIMEZONE, +}; +void StatisticReporter(int32_t size, std::shared_ptr timer); +void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std::string newTime, int64_t ntpTime); +void TimerBehaviorReport(std::shared_ptr timer, bool isStart); +void TimerCountStaticReporter(int count, int* uidArr, int* createTimerCountArr, int* startTimerCountArr); } // namespace MiscServices } // namespace OHOS #endif // TIME_SYSEVENT_H diff --git a/services/dfx/src/time_sysevent.cpp b/services/dfx/src/time_sysevent.cpp index 0bb18793..a558f902 100644 --- a/services/dfx/src/time_sysevent.cpp +++ b/services/dfx/src/time_sysevent.cpp @@ -17,6 +17,8 @@ #include "hisysevent.h" #include "time_hilog.h" +#include "time_file_utils.h" +#include "ipc_skeleton.h" namespace OHOS { namespace MiscServices { @@ -24,25 +26,103 @@ namespace { using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; } // namespace -void StatisticReporter(int32_t callerPid, int32_t size, std::shared_ptr timer) +std::string GetBundleOrProcessName() +{ + std::string bundleOrProcessName = TimeFileUtils::GetBundleNameByTokenID(IPCSkeleton::GetCallingTokenID()); + if (bundleOrProcessName.empty()) { + bundleOrProcessName = TimeFileUtils::GetNameByPid(IPCSkeleton::GetCallingPid()); + } + return bundleOrProcessName; +} + +void StatisticReporter(int32_t size, std::shared_ptr timer) { if (timer == nullptr) { return; } int32_t callerUid = timer->uid; + int32_t callerPid = timer->pid; std::string bundleOrProcessName = timer->bundleName; int32_t type = timer->type; int64_t triggerTime = timer->whenElapsed.time_since_epoch().count(); auto interval = static_cast(timer->repeatInterval.count()); - int ret = HiSysEventWrite(HiSysEventNameSpace::Domain::TIME, "MISC_TIME_STATISTIC_REPORT", - HiSysEventNameSpace::EventType::STATISTIC, "CALLER_PID", callerPid, "CALLER_UID", callerUid, - "BUNDLE_OR_PROCESS_NAME", bundleOrProcessName, "TIMER_SIZE", size, "TIMER_TYPE", type, - "TRIGGER_TIME", triggerTime, "INTERVAL", interval); + struct HiSysEventParam params[] = { + {"CALLER_PID", HISYSEVENT_INT32, {callerPid}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {callerUid}, 0}, + {"BUNDLE_OR_PROCESS_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, bundleOrProcessName.length()}, + {"TIMER_SIZE", HISYSEVENT_INT32, {size}, 0}, + {"TIMER_TYPE", HISYSEVENT_INT32, {type}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {triggerTime}, 0}, + {"INTERVAL", HISYSEVENT_UINT64, {interval}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "MISC_TIME_STATISTIC_REPORT", HISYSEVENT_STATISTIC, + params, sizeof(sizeof(params)/sizeof(params[0]))); if (ret != 0) { TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed! pid %{public}d,uid %{public}d,timer type %{public}d", callerPid, callerUid, type); } } -} // namespace MiscServices + +void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std::string newTime, int64_t ntpTime) +{ + std::string bundleOrProcessName = GetBundleOrProcessName(); + struct HiSysEventParam params[] = { + {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {IPCSkeleton::GetCallingUid()}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, bundleOrProcessName.length()}, + {"ORIGINAL_TIME", HISYSEVENT_STRING, {originTime.c_str()}, originTime.length()}, + {"SET_TIME", HISYSEVENT_STRING, {newTime.c_str()}, newTime.length()}, + {"NTP_TIME", HISYSEVENT_INT64, {ntpTime}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIME", HISYSEVENT_BEHAVIOR, params, + sizeof(sizeof(params)/sizeof(params[0]))); + if (ret != 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "TimeBehaviorReport Statistic failed! eventCode %{public}d," + "name:%{public}s", eventCode, bundleOrProcessName.c_str()); + } +} + +void TimerBehaviorReport(std::shared_ptr timer, bool isStart) +{ + if (timer == nullptr) { + return; + } + int triggerOffset = isStart ? RTC_WAKEUP_EXACT_TIMER_START : RTC_WAKEUP_EXACT_TIMER_TRIGGER; + int exactOffset = (timer->windowLength == std::chrono::milliseconds::zero()) ? 0 : EXACT_OFFSET; + ReportEventCode eventCode = static_cast(triggerOffset + timer->type + exactOffset); + auto bundleOrProcessName = timer->bundleName; + auto interval = static_cast(timer->repeatInterval.count()); + struct HiSysEventParam params[] = { + {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, + {"TIMER_ID", HISYSEVENT_UINT32, {timer->id}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {timer->when.count()}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {timer->uid}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, 0}, + {"INTERVAL", HISYSEVENT_UINT32, {interval}, 0} + }; + int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIMER", HISYSEVENT_BEHAVIOR, + params, sizeof(sizeof(params)/sizeof(params[0]))); + if (ret != 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, + "TimerBehaviorReport failed! pid %{public}d,uid %{public}d,timer type %{public}d", timer->pid, timer->uid, + timer->type); + } +} + +void TimerCountStaticReporter(int count, int* uidArr, int* createTimerCountArr, int* startTimerCountArr) +{ + struct HiSysEventParam params[] = { + {"TIMER_NUM", HISYSEVENT_INT32, {count}, 0}, + {"TOP_UID", HISYSEVENT_INT32_ARRAY, {uidArr}, 5}, + {"TOP_NUM", HISYSEVENT_INT32_ARRAY, {createTimerCountArr}, 5}, + {"TOP_STRAT_NUM", HISYSEVENT_INT32_ARRAY, {startTimerCountArr}, 5} + }; + int ret = OH_HiSysEvent_Write("TIME", "ALARM_COUNT", HISYSEVENT_STATISTIC, + params, sizeof(params)/sizeof(params[0])); + if (ret != 0) { + TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed!"); + } +} +} // namespace MiscServices+ } // namespace OHOS \ No newline at end of file diff --git a/services/ipc/stub/time_service_stub.cpp b/services/ipc/stub/time_service_stub.cpp index 1426e145..07882182 100644 --- a/services/ipc/stub/time_service_stub.cpp +++ b/services/ipc/stub/time_service_stub.cpp @@ -19,6 +19,7 @@ #include "time_service_stub.h" #include "ntp_update_time.h" #include "ntp_trusted_time.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { diff --git a/services/time/src/ntp_update_time.cpp b/services/time/src/ntp_update_time.cpp index de6275a7..8d6cbccd 100644 --- a/services/time/src/ntp_update_time.cpp +++ b/services/time/src/ntp_update_time.cpp @@ -26,6 +26,7 @@ #include "parameters.h" #include "time_common.h" #include "time_system_ability.h" +#include "time_sysevent.h" using namespace std::chrono; diff --git a/services/time/src/sntp_client.cpp b/services/time/src/sntp_client.cpp index c293d88a..9040c77c 100644 --- a/services/time/src/sntp_client.cpp +++ b/services/time/src/sntp_client.cpp @@ -31,6 +31,7 @@ #include #include "time_common.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { @@ -276,6 +277,8 @@ bool SNTPClient::ReceivedMessage(char *buffer) "_receiveClient:%{public}s", std::to_string(_originClient).c_str(), std::to_string(_receiveServer).c_str(), std::to_string(_transmitServer).c_str(), std::to_string(_receiveClient).c_str()); + TimeBehaviorReport(ReportEventCode::NTP_REFRESH, std::to_string(_originClient) + std::to_string(_receiveClient), + std::to_string(_transmitServer) + std::to_string(_receiveClient), mNtpTime); return true; } diff --git a/services/time/src/time_zone_info.cpp b/services/time/src/time_zone_info.cpp index 8c478b65..7f72e522 100644 --- a/services/time/src/time_zone_info.cpp +++ b/services/time/src/time_zone_info.cpp @@ -20,6 +20,7 @@ #include "time_zone_info.h" #include "ipc_skeleton.h" #include "time_file_utils.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { @@ -78,6 +79,7 @@ bool TimeZoneInfo::SetTimezone(const std::string &timezoneId) return false; } curTimezoneId_ = timezoneId; + TimeBehaviorReport(ReportEventCode::SET_TIMEZONE, curTimezoneId_, timezoneId, 0); return true; } diff --git a/services/time_system_ability.cpp b/services/time_system_ability.cpp index 5587c22f..f25b5274 100644 --- a/services/time_system_ability.cpp +++ b/services/time_system_ability.cpp @@ -510,6 +510,9 @@ bool TimeSystemAbility::SetRealTime(int64_t time) TimeServiceNotify::GetInstance().PublishTimeChangeEvents(currentTime); } TimeTickNotify::GetInstance().Callback(); + int64_t curtime = 0; + TimeSystemAbility::GetNtpTimeMs(curtime); + TimeBehaviorReport(ReportEventCode::SET_TIME, std::to_string(beforeTime), std::to_string(time), curtime); return true; } diff --git a/services/time_system_ability.h b/services/time_system_ability.h index a7c87bd4..5196a27f 100644 --- a/services/time_system_ability.h +++ b/services/time_system_ability.h @@ -33,6 +33,7 @@ #include "shutdown/sync_shutdown_callback_stub.h" #include "shutdown/shutdown_client.h" #include "cjson_helper.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { diff --git a/services/timer/include/timer_manager.h b/services/timer/include/timer_manager.h index 3897ee3b..1413504a 100644 --- a/services/timer/include/timer_manager.h +++ b/services/timer/include/timer_manager.h @@ -153,7 +153,7 @@ private: void IncreaseTimerCount(int uid); void DecreaseTimerCount(int uid); void CheckTimerCount(); - void ShowTimerCountByUid(); + void ShowTimerCountByUid(int count); void AddTimerName(int uid, std::string name, uint64_t timerId); void DeleteTimerName(int uid, std::string name, uint64_t timerId); diff --git a/services/timer/include/timer_proxy.h b/services/timer/include/timer_proxy.h index f88ec9c6..5061df03 100644 --- a/services/timer/include/timer_proxy.h +++ b/services/timer/include/timer_proxy.h @@ -48,6 +48,7 @@ public: void RecordProxyTimerMap(const std::shared_ptr &alarm, bool isPid); void RemoveUidTimerMap(const std::shared_ptr &alarm); void RemoveUidTimerMap(const uint64_t id); + int32_t CountUidTimerMapByUid(int32_t uid); bool IsProxy(const int32_t uid, const int32_t pid); #ifdef HIDUMPER_ENABLE bool ShowProxyTimerInfo(int fd, const int64_t now); diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 942e1957..8995fb5e 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -305,7 +305,7 @@ void TimerManager::CheckTimerCount() if (count > (timerOutOfRangeTimes_ + 1) * TIMER_ALARM_COUNT) { timerOutOfRangeTimes_ += 1; TIME_HILOGI(TIME_MODULE_SERVICE, "%{public}d timer in system", count); - ShowTimerCountByUid(); + ShowTimerCountByUid(count); lastTimerOutOfRangeTime_ = GetBootTimeNs(); return; } @@ -313,26 +313,41 @@ void TimerManager::CheckTimerCount() if (count > MAX_TIMER_ALARM_COUNT && currentBootTime - lastTimerOutOfRangeTime_ > std::chrono::minutes(TIMER_ALRAM_INTERVAL)) { TIME_HILOGI(TIME_MODULE_SERVICE, "%{public}d timer in system", count); - ShowTimerCountByUid(); + ShowTimerCountByUid(count); lastTimerOutOfRangeTime_ = currentBootTime; return; } } -void TimerManager::ShowTimerCountByUid() +void TimerManager::ShowTimerCountByUid(int count) { std::string uidStr = ""; std::string countStr = ""; + int* uidArr = new int[TIMER_COUNT_TOP_NUM]; + int* createTimerCountArr = new int[TIMER_COUNT_TOP_NUM]; + int* startTimerCountArr = new int[TIMER_COUNT_TOP_NUM]; auto size = static_cast(timerCount_.size()); std::sort(timerCount_.begin(), timerCount_.end(), [](const std::pair& a, const std::pair& b) { return a.second > b.second; }); auto limitedSize = (size > TIMER_COUNT_TOP_NUM) ? TIMER_COUNT_TOP_NUM : size; - for (auto it = timerCount_.begin(); it != timerCount_.begin() + limitedSize; ++it) { - uidStr = uidStr + std::to_string(it->first) + " "; - countStr = countStr + std::to_string(it->second) + " "; + for (int i = 0; i < TIMER_COUNT_TOP_NUM; i++) { + if (i < limitedSize) { + int uid = timerCount_[i].first; + int createTimerCount = timerCount_[i].second; + uidStr = uidStr + std::to_string(uid) + " "; + countStr = countStr + std::to_string(createTimerCount) + " "; + uidArr[i] = uid; + createTimerCountArr[i] = createTimerCount; + startTimerCountArr[i] = TimerProxy::GetInstance().CountUidTimerMapByUid(uid); + } + uidArr[i] = 0; + createTimerCountArr[i] = 0; + startTimerCountArr[i] = 0; + } + TimerCountStaticReporter(count, uidArr, createTimerCountArr, startTimerCountArr); TIME_HILOGI(TIME_MODULE_SERVICE, "Top uid:[%{public}s], nums:[%{public}s]", uidStr.c_str(), countStr.c_str()); } @@ -930,13 +945,14 @@ void TimerManager::DeliverTimersLocked(const std::vectorwakeup;}); for (const auto &timer : triggerList) { + TimerBehaviorReport(timer, false); if (timer->wakeup) { #ifdef POWER_MANAGER_ENABLE TIME_HILOGD(TIME_MODULE_SERVICE, "id: %{public}" PRId64 ", uid: %{public}d bundleName: %{public}s", timer->id, timer->uid, timer->bundleName.c_str()); AddRunningLock(USE_LOCK_ONE_SEC_IN_NANO); #endif - StatisticReporter(IPCSkeleton::GetCallingPid(), wakeupNums, timer); + StatisticReporter(wakeupNums, timer); } if (timer->callback) { if (TimerProxy::GetInstance().CallbackAlarmIfNeed(timer) == PEER_END_DEAD diff --git a/services/timer/src/timer_proxy.cpp b/services/timer/src/timer_proxy.cpp index fedfe0d7..269f014d 100644 --- a/services/timer/src/timer_proxy.cpp +++ b/services/timer/src/timer_proxy.cpp @@ -175,6 +175,16 @@ void TimerProxy::EraseAlarmItem( } } +int32_t TimerProxy::CountUidTimerMapByUid(int32_t uid) +{ + std::lock_guard lock(uidTimersMutex_); + auto it = uidTimersMap_.find(alarm->uid); + if (it == uidTimersMap_.end()) { + return 0; + } + return it->second.size(); +} + void TimerProxy::RecordUidTimerMap(const std::shared_ptr &alarm, const bool isRebatched) { if (isRebatched) { @@ -276,14 +286,15 @@ void TimerProxy::UpdateProxyWhenElapsedForProxyTimers(int32_t uid, int pid, TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d pid: %{public}d is already proxy", uid, pid); return; } - - std::lock_guard lockUidTimers(uidTimersMutex_); - std::vector timerList; - auto itUidTimersMap = uidTimersMap_.find(uid); - if (itUidTimersMap == uidTimersMap_.end()) { - TIME_HILOGD(TIME_MODULE_SERVICE, "uid: %{public}d in map not found", uid); - proxyTimers_[key] = timerList; - return; + { + std::lock_guard lockUidTimers(uidTimersMutex_); + std::vector timerList; + auto itUidTimersMap = uidTimersMap_.find(uid); + if (itUidTimersMap == uidTimersMap_.end()) { + TIME_HILOGD(TIME_MODULE_SERVICE, "uid: %{public}d in map not found", uid); + proxyTimers_[key] = timerList; + return; + } } for (auto itTimerInfo = itUidTimersMap->second.begin(); itTimerInfo!= itUidTimersMap->second.end(); @@ -315,11 +326,13 @@ bool TimerProxy::RestoreProxyWhenElapsed(const int uid, const int pid, return false; } - std::lock_guard lockPidTimers(uidTimersMutex_); - auto itTimer = uidTimersMap_.find(uid); - if (uidTimersMap_.find(uid) == uidTimersMap_.end()) { - TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d timer info not found, erase proxy map. ", uid); - return true; + { + std::lock_guard lockPidTimers(uidTimersMutex_); + auto itTimer = uidTimersMap_.find(uid); + if (uidTimersMap_.find(uid) == uidTimersMap_.end()) { + TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d timer info not found, erase proxy map. ", uid); + return true; + } } for (int elem : itProxy->second) { -- Gitee From b9bbd981cbc5928cedb6fdfe48c826cdd581a60f Mon Sep 17 00:00:00 2001 From: gaozhichao Date: Fri, 7 Feb 2025 17:38:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[fix]=20=E6=89=93=E7=82=B9=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaozhichao --- services/dfx/src/time_sysevent.cpp | 82 ++++++++++++++++------------ services/timer/src/timer_manager.cpp | 2 - 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/services/dfx/src/time_sysevent.cpp b/services/dfx/src/time_sysevent.cpp index eac2aa12..2ba74d92 100644 --- a/services/dfx/src/time_sysevent.cpp +++ b/services/dfx/src/time_sysevent.cpp @@ -15,6 +15,8 @@ #include "time_sysevent.h" +#include + #include "hisysevent.h" #include "time_hilog.h" #include "time_file_utils.h" @@ -24,6 +26,7 @@ namespace OHOS { namespace MiscServices { namespace { using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; +static const int COUNT_REPORT_ARRAY_LENGTH = 5; } // namespace std::string GetBundleOrProcessName() @@ -47,13 +50,13 @@ void StatisticReporter(int32_t size, std::shared_ptr timer) int64_t triggerTime = timer->whenElapsed.time_since_epoch().count(); auto interval = static_cast(timer->repeatInterval.count()); struct HiSysEventParam params[] = { - {"CALLER_PID", HISYSEVENT_INT32, {callerPid}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {callerUid}, 0}, - {"BUNDLE_OR_PROCESS_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, bundleOrProcessName.length()}, - {"TIMER_SIZE", HISYSEVENT_INT32, {size}, 0}, - {"TIMER_TYPE", HISYSEVENT_INT32, {type}, 0}, - {"TRIGGER_TIME", HISYSEVENT_INT64, {triggerTime}, 0}, - {"INTERVAL", HISYSEVENT_UINT64, {interval}, 0} + {"CALLER_PID", HISYSEVENT_INT32, {callerPid}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {callerUid}, 0}, + {"BUNDLE_OR_PROCESS_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"TIMER_SIZE", HISYSEVENT_INT32, {size}, 0}, + {"TIMER_TYPE", HISYSEVENT_INT32, {type}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {triggerTime}, 0}, + {"INTERVAL", HISYSEVENT_UINT64, {interval}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "MISC_TIME_STATISTIC_REPORT", HISYSEVENT_STATISTIC, params, sizeof(params)/sizeof(params[0])); @@ -68,18 +71,18 @@ void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std:: { std::string bundleOrProcessName = GetBundleOrProcessName(); struct HiSysEventParam params[] = { - {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {IPCSkeleton::GetCallingUid()}, 0}, - {"CALLER_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, bundleOrProcessName.length()}, - {"ORIGINAL_TIME", HISYSEVENT_STRING, {originTime.c_str()}, originTime.length()}, - {"SET_TIME", HISYSEVENT_STRING, {newTime.c_str()}, newTime.length()}, - {"NTP_TIME", HISYSEVENT_INT64, {ntpTime}, 0} + {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {IPCSkeleton::GetCallingUid()}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"ORIGINAL_TIME", HISYSEVENT_STRING, {.s = const_cast(originTime.c_str())}, 0}, + {"SET_TIME", HISYSEVENT_STRING, {.s = const_cast(newTime.c_str())}, 0}, + {"NTP_TIME", HISYSEVENT_INT64, {ntpTime}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIME", HISYSEVENT_BEHAVIOR, params, sizeof(params)/sizeof(params[0])); if (ret != 0) { TIME_HILOGE(TIME_MODULE_SERVICE, "TimeBehaviorReport failed! eventCode %{public}d, name:%{public}s," - "ret:%{public}d", eventCode, bundleOrProcessName.c_str(), ret); + "ret:%{public}d", eventCode, bundleOrProcessName.c_str(), ret); } } @@ -94,35 +97,44 @@ void TimerBehaviorReport(std::shared_ptr timer, bool isStart) auto bundleOrProcessName = timer->bundleName; auto interval = static_cast(timer->repeatInterval.count()); struct HiSysEventParam params[] = { - {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, - {"TIMER_ID", HISYSEVENT_UINT32, {timer->id}, 0}, - {"TRIGGER_TIME", HISYSEVENT_INT64, {timer->when.count()}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {timer->uid}, 0}, - {"CALLER_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, bundleOrProcessName.length()}, - {"INTERVAL", HISYSEVENT_UINT32, {interval}, 0} + {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, + {"TIMER_ID", HISYSEVENT_UINT32, {timer->id}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {timer->when.count()}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {timer->uid}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"INTERVAL", HISYSEVENT_UINT32, {interval}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIMER", HISYSEVENT_BEHAVIOR, params, sizeof(params)/sizeof(params[0])); if (ret != 0) { - TIME_HILOGE(TIME_MODULE_SERVICE, - "TimerBehaviorReport failed! eventCode %{public}d, name%{public}s,timerid %{public}d", eventCode, - bundleOrProcessName.c_str(), timer->id); + TIME_HILOGE(TIME_MODULE_SERVICE, "TimerBehaviorReport failed! eventCode:%{public}d," + "id:%{public}" PRIu64 " name:%{public}s", static_cast(eventCode), timer->id, + bundleOrProcessName.c_str()); } } void TimerCountStaticReporter(int count, int* uidArr, int* createTimerCountArr, int* startTimerCountArr) { struct HiSysEventParam params[] = { - {"TIMER_NUM", HISYSEVENT_INT32, {count}, 0}, - {"TOP_UID", HISYSEVENT_INT32_ARRAY, {uidArr}, 5}, - {"TOP_NUM", HISYSEVENT_INT32_ARRAY, {createTimerCountArr}, 5}, - {"TOP_STRAT_NUM", HISYSEVENT_INT32_ARRAY, {startTimerCountArr}, 5} + {"TIMER_NUM", HISYSEVENT_INT32, {count}, 0}, + {"TOP_UID", HISYSEVENT_INT32_ARRAY, {uidArr}, COUNT_REPORT_ARRAY_LENGTH}, + {"TOP_NUM", HISYSEVENT_INT32_ARRAY, {createTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH}, + {"TOP_STRAT_NUM", HISYSEVENT_INT32_ARRAY, {startTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH} }; int ret = OH_HiSysEvent_Write("TIME", "ALARM_COUNT", HISYSEVENT_STATISTIC, params, sizeof(params)/sizeof(params[0])); if (ret != 0) { + std::string uidStr = ""; + std::string createCountStr = ""; + std::string startCountStr = ""; + for (int i = 0; i < COUNT_REPORT_ARRAY_LENGTH; i++) { + uidStr = uidStr + std::to_string(uidArr[i]) + " "; + createCountStr = createCountStr + std::to_string(createTimerCountArr[i]) + " "; + startCountStr = startCountStr + std::to_string(startTimerCountArr[i]) + " "; + } TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed! count:%{public}d, uid:[%{public}s]," - "create count:[%{public}s], startcount:[%{public}s]", count, uidArr, createTimerCountArr, startTimerCountArr); + "create count:[%{public}s], startcount:[%{public}s]", count, uidStr.c_str(), createCountStr.c_str(), + startCountStr.c_str()); } } @@ -131,18 +143,18 @@ void TimeServiceFaultReporter(ReportEventCode eventCode, int errCode, std::strin int uid = IPCSkeleton::GetCallingUid(); std::string bundleOrProcessName = GetBundleOrProcessName(); struct HiSysEventParam params[] = { - {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, - {"ERR_CODE", HISYSEVENT_INT32, {errCode}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {uid}, 0}, - {"CALLER_NAME", HISYSEVENT_STRING, {bundleOrProcessName.c_str()}, bundleOrProcessName.length()}, - {"EXTRA", HISYSEVENT_STRING, {extraInfo.c_str()}, extraInfo.length()} + {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, + {"ERR_CODE", HISYSEVENT_INT32, {errCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {uid}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"EXTRA", HISYSEVENT_STRING, {.s = const_cast(extraInfo.c_str())}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "ALARM_COUNT", HISYSEVENT_STATISTIC, params, sizeof(params)/sizeof(params[0])); if (ret != 0) { TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed! eventCode:%{public}d errorcode:%{public}d" - "callname:%{public}s", eventCode, errCode, bundleOrProcessName.c_str()); + "callname:%{public}s", eventCode, errCode, bundleOrProcessName.c_str()); } } -} // namespace MiscServices+ +} // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index e4fb3b6c..ca9c676b 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -950,8 +950,6 @@ void TimerManager::DeliverTimersLocked(const std::vectorwakeup) { #ifdef POWER_MANAGER_ENABLE - TIME_HILOGD(TIME_MODULE_SERVICE, "id: %{public}" PRId64 ", uid: %{public}d bundleName: %{public}s", - timer->id, timer->uid, timer->bundleName.c_str()); AddRunningLock(USE_LOCK_ONE_SEC_IN_NANO); #endif StatisticReporter(wakeupNums, timer); -- Gitee From ad2d05a2200931a55d7410e3eaf25a2625255864 Mon Sep 17 00:00:00 2001 From: gaozhichao Date: Sat, 8 Feb 2025 15:36:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[fix]=20=E6=89=93=E7=82=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaozhichao --- services/dfx/include/time_sysevent.h | 4 +- services/dfx/src/time_sysevent.cpp | 58 +++++++++++++-------------- services/time/src/ntp_update_time.cpp | 1 - services/time/src/sntp_client.cpp | 5 ++- services/time_system_ability.cpp | 3 +- services/timer/src/timer_manager.cpp | 31 +++++++------- services/timer/src/timer_proxy.cpp | 28 +++++-------- 7 files changed, 61 insertions(+), 69 deletions(-) diff --git a/services/dfx/include/time_sysevent.h b/services/dfx/include/time_sysevent.h index 49c79b3c..6b09f84d 100644 --- a/services/dfx/include/time_sysevent.h +++ b/services/dfx/include/time_sysevent.h @@ -26,6 +26,7 @@ constexpr int32_t TRIGGER_TIMER_OFFSET = 0x00000100; constexpr int32_t TIMER_FAULT_OFFSET = 0x00000200; constexpr int32_t MODIFY_TIME_OFFSET = 0x01000000; constexpr int32_t EXACT_OFFSET = 4; +static const int COUNT_REPORT_ARRAY_LENGTH = 5; enum ReportEventCode : int32_t { RTC_WAKEUP_EXACT_TIMER_START = START_TIMER_OFFSET, @@ -52,7 +53,8 @@ enum ReportEventCode : int32_t { void StatisticReporter(int32_t size, std::shared_ptr timer); void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std::string newTime, int64_t ntpTime); void TimerBehaviorReport(std::shared_ptr timer, bool isStart); -void TimerCountStaticReporter(int count, int* uidArr, int* createTimerCountArr, int* startTimerCountArr); +void TimerCountStaticReporter(int count, int (&uidArr)[COUNT_REPORT_ARRAY_LENGTH], + int (&createTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH], int (&startTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH]); void TimeServiceFaultReporter(ReportEventCode eventCode, int errCode, std::string extraInfo); } // namespace MiscServices } // namespace OHOS diff --git a/services/dfx/src/time_sysevent.cpp b/services/dfx/src/time_sysevent.cpp index 2ba74d92..e414b5ba 100644 --- a/services/dfx/src/time_sysevent.cpp +++ b/services/dfx/src/time_sysevent.cpp @@ -26,7 +26,6 @@ namespace OHOS { namespace MiscServices { namespace { using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; -static const int COUNT_REPORT_ARRAY_LENGTH = 5; } // namespace std::string GetBundleOrProcessName() @@ -50,13 +49,13 @@ void StatisticReporter(int32_t size, std::shared_ptr timer) int64_t triggerTime = timer->whenElapsed.time_since_epoch().count(); auto interval = static_cast(timer->repeatInterval.count()); struct HiSysEventParam params[] = { - {"CALLER_PID", HISYSEVENT_INT32, {callerPid}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {callerUid}, 0}, + {"CALLER_PID", HISYSEVENT_INT32, {.i32 = callerPid}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = callerUid}, 0}, {"BUNDLE_OR_PROCESS_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, - {"TIMER_SIZE", HISYSEVENT_INT32, {size}, 0}, - {"TIMER_TYPE", HISYSEVENT_INT32, {type}, 0}, - {"TRIGGER_TIME", HISYSEVENT_INT64, {triggerTime}, 0}, - {"INTERVAL", HISYSEVENT_UINT64, {interval}, 0} + {"TIMER_SIZE", HISYSEVENT_INT32, {.i32 = size}, 0}, + {"TIMER_TYPE", HISYSEVENT_INT32, {.i32 = type}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {.i64 = triggerTime}, 0}, + {"INTERVAL", HISYSEVENT_UINT64, {.ui64 = interval}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "MISC_TIME_STATISTIC_REPORT", HISYSEVENT_STATISTIC, params, sizeof(params)/sizeof(params[0])); @@ -71,12 +70,12 @@ void TimeBehaviorReport(ReportEventCode eventCode, std::string originTime, std:: { std::string bundleOrProcessName = GetBundleOrProcessName(); struct HiSysEventParam params[] = { - {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {IPCSkeleton::GetCallingUid()}, 0}, - {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, - {"ORIGINAL_TIME", HISYSEVENT_STRING, {.s = const_cast(originTime.c_str())}, 0}, - {"SET_TIME", HISYSEVENT_STRING, {.s = const_cast(newTime.c_str())}, 0}, - {"NTP_TIME", HISYSEVENT_INT64, {ntpTime}, 0} + {"EVENT_CODE", HISYSEVENT_INT32, {.i32 = eventCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = IPCSkeleton::GetCallingUid()}, 0}, + {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, + {"ORIGINAL_TIME", HISYSEVENT_STRING, {.s = const_cast(originTime.c_str())}, 0}, + {"SET_TIME", HISYSEVENT_STRING, {.s = const_cast(newTime.c_str())}, 0}, + {"NTP_TIME", HISYSEVENT_INT64, {.i64 = ntpTime}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIME", HISYSEVENT_BEHAVIOR, params, sizeof(params)/sizeof(params[0])); @@ -97,12 +96,12 @@ void TimerBehaviorReport(std::shared_ptr timer, bool isStart) auto bundleOrProcessName = timer->bundleName; auto interval = static_cast(timer->repeatInterval.count()); struct HiSysEventParam params[] = { - {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, - {"TIMER_ID", HISYSEVENT_UINT32, {timer->id}, 0}, - {"TRIGGER_TIME", HISYSEVENT_INT64, {timer->when.count()}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {timer->uid}, 0}, + {"EVENT_CODE", HISYSEVENT_INT32, {.i32 = eventCode}, 0}, + {"TIMER_ID", HISYSEVENT_UINT32, {.ui32 = timer->id}, 0}, + {"TRIGGER_TIME", HISYSEVENT_INT64, {.i64 = timer->when.count()}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = timer->uid}, 0}, {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, - {"INTERVAL", HISYSEVENT_UINT32, {interval}, 0} + {"INTERVAL", HISYSEVENT_UINT32, {.ui32 =interval}, 0} }; int ret = OH_HiSysEvent_Write("TIME", "BEHAVIOR_TIMER", HISYSEVENT_BEHAVIOR, params, sizeof(params)/sizeof(params[0])); @@ -113,13 +112,14 @@ void TimerBehaviorReport(std::shared_ptr timer, bool isStart) } } -void TimerCountStaticReporter(int count, int* uidArr, int* createTimerCountArr, int* startTimerCountArr) +void TimerCountStaticReporter(int count, int (&uidArr)[COUNT_REPORT_ARRAY_LENGTH], + int (&createTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH], int (&startTimerCountArr)[COUNT_REPORT_ARRAY_LENGTH]) { struct HiSysEventParam params[] = { - {"TIMER_NUM", HISYSEVENT_INT32, {count}, 0}, - {"TOP_UID", HISYSEVENT_INT32_ARRAY, {uidArr}, COUNT_REPORT_ARRAY_LENGTH}, - {"TOP_NUM", HISYSEVENT_INT32_ARRAY, {createTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH}, - {"TOP_STRAT_NUM", HISYSEVENT_INT32_ARRAY, {startTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH} + {"TIMER_NUM", HISYSEVENT_INT32, {.i32 = count}, 0}, + {"TOP_UID", HISYSEVENT_INT32_ARRAY, {.array = uidArr}, COUNT_REPORT_ARRAY_LENGTH}, + {"TOP_NUM", HISYSEVENT_INT32_ARRAY, {.array = createTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH}, + {"TOP_STRAT_NUM", HISYSEVENT_INT32_ARRAY, {.array = startTimerCountArr}, COUNT_REPORT_ARRAY_LENGTH} }; int ret = OH_HiSysEvent_Write("TIME", "ALARM_COUNT", HISYSEVENT_STATISTIC, params, sizeof(params)/sizeof(params[0])); @@ -132,7 +132,7 @@ void TimerCountStaticReporter(int count, int* uidArr, int* createTimerCountArr, createCountStr = createCountStr + std::to_string(createTimerCountArr[i]) + " "; startCountStr = startCountStr + std::to_string(startTimerCountArr[i]) + " "; } - TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed! count:%{public}d, uid:[%{public}s]," + TIME_HILOGE(TIME_MODULE_SERVICE, "TimerCountStaticReporter failed! count:%{public}d, uid:[%{public}s]," "create count:[%{public}s], startcount:[%{public}s]", count, uidStr.c_str(), createCountStr.c_str(), startCountStr.c_str()); } @@ -143,16 +143,16 @@ void TimeServiceFaultReporter(ReportEventCode eventCode, int errCode, std::strin int uid = IPCSkeleton::GetCallingUid(); std::string bundleOrProcessName = GetBundleOrProcessName(); struct HiSysEventParam params[] = { - {"EVENT_CODE", HISYSEVENT_INT32, {eventCode}, 0}, - {"ERR_CODE", HISYSEVENT_INT32, {errCode}, 0}, - {"CALLER_UID", HISYSEVENT_INT32, {uid}, 0}, + {"EVENT_CODE", HISYSEVENT_INT32, {.i32 = eventCode}, 0}, + {"ERR_CODE", HISYSEVENT_INT32, {.i32 = errCode}, 0}, + {"CALLER_UID", HISYSEVENT_INT32, {.i32 = uid}, 0}, {"CALLER_NAME", HISYSEVENT_STRING, {.s = const_cast(bundleOrProcessName.c_str())}, 0}, {"EXTRA", HISYSEVENT_STRING, {.s = const_cast(extraInfo.c_str())}, 0} }; - int ret = OH_HiSysEvent_Write("TIME", "ALARM_COUNT", HISYSEVENT_STATISTIC, + int ret = OH_HiSysEvent_Write("TIME", "FUNC_FAULT", HISYSEVENT_FAULT, params, sizeof(params)/sizeof(params[0])); if (ret != 0) { - TIME_HILOGE(TIME_MODULE_SERVICE, "hisysevent Statistic failed! eventCode:%{public}d errorcode:%{public}d" + TIME_HILOGE(TIME_MODULE_SERVICE, "TimeServiceFaultReporter failed! eventCode:%{public}d errorcode:%{public}d" "callname:%{public}s", eventCode, errCode, bundleOrProcessName.c_str()); } } diff --git a/services/time/src/ntp_update_time.cpp b/services/time/src/ntp_update_time.cpp index 5242c92a..e483c3b8 100644 --- a/services/time/src/ntp_update_time.cpp +++ b/services/time/src/ntp_update_time.cpp @@ -26,7 +26,6 @@ #include "parameters.h" #include "time_common.h" #include "time_system_ability.h" -#include "time_sysevent.h" using namespace std::chrono; diff --git a/services/time/src/sntp_client.cpp b/services/time/src/sntp_client.cpp index f887cc6a..e6ac5df9 100644 --- a/services/time/src/sntp_client.cpp +++ b/services/time/src/sntp_client.cpp @@ -274,8 +274,9 @@ bool SNTPClient::ReceivedMessage(char *buffer) "_receiveClient:%{public}s", std::to_string(_originClient).c_str(), std::to_string(_receiveServer).c_str(), std::to_string(_transmitServer).c_str(), std::to_string(_receiveClient).c_str()); - TimeBehaviorReport(ReportEventCode::NTP_REFRESH, std::to_string(_originClient) + std::to_string(_receiveClient), - std::to_string(_transmitServer) + std::to_string(_receiveClient), mNtpTime); + TimeBehaviorReport(ReportEventCode::NTP_REFRESH, + std::to_string(_originClient) + "|" + std::to_string(_receiveClient), + std::to_string(_transmitServer) + "|" + std::to_string(_receiveServer), mNtpTime); return true; } diff --git a/services/time_system_ability.cpp b/services/time_system_ability.cpp index f7260094..5faac115 100644 --- a/services/time_system_ability.cpp +++ b/services/time_system_ability.cpp @@ -563,8 +563,7 @@ bool TimeSystemAbility::SetRealTime(int64_t time) TimeServiceNotify::GetInstance().PublishTimeChangeEvents(currentTime); } TimeTickNotify::GetInstance().Callback(); - int64_t curtime = 0; - TimeSystemAbility::GetNtpTimeMs(curtime); + int64_t curtime = NtpTrustedTime::GetInstance().CurrentTimeMillis(); TimeBehaviorReport(ReportEventCode::SET_TIME, std::to_string(beforeTime), std::to_string(time), curtime); return true; } diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 3f2ab5c1..49a89e7e 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -355,28 +355,25 @@ void TimerManager::ShowTimerCountByUid(int count) { std::string uidStr = ""; std::string countStr = ""; - int* uidArr = new int[TIMER_COUNT_TOP_NUM]; - int* createTimerCountArr = new int[TIMER_COUNT_TOP_NUM]; - int* startTimerCountArr = new int[TIMER_COUNT_TOP_NUM]; + int uidArr[TIMER_COUNT_TOP_NUM]; + int createTimerCountArr[TIMER_COUNT_TOP_NUM]; + int startTimerCountArr[TIMER_COUNT_TOP_NUM]; auto size = static_cast(timerCount_.size()); std::sort(timerCount_.begin(), timerCount_.end(), [](const std::pair& a, const std::pair& b) { return a.second > b.second; }); auto limitedSize = (size > TIMER_COUNT_TOP_NUM) ? TIMER_COUNT_TOP_NUM : size; - for (int i = 0; i < TIMER_COUNT_TOP_NUM; i++) { - if (i < limitedSize) { - int uid = timerCount_[i].first; - int createTimerCount = timerCount_[i].second; - uidStr = uidStr + std::to_string(uid) + " "; - countStr = countStr + std::to_string(createTimerCount) + " "; - uidArr[i] = uid; - createTimerCountArr[i] = createTimerCount; - startTimerCountArr[i] = TimerProxy::GetInstance().CountUidTimerMapByUid(uid); - } - uidArr[i] = 0; - createTimerCountArr[i] = 0; - startTimerCountArr[i] = 0; + int index = 0; + for (auto it = timerCount_.begin(); it != timerCount_.begin() + limitedSize; ++it) { + int uid = it->first; + int createTimerCount = it->second; + uidStr = uidStr + std::to_string(uid) + " "; + countStr = countStr + std::to_string(createTimerCount) + " "; + uidArr[index] = uid; + createTimerCountArr[index] = createTimerCount; + startTimerCountArr[index] = TimerProxy::GetInstance().CountUidTimerMapByUid(uid); + ++index; } TimerCountStaticReporter(count, uidArr, createTimerCountArr, startTimerCountArr); TIME_HILOGI(TIME_MODULE_SERVICE, "Top uid:[%{public}s], nums:[%{public}s]", uidStr.c_str(), countStr.c_str()); @@ -982,11 +979,11 @@ void TimerManager::DeliverTimersLocked(const std::vectorwakeup;}); for (const auto &timer : triggerList) { - TimerBehaviorReport(timer, false); if (timer->wakeup) { #ifdef POWER_MANAGER_ENABLE AddRunningLock(USE_LOCK_ONE_SEC_IN_NANO); #endif + TimerBehaviorReport(timer, false); StatisticReporter(wakeupNums, timer); } if (timer->callback) { diff --git a/services/timer/src/timer_proxy.cpp b/services/timer/src/timer_proxy.cpp index 42c5c17b..c123dd40 100644 --- a/services/timer/src/timer_proxy.cpp +++ b/services/timer/src/timer_proxy.cpp @@ -291,16 +291,13 @@ void TimerProxy::UpdateProxyWhenElapsedForProxyTimers(int32_t uid, int pid, TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d pid: %{public}d is already proxy", uid, pid); return; } - std::unordered_map>>::iterator itUidTimersMap; + std::lock_guard lockUidTimers(uidTimersMutex_); std::vector timerList; - { - std::lock_guard lockUidTimers(uidTimersMutex_); - itUidTimersMap = uidTimersMap_.find(uid); - if (itUidTimersMap == uidTimersMap_.end()) { - TIME_HILOGD(TIME_MODULE_SERVICE, "uid: %{public}d in map not found", uid); - proxyTimers_[key] = timerList; - return; - } + auto itUidTimersMap = uidTimersMap_.find(uid); + if (itUidTimersMap == uidTimersMap_.end()) { + TIME_HILOGD(TIME_MODULE_SERVICE, "uid: %{public}d in map not found", uid); + proxyTimers_[key] = timerList; + return; } for (auto itTimerInfo = itUidTimersMap->second.begin(); itTimerInfo!= itUidTimersMap->second.end(); @@ -331,14 +328,11 @@ bool TimerProxy::RestoreProxyWhenElapsed(const int uid, const int pid, TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d pid:%{public}d not in proxy.", uid, pid); return false; } - std::unordered_map>>::iterator itTimer; - { - std::lock_guard lockPidTimers(uidTimersMutex_); - itTimer = uidTimersMap_.find(uid); - if (uidTimersMap_.find(uid) == uidTimersMap_.end()) { - TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d timer info not found, erase proxy map. ", uid); - return true; - } + std::lock_guard lockPidTimers(uidTimersMutex_); + auto itTimer = uidTimersMap_.find(uid); + if (uidTimersMap_.find(uid) == uidTimersMap_.end()) { + TIME_HILOGD(TIME_MODULE_SERVICE, "uid:%{public}d timer info not found, erase proxy map. ", uid); + return true; } for (auto elem : itProxy->second) { -- Gitee