From b50681fb66e903b8c2b7fdd07b9a9255cb9e6454 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 13:06:07 +0800 Subject: [PATCH 1/6] Signed-off-by: GlaryCastle Changes to be committed: modified: bundle.json new file: hisysevent.yaml modified: services/BUILD.gn new file: services/dfx/include/time_cmd_dispatcher.h new file: services/dfx/include/time_cmd_parse.h new file: services/dfx/include/time_sysevent.h new file: services/dfx/include/time_trace.h new file: services/dfx/src/time_cmd_dispatcher.cpp new file: services/dfx/src/time_cmd_parse.cpp new file: services/dfx/src/time_sysevent.cpp new file: services/dfx/src/time_trace.cpp modified: services/time_manager/include/time_service.h modified: services/time_manager/src/time_service.cpp modified: services/timer/include/timer_manager.h modified: services/timer/src/timer_manager.cpp --- bundle.json | 3 + hisysevent.yaml | 22 ++++ services/BUILD.gn | 8 ++ services/dfx/include/time_cmd_dispatcher.h | 40 +++++++ services/dfx/include/time_cmd_parse.h | 37 +++++++ services/dfx/include/time_sysevent.h | 26 +++++ services/dfx/include/time_trace.h | 32 ++++++ services/dfx/src/time_cmd_dispatcher.cpp | 66 +++++++++++ services/dfx/src/time_cmd_parse.cpp | 51 +++++++++ services/dfx/src/time_sysevent.cpp | 40 +++++++ services/dfx/src/time_trace.cpp | 40 +++++++ services/time_manager/include/time_service.h | 9 ++ services/time_manager/src/time_service.cpp | 109 ++++++++++++++++++- services/timer/include/timer_manager.h | 3 + services/timer/src/timer_manager.cpp | 53 +++++++++ 15 files changed, 537 insertions(+), 2 deletions(-) create mode 100644 hisysevent.yaml create mode 100644 services/dfx/include/time_cmd_dispatcher.h create mode 100644 services/dfx/include/time_cmd_parse.h create mode 100644 services/dfx/include/time_sysevent.h create mode 100644 services/dfx/include/time_trace.h create mode 100644 services/dfx/src/time_cmd_dispatcher.cpp create mode 100644 services/dfx/src/time_cmd_parse.cpp create mode 100644 services/dfx/src/time_sysevent.cpp create mode 100644 services/dfx/src/time_trace.cpp diff --git a/bundle.json b/bundle.json index 7de1b69..e596651 100644 --- a/bundle.json +++ b/bundle.json @@ -17,6 +17,9 @@ ], "features": [ ], + "hisysevent_config": [ + "//base/miscservices/time/hisysevent.yaml" + ], "adapted_system_type": [ "standard" ], diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 0000000..b094556 --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2021-2022 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +domain: TIME + +MISC_TIME_STATISTIC_REPORT: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStatus, desc: trigger timer report} + CALLER_PID: {type: INT32, desc: the process id} + CALLER_UID: {type: INT32, desc: the user id} + TIMER_TYPE: {type: INT32,desc: the timer type} + TRIGGER_TIME: {type:INT64,desc the trigger time} + INTERVAL: {type: INT32, desc: the trigger time} \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 45e5e0e..f125d03 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -20,6 +20,7 @@ config("time_service_config") { "../utils/native/include", "time_manager/include", "timer/include", + "dfx/include", "//utils/system/safwk/native/include", "//third_party/json/include", "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", @@ -58,6 +59,10 @@ ohos_shared_library("time_service") { "timer/src/timer_handler.cpp", "timer/src/timer_info.cpp", "timer/src/timer_manager.cpp", + "dfx/src/time_sysevent.cpp", + "dfx/src/time_trace.cpp", + "dfx/src/time_cmd_parse.cpp", + "dfx/src/time_cmd_dispatcher.cpp", ] deps = [ @@ -73,6 +78,9 @@ ohos_shared_library("time_service") { "ability_runtime:wantagent_innerkits", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "relational_store:native_appdatafwk", diff --git a/services/dfx/include/time_cmd_dispatcher.h b/services/dfx/include/time_cmd_dispatcher.h new file mode 100644 index 0000000..c653623 --- /dev/null +++ b/services/dfx/include/time_cmd_dispatcher.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022-2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIME_CMD_DISPATCHER_H +#define TIME_CMD_DISPATCHER_H + +#include +#include +#include + +#include "time_cmd_parse.h" + +namespace OHOS { +namespace MiscServices { + +class TimeCmdDispatcher { +public: + static TimeCmdDispatcher &GetInstance(); + void RegisterCommand(std::shared_ptr &cmd); + bool Dispatch(int fd, const std::vector &args); + std::string getCmdTitle(int fd, const std::vector &args); + +private: + std::map> cmdHandler; +}; +} // namespace MiscServices +} // namespace OHOS +#endif //TIME_CMD_DISPATCHER_H \ No newline at end of file diff --git a/services/dfx/include/time_cmd_parse.h b/services/dfx/include/time_cmd_parse.h new file mode 100644 index 0000000..db48880 --- /dev/null +++ b/services/dfx/include/time_cmd_parse.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022-2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIME_CMDPARSE_H +#define TIME_CMDPARSE_H + +#include +#include +#include + +class TimeCmdParse { +public: + using Action = std::function &input)>; + TimeCmdParse(const std::vector &argsFormat, const std::string &strHelp, const Action &action); + std::string ShowHelp(); + void DoAction(int fd, const std::vector &input); + std::string GetOption(); + std::string GetFormat(); + +private: + std::vector format; + std::string help; + Action action; +}; +#endif //TIME_CMDPARSE_H \ No newline at end of file diff --git a/services/dfx/include/time_sysevent.h b/services/dfx/include/time_sysevent.h new file mode 100644 index 0000000..c9803b8 --- /dev/null +++ b/services/dfx/include/time_sysevent.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIME_SYSEVENT_H +#define TIME_SYSEVENT_H + +#include + +namespace OHOS { +namespace MiscServices { +void StatisticReporter(int32_t callerPid, int32_t callerUid, int32_t type, int64_t triggerTime, uint64_t interval); +} // namespace MiscServices +} // namespace OHOS +#endif // TIME_SYSEVENT_H diff --git a/services/dfx/include/time_trace.h b/services/dfx/include/time_trace.h new file mode 100644 index 0000000..863bb5a --- /dev/null +++ b/services/dfx/include/time_trace.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIME_TRACE_H +#define TIME_TRACE_H + +#include + +namespace OHOS { +namespace MiscServices { +void InitHiTrace(); +void ValueTrace(const std::string &name, int64_t count); +class TimeTrace { +public: + explicit TimeTrace(const std::string &value); + virtual ~TimeTrace(); +}; +} // namespace MiscServices +} // namespace OHOS +#endif // TIME_TRACE_H diff --git a/services/dfx/src/time_cmd_dispatcher.cpp b/services/dfx/src/time_cmd_dispatcher.cpp new file mode 100644 index 0000000..8f4a2f6 --- /dev/null +++ b/services/dfx/src/time_cmd_dispatcher.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022-2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "time_cmd_dispatcher.h" +#include "time_hilog_wreapper.h" + +namespace OHOS { +namespace MiscServices { + +bool TimeCmdDispatcher::Dispatch(int fd, const std::vector &args) +{ + if (args.empty() || args.at(0) == "-h") { + dprintf(fd, "\n%-15s: %-20s", "Option", "Description"); + for (auto &[key, handler] : cmdHandler) { + dprintf(fd, "\n%-15s: %-20s", handler->GetFormat().c_str(), handler->ShowHelp().c_str()); + } + return false; + } + std::string cmdTitle = getCmdTitle(fd, args); + auto handler = cmdHandler.find(cmdTitle); + if (handler != cmdHandler.end()) { + handler->second->DoAction(fd, args); + return true; + } + return false; +} + +void TimeCmdDispatcher::RegisterCommand(std::shared_ptr &cmd) +{ + cmdHandler.insert(std::make_pair(cmd->GetOption(), cmd)); +} + +std::string TimeCmdDispatcher::getCmdTitle(int fd, const std::vector &args) +{ + std::string formatTitle; + for (unsigned long i = 0; i < args.size() - 1; i++) { + formatTitle += args.at(i); + formatTitle += " "; + } + return formatTitle.substr(0, formatTitle.length() - 1); + dprintf(fd, "TimeCmdDispatcher::getCmdTitle formatTitle:%s.\n", formatTitle.c_str()); +} + +TimeCmdDispatcher &TimeCmdDispatcher::GetInstance() +{ + static TimeCmdDispatcher instance; + return instance; +} + +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/dfx/src/time_cmd_parse.cpp b/services/dfx/src/time_cmd_parse.cpp new file mode 100644 index 0000000..705f313 --- /dev/null +++ b/services/dfx/src/time_cmd_parse.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022-2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "time_cmd_parse.h" + +TimeCmdParse::TimeCmdParse( + const std::vector &argsFormat, const std::string &strHelp, const TimeCmdParse::Action &action) + : format(argsFormat), help(strHelp), action(action) +{ +} +std::string TimeCmdParse::ShowHelp() +{ + return help; +} + +void TimeCmdParse::DoAction(int fd, const std::vector &input) +{ + action(fd, input); +} + +std::string TimeCmdParse::GetOption() +{ + std::string formatTitle; + for (unsigned long i = 0; i < format.size() - 1; i++) { + formatTitle += format.at(i); + formatTitle += " "; + } + return formatTitle.substr(0, formatTitle.length() - 1); +} + +std::string TimeCmdParse::GetFormat() +{ + std::string formatStr; + for (auto &seg : format) { + formatStr += seg; + formatStr += " "; + } + return formatStr; +} \ No newline at end of file diff --git a/services/dfx/src/time_sysevent.cpp b/services/dfx/src/time_sysevent.cpp new file mode 100644 index 0000000..94f18a7 --- /dev/null +++ b/services/dfx/src/time_sysevent.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "time_sysevent.h" + +#include "hisysevent.h" +#include "time_hilog_wreapper.h" + +namespace OHOS { +namespace MiscServices { +namespace { +using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; +const std::string DOMAIN_STR = std::string(HiSysEventNameSpace::Domain::TIME); +} // namespace + +void StatisticReporter(int32_t callerPid, int32_t callerUid, int32_t type, int64_t triggerTime, uint64_t interval) +{ + int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "MISC_TIME_STATISTIC_REPORT", + HiSysEventNameSpace::EventType::STATISTIC, "CALLER_PID", callerPid, "CALLER_UID", callerUid, "TIMER_TYPE", + type, "TRIGGER_TIME", triggerTime, "INTERVAL", interval); + 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 +} // namespace OHOS diff --git a/services/dfx/src/time_trace.cpp b/services/dfx/src/time_trace.cpp new file mode 100644 index 0000000..2d599f7 --- /dev/null +++ b/services/dfx/src/time_trace.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "time_trace.h" + +#include "hitrace_meter.h" + +namespace OHOS { +namespace MiscServices { +void InitHiTrace() +{ + UpdateTraceLabel(); +} + +void ValueTrace(const std::string &name, int64_t count) +{ + CountTrace(HITRACE_TAG_MISC, name, count); +} +TimeTrace::TimeTrace(const std::string &value) +{ + StartTrace(HITRACE_TAG_MISC, value); +} + +TimeTrace::~TimeTrace() +{ + FinishTrace(HITRACE_TAG_MISC); +} +} // namespace MiscServices +} // namespace OHOS diff --git a/services/time_manager/include/time_service.h b/services/time_manager/include/time_service.h index 8d6ba68..adc6ce3 100644 --- a/services/time_manager/include/time_service.h +++ b/services/time_manager/include/time_service.h @@ -27,6 +27,9 @@ #include "event_handler.h" #include "time.h" #include "securec.h" +#include "time_cmd_dispatcher.h" +#include "time_cmd_parse.h" +#include "time_sysevent.h" namespace OHOS { namespace MiscServices { @@ -65,6 +68,12 @@ public: void NetworkTimeStatusOn() override; bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) override; bool ResetAllProxy() override; + int Dump(int fd, const std::vector &args) override; + void DumpAllTimeInfo(int fd, const std::vector &input); + void DumpTimerInfo(int fd, const std::vector &input); + void DumpTimerInfoById(int fd, const std::vector &input); + void DumpTimerTriggerById(int fd, const std::vector &input); + void InitDumpCmd(); protected: void OnStart() override; diff --git a/services/time_manager/src/time_service.cpp b/services/time_manager/src/time_service.cpp index 60167d8..65671d4 100644 --- a/services/time_manager/src/time_service.cpp +++ b/services/time_manager/src/time_service.cpp @@ -90,6 +90,28 @@ sptr TimeService::GetInstance() return instance_; } +void TimeService::InitDumpCmd() +{ + auto cmdTime = std::make_shared(std::vector({ "-time" }), + "dump current time info,include localtime,timezone info", + [this](int fd, const std::vector &input) { DumpAllTimeInfo(fd, input); }); + TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTime); + + auto cmdTimerAll = std::make_shared(std::vector({ "-timer", "-a" }), + "dump all timer info", [this](int fd, const std::vector &input) { DumpTimerInfo(fd, input); }); + TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTimerAll); + + auto cmdTimerInfo = std::make_shared(std::vector({ "-timer", "-i", "[n]" }), + "dump the timer info with timer id", + [this](int fd, const std::vector &input) { DumpTimerInfoById(fd, input); }); + TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTimerInfo); + + auto cmdTimerTrigger = std::make_shared(std::vector({ "-timer", "-s", "[n]" }), + "dump current time info,include localtime,timezone info", + [this](int fd, const std::vector &input) { DumpTimerTriggerById(fd, input); }); + TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTimerTrigger); +} + void TimeService::OnStart() { TIME_HILOGI(TIME_MODULE_SERVICE, " TimeService OnStart."); @@ -110,7 +132,7 @@ void TimeService::OnStart() TIME_HILOGE(TIME_MODULE_SERVICE, "Init failed. Try again 10s later."); return; } - + InitDumpCmd(); TIME_HILOGI(TIME_MODULE_SERVICE, "Start TimeService success."); return; } @@ -222,7 +244,9 @@ uint64_t TimeService::CreateTimer(int32_t type, bool repeat, uint64_t interval, auto callbackFunc = [timerCallback](uint64_t id) { timerCallback->NotifyTimer(id); }; - + int64_t triggerTime = 0; + GetWallTimeMs(triggerTime); + StatisticReporter(IPCSkeleton::GetCallingPid(), uid, type, triggerTime, interval); if (timerManagerHandler_ == nullptr) { TIME_HILOGE(TIME_MODULE_SERVICE, "Timer manager nullptr."); timerManagerHandler_ = TimerManager::Create(); @@ -335,6 +359,87 @@ int32_t TimeService::SetTime(const int64_t time) return ERR_OK; } +int TimeService::Dump(int fd, const std::vector &args) +{ + int uid = static_cast(IPCSkeleton::GetCallingUid()); + const int maxUid = 10000; + if (uid > maxUid) { + return E_TIME_DEAL_FAILED; + } + + std::vector argsStr; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + + TimeCmdDispatcher::GetInstance().Dispatch(fd, argsStr); + return ERR_OK; +} + +void TimeService::DumpAllTimeInfo(int fd, const std::vector &input) +{ + dprintf(fd, "\n - dump all time info :\n"); + struct timespec ts; + struct tm timestr; + char date_time[64]; + if (GetTimeByClockid(CLOCK_BOOTTIME, ts)) { + strftime(date_time, sizeof(date_time), "%Y-%m-%d %H:%M:%S", localtime_r(&ts.tv_sec, ×tr)); + dprintf(fd, " * date time = %s\n", date_time); + } else { + dprintf(fd, " * dump date time error.\n"); + } + dprintf(fd, " - dump the time Zone:\n"); + std::string timeZone = ""; + int32_t bRet = GetTimeZone(timeZone); + if (bRet == ERR_OK) { + dprintf(fd, " * time zone = %s\n", timeZone.c_str()); + } else { + dprintf(fd, " * dump time zone error,is %s\n", timeZone.c_str()); + } +} + +void TimeService::DumpTimerInfo(int fd, const std::vector &input) +{ + dprintf(fd, "\n - dump all timer info :\n"); + if (timerManagerHandler_ == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Timer manager nullptr."); + timerManagerHandler_ = TimerManager::Create(); + if (timerManagerHandler_ == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Redo Timer manager Init Failed."); + return; + } + } + timerManagerHandler_->ShowtimerEntryMap(fd); +} + +void TimeService::DumpTimerInfoById(int fd, const std::vector &input) +{ + dprintf(fd, "\n - dump the timer info with timer id:\n"); + if (timerManagerHandler_ == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Timer manager nullptr."); + timerManagerHandler_ = TimerManager::Create(); + if (timerManagerHandler_ == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Redo Timer manager Init Failed."); + return; + } + } + timerManagerHandler_->ShowTimerEntryById(fd, std::atoi(input.at(2).c_str())); +} + +void TimeService::DumpTimerTriggerById(int fd, const std::vector &input) +{ + dprintf(fd, "\n - dump timer trigger statics with timer id:\n"); + if (timerManagerHandler_ == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Timer manager nullptr."); + timerManagerHandler_ = TimerManager::Create(); + if (timerManagerHandler_ == nullptr) { + TIME_HILOGE(TIME_MODULE_SERVICE, "Redo Timer manager Init Failed."); + return; + } + } + timerManagerHandler_->ShowTimerTriggerById(fd, std::atoi(input.at(2).c_str())); +} + int TimeService::set_rtc_time(time_t sec) { struct rtc_time rtc {}; diff --git a/services/timer/include/timer_manager.h b/services/timer/include/timer_manager.h index d3c1a51..09fbc64 100644 --- a/services/timer/include/timer_manager.h +++ b/services/timer/include/timer_manager.h @@ -43,6 +43,9 @@ public: bool DestroyTimer(uint64_t timerNumber) override; bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) override; bool ResetAllProxy() override; + bool ShowtimerEntryMap(int fd); + bool ShowTimerEntryById(int fd, uint64_t timerId); + bool ShowTimerTriggerById(int fd, uint64_t timerId); ~TimerManager() override; private: diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 1253445..90f7e4d 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -669,5 +669,58 @@ steady_clock::time_point MaxTriggerTime(steady_clock::time_point now, } return triggerAtTime + milliseconds(static_cast(BATCH_WINDOW_COE * futurity.count())); } + +bool TimerManager::ShowtimerEntryMap(int fd) +{ + TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + std::lock_guard lock(entryMapMutex_); + std::map>::iterator iter = timerEntryMap_.begin(); + for (; iter != timerEntryMap_.end(); iter++) { + dprintf(fd, " - dump timer number = %d\n", iter->first); + dprintf(fd, " * timer id = %d\n", iter->second->id); + dprintf(fd, " * timer type = %d\n", iter->second->type); + dprintf(fd, " * timer window Length = %d\n", iter->second->windowLength); + dprintf(fd, " * timer interval = %d\n", iter->second->flag); + dprintf(fd, " * timer uid = %d\n\n", iter->second->uid); + } + TIME_HILOGD(TIME_MODULE_SERVICE, "end."); + return true; +} + +bool TimerManager::ShowTimerEntryById(int fd, uint64_t timerId) +{ + TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + std::lock_guard lock(entryMapMutex_); + std::map>::iterator iter = timerEntryMap_.find(timerId); + if (iter == timerEntryMap_.end()) { + TIME_HILOGD(TIME_MODULE_SERVICE, "end."); + return false; + } else { + dprintf(fd, " - dump timer number = %d\n", iter->first); + dprintf(fd, " * timer id = %d\n", iter->second->id); + dprintf(fd, " * timer type = %d\n", iter->second->type); + dprintf(fd, " * timer window Length = %d\n", iter->second->windowLength); + dprintf(fd, " * timer interval = %d\n", iter->second->flag); + dprintf(fd, " * timer uid = %d\n\n", iter->second->uid); + } + TIME_HILOGD(TIME_MODULE_SERVICE, "end."); + return true; +} + +bool TimerManager::ShowTimerTriggerById(int fd, uint64_t timerId) +{ + TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + std::lock_guard lock(entryMapMutex_); + for (size_t i = 0; i < alarmBatches_.size(); i++) { + for (size_t j = 0; j < alarmBatches_[i]->Size(); j++) { + if (alarmBatches_[i]->Get(j)->id == timerId) { + dprintf(fd, " - dump timer id = %d\n", alarmBatches_[i]->Get(j)->id); + dprintf(fd, " * timer trigger = %d\n", alarmBatches_[i]->Get(j)->origWhen); + } + } + } + TIME_HILOGD(TIME_MODULE_SERVICE, "end."); + return true; +} } // MiscServices } // OHOS \ No newline at end of file From 400c368c4e2ef0fe8fb6d09836372cac17472592 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 13:46:57 +0800 Subject: [PATCH 2/6] Signed-off-by: GlaryCastle Changes to be committed: modified: services/dfx/include/time_cmd_dispatcher.h modified: services/dfx/include/time_cmd_parse.h modified: services/dfx/src/time_cmd_dispatcher.cpp modified: services/time_manager/src/time_service.cpp --- services/dfx/include/time_cmd_dispatcher.h | 4 +--- services/dfx/include/time_cmd_parse.h | 2 +- services/dfx/src/time_cmd_dispatcher.cpp | 5 ++--- services/time_manager/src/time_service.cpp | 6 ++++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/services/dfx/include/time_cmd_dispatcher.h b/services/dfx/include/time_cmd_dispatcher.h index c653623..ad88a81 100644 --- a/services/dfx/include/time_cmd_dispatcher.h +++ b/services/dfx/include/time_cmd_dispatcher.h @@ -19,12 +19,10 @@ #include #include #include - #include "time_cmd_parse.h" namespace OHOS { namespace MiscServices { - class TimeCmdDispatcher { public: static TimeCmdDispatcher &GetInstance(); @@ -37,4 +35,4 @@ private: }; } // namespace MiscServices } // namespace OHOS -#endif //TIME_CMD_DISPATCHER_H \ No newline at end of file +#endif // TIME_CMD_DISPATCHER_H \ No newline at end of file diff --git a/services/dfx/include/time_cmd_parse.h b/services/dfx/include/time_cmd_parse.h index db48880..04ffba2 100644 --- a/services/dfx/include/time_cmd_parse.h +++ b/services/dfx/include/time_cmd_parse.h @@ -34,4 +34,4 @@ private: std::string help; Action action; }; -#endif //TIME_CMDPARSE_H \ No newline at end of file +#endif // TIME_CMDPARSE_H \ No newline at end of file diff --git a/services/dfx/src/time_cmd_dispatcher.cpp b/services/dfx/src/time_cmd_dispatcher.cpp index 8f4a2f6..331e3cb 100644 --- a/services/dfx/src/time_cmd_dispatcher.cpp +++ b/services/dfx/src/time_cmd_dispatcher.cpp @@ -13,15 +13,14 @@ * limitations under the License. */ +#include "time_cmd_dispatcher.h" + #include #include - -#include "time_cmd_dispatcher.h" #include "time_hilog_wreapper.h" namespace OHOS { namespace MiscServices { - bool TimeCmdDispatcher::Dispatch(int fd, const std::vector &args) { if (args.empty() || args.at(0) == "-h") { diff --git a/services/time_manager/src/time_service.cpp b/services/time_manager/src/time_service.cpp index 65671d4..04f8546 100644 --- a/services/time_manager/src/time_service.cpp +++ b/services/time_manager/src/time_service.cpp @@ -423,7 +423,8 @@ void TimeService::DumpTimerInfoById(int fd, const std::vector &inpu return; } } - timerManagerHandler_->ShowTimerEntryById(fd, std::atoi(input.at(2).c_str())); + int paramNumPos=2; + timerManagerHandler_->ShowTimerEntryById(fd, std::atoi(input.at(paramNumPos).c_str())); } void TimeService::DumpTimerTriggerById(int fd, const std::vector &input) @@ -437,7 +438,8 @@ void TimeService::DumpTimerTriggerById(int fd, const std::vector &i return; } } - timerManagerHandler_->ShowTimerTriggerById(fd, std::atoi(input.at(2).c_str())); + int paramNumPos=2; + timerManagerHandler_->ShowTimerTriggerById(fd, std::atoi(input.at(paramNumPos).c_str())); } int TimeService::set_rtc_time(time_t sec) From 626eeae6ba2f73e8c80cf4a79efa24383daad972 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 14:02:18 +0800 Subject: [PATCH 3/6] Signed-off-by: GlaryCastle Changes to be committed: modified: services/BUILD.gn --- services/BUILD.gn | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index f125d03..28690b5 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -39,6 +39,10 @@ ohos_shared_library("time_service") { ] sources = [ + "dfx/src/time_cmd_dispatcher.cpp", + "dfx/src/time_cmd_parse.cpp", + "dfx/src/time_sysevent.cpp", + "dfx/src/time_trace.cpp", "time_manager/src/itimer_info.cpp", "time_manager/src/net_conn_callback_observer.cpp", "time_manager/src/nitz_subscriber.cpp", @@ -59,10 +63,6 @@ ohos_shared_library("time_service") { "timer/src/timer_handler.cpp", "timer/src/timer_info.cpp", "timer/src/timer_manager.cpp", - "dfx/src/time_sysevent.cpp", - "dfx/src/time_trace.cpp", - "dfx/src/time_cmd_parse.cpp", - "dfx/src/time_cmd_dispatcher.cpp", ] deps = [ From 6d6f7894a871e096d37db1bf8298020e4d424251 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 14:41:56 +0800 Subject: [PATCH 4/6] Signed-off-by: GlaryCastle Changes to be committed: modified: services/time_manager/src/time_service.cpp --- services/time_manager/src/time_service.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/time_manager/src/time_service.cpp b/services/time_manager/src/time_service.cpp index 04f8546..462864d 100644 --- a/services/time_manager/src/time_service.cpp +++ b/services/time_manager/src/time_service.cpp @@ -423,7 +423,7 @@ void TimeService::DumpTimerInfoById(int fd, const std::vector &inpu return; } } - int paramNumPos=2; + int paramNumPos = 2; timerManagerHandler_->ShowTimerEntryById(fd, std::atoi(input.at(paramNumPos).c_str())); } @@ -438,7 +438,7 @@ void TimeService::DumpTimerTriggerById(int fd, const std::vector &i return; } } - int paramNumPos=2; + int paramNumPos = 2; timerManagerHandler_->ShowTimerTriggerById(fd, std::atoi(input.at(paramNumPos).c_str())); } From 5b6ad7d64ff2bbe6abe0a466981b2169e5b2a8f7 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 15:01:40 +0800 Subject: [PATCH 5/6] Signed-off-by: GlaryCastle Changes to be committed: modified: services/dfx/src/time_cmd_dispatcher.cpp modified: services/timer/src/timer_manager.cpp --- services/dfx/src/time_cmd_dispatcher.cpp | 1 - services/timer/src/timer_manager.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/services/dfx/src/time_cmd_dispatcher.cpp b/services/dfx/src/time_cmd_dispatcher.cpp index 331e3cb..e20997f 100644 --- a/services/dfx/src/time_cmd_dispatcher.cpp +++ b/services/dfx/src/time_cmd_dispatcher.cpp @@ -60,6 +60,5 @@ TimeCmdDispatcher &TimeCmdDispatcher::GetInstance() static TimeCmdDispatcher instance; return instance; } - } // 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 90f7e4d..e54cf04 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -680,7 +680,7 @@ bool TimerManager::ShowtimerEntryMap(int fd) dprintf(fd, " * timer id = %d\n", iter->second->id); dprintf(fd, " * timer type = %d\n", iter->second->type); dprintf(fd, " * timer window Length = %d\n", iter->second->windowLength); - dprintf(fd, " * timer interval = %d\n", iter->second->flag); + dprintf(fd, " * timer interval = %d\n", iter->second->interval); dprintf(fd, " * timer uid = %d\n\n", iter->second->uid); } TIME_HILOGD(TIME_MODULE_SERVICE, "end."); From 5a34f60f218a412b3c93dbd3211c8b3f04e7a464 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 16:33:17 +0800 Subject: [PATCH 6/6] Signed-off-by: GlaryCastle Changes to be committed: modified: hisysevent.yaml modified: services/dfx/include/time_cmd_dispatcher.h modified: services/dfx/include/time_cmd_parse.h modified: services/dfx/src/time_cmd_dispatcher.cpp modified: services/dfx/src/time_cmd_parse.cpp --- hisysevent.yaml | 6 +++--- services/dfx/include/time_cmd_dispatcher.h | 2 +- services/dfx/include/time_cmd_parse.h | 2 +- services/dfx/src/time_cmd_dispatcher.cpp | 2 +- services/dfx/src/time_cmd_parse.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index b094556..ee969a3 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -17,6 +17,6 @@ MISC_TIME_STATISTIC_REPORT: __BASE: {type: STATISTIC, level: MINOR, tag: PowerStatus, desc: trigger timer report} CALLER_PID: {type: INT32, desc: the process id} CALLER_UID: {type: INT32, desc: the user id} - TIMER_TYPE: {type: INT32,desc: the timer type} - TRIGGER_TIME: {type:INT64,desc the trigger time} - INTERVAL: {type: INT32, desc: the trigger time} \ No newline at end of file + 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 diff --git a/services/dfx/include/time_cmd_dispatcher.h b/services/dfx/include/time_cmd_dispatcher.h index ad88a81..ea37259 100644 --- a/services/dfx/include/time_cmd_dispatcher.h +++ b/services/dfx/include/time_cmd_dispatcher.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/services/dfx/include/time_cmd_parse.h b/services/dfx/include/time_cmd_parse.h index 04ffba2..75f4d07 100644 --- a/services/dfx/include/time_cmd_parse.h +++ b/services/dfx/include/time_cmd_parse.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/services/dfx/src/time_cmd_dispatcher.cpp b/services/dfx/src/time_cmd_dispatcher.cpp index e20997f..afb6167 100644 --- a/services/dfx/src/time_cmd_dispatcher.cpp +++ b/services/dfx/src/time_cmd_dispatcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 diff --git a/services/dfx/src/time_cmd_parse.cpp b/services/dfx/src/time_cmd_parse.cpp index 705f313..2e58fa5 100644 --- a/services/dfx/src/time_cmd_parse.cpp +++ b/services/dfx/src/time_cmd_parse.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 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