mirror of
https://github.com/openharmony/miscservices_time.git
synced 2026-07-19 20:03:38 -04:00
!189 miscservices_time dfx
Merge pull request !189 from GlaryCastle/master
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
],
|
||||
"features": [
|
||||
],
|
||||
"hisysevent_config": [
|
||||
"//base/miscservices/time/hisysevent.yaml"
|
||||
],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
|
||||
@@ -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 interval time}
|
||||
@@ -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",
|
||||
@@ -38,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",
|
||||
@@ -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",
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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_CMD_DISPATCHER_H
|
||||
#define TIME_CMD_DISPATCHER_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "time_cmd_parse.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class TimeCmdDispatcher {
|
||||
public:
|
||||
static TimeCmdDispatcher &GetInstance();
|
||||
void RegisterCommand(std::shared_ptr<TimeCmdParse> &cmd);
|
||||
bool Dispatch(int fd, const std::vector<std::string> &args);
|
||||
std::string getCmdTitle(int fd, const std::vector<std::string> &args);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::shared_ptr<TimeCmdParse>> cmdHandler;
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
#endif // TIME_CMD_DISPATCHER_H
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_CMDPARSE_H
|
||||
#define TIME_CMDPARSE_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TimeCmdParse {
|
||||
public:
|
||||
using Action = std::function<void(int fd, const std::vector<std::string> &input)>;
|
||||
TimeCmdParse(const std::vector<std::string> &argsFormat, const std::string &strHelp, const Action &action);
|
||||
std::string ShowHelp();
|
||||
void DoAction(int fd, const std::vector<std::string> &input);
|
||||
std::string GetOption();
|
||||
std::string GetFormat();
|
||||
|
||||
private:
|
||||
std::vector<std::string> format;
|
||||
std::string help;
|
||||
Action action;
|
||||
};
|
||||
#endif // TIME_CMDPARSE_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 <string>
|
||||
|
||||
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
|
||||
@@ -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 <string>
|
||||
|
||||
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
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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_cmd_dispatcher.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include "time_hilog_wreapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
bool TimeCmdDispatcher::Dispatch(int fd, const std::vector<std::string> &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<TimeCmdParse> &cmd)
|
||||
{
|
||||
cmdHandler.insert(std::make_pair(cmd->GetOption(), cmd));
|
||||
}
|
||||
|
||||
std::string TimeCmdDispatcher::getCmdTitle(int fd, const std::vector<std::string> &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
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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_cmd_parse.h"
|
||||
|
||||
TimeCmdParse::TimeCmdParse(
|
||||
const std::vector<std::string> &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<std::string> &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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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<std::u16string> &args) override;
|
||||
void DumpAllTimeInfo(int fd, const std::vector<std::string> &input);
|
||||
void DumpTimerInfo(int fd, const std::vector<std::string> &input);
|
||||
void DumpTimerInfoById(int fd, const std::vector<std::string> &input);
|
||||
void DumpTimerTriggerById(int fd, const std::vector<std::string> &input);
|
||||
void InitDumpCmd();
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
|
||||
@@ -90,6 +90,28 @@ sptr<TimeService> TimeService::GetInstance()
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void TimeService::InitDumpCmd()
|
||||
{
|
||||
auto cmdTime = std::make_shared<TimeCmdParse>(std::vector<std::string>({ "-time" }),
|
||||
"dump current time info,include localtime,timezone info",
|
||||
[this](int fd, const std::vector<std::string> &input) { DumpAllTimeInfo(fd, input); });
|
||||
TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTime);
|
||||
|
||||
auto cmdTimerAll = std::make_shared<TimeCmdParse>(std::vector<std::string>({ "-timer", "-a" }),
|
||||
"dump all timer info", [this](int fd, const std::vector<std::string> &input) { DumpTimerInfo(fd, input); });
|
||||
TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTimerAll);
|
||||
|
||||
auto cmdTimerInfo = std::make_shared<TimeCmdParse>(std::vector<std::string>({ "-timer", "-i", "[n]" }),
|
||||
"dump the timer info with timer id",
|
||||
[this](int fd, const std::vector<std::string> &input) { DumpTimerInfoById(fd, input); });
|
||||
TimeCmdDispatcher::GetInstance().RegisterCommand(cmdTimerInfo);
|
||||
|
||||
auto cmdTimerTrigger = std::make_shared<TimeCmdParse>(std::vector<std::string>({ "-timer", "-s", "[n]" }),
|
||||
"dump current time info,include localtime,timezone info",
|
||||
[this](int fd, const std::vector<std::string> &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,89 @@ int32_t TimeService::SetTime(const int64_t time)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int TimeService::Dump(int fd, const std::vector<std::u16string> &args)
|
||||
{
|
||||
int uid = static_cast<int>(IPCSkeleton::GetCallingUid());
|
||||
const int maxUid = 10000;
|
||||
if (uid > maxUid) {
|
||||
return E_TIME_DEAL_FAILED;
|
||||
}
|
||||
|
||||
std::vector<std::string> 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<std::string> &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<std::string> &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<std::string> &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;
|
||||
}
|
||||
}
|
||||
int paramNumPos = 2;
|
||||
timerManagerHandler_->ShowTimerEntryById(fd, std::atoi(input.at(paramNumPos).c_str()));
|
||||
}
|
||||
|
||||
void TimeService::DumpTimerTriggerById(int fd, const std::vector<std::string> &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;
|
||||
}
|
||||
}
|
||||
int paramNumPos = 2;
|
||||
timerManagerHandler_->ShowTimerTriggerById(fd, std::atoi(input.at(paramNumPos).c_str()));
|
||||
}
|
||||
|
||||
int TimeService::set_rtc_time(time_t sec)
|
||||
{
|
||||
struct rtc_time rtc {};
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -669,5 +669,58 @@ steady_clock::time_point MaxTriggerTime(steady_clock::time_point now,
|
||||
}
|
||||
return triggerAtTime + milliseconds(static_cast<long>(BATCH_WINDOW_COE * futurity.count()));
|
||||
}
|
||||
|
||||
bool TimerManager::ShowtimerEntryMap(int fd)
|
||||
{
|
||||
TIME_HILOGD(TIME_MODULE_SERVICE, "start.");
|
||||
std::lock_guard<std::mutex> lock(entryMapMutex_);
|
||||
std::map<uint64_t, std::shared_ptr<TimerEntry>>::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->interval);
|
||||
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<std::mutex> lock(entryMapMutex_);
|
||||
std::map<uint64_t, std::shared_ptr<TimerEntry>>::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<std::mutex> 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
|
||||
Reference in New Issue
Block a user