!216 Watchdog改名dump

Merge pull request !216 from 太帅太烦恼/master
This commit is contained in:
openharmony_ci 2024-06-06 08:13:20 +00:00 committed by Gitee
commit 051a5801b5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 87 additions and 135 deletions

View File

@ -114,7 +114,6 @@ ohos_shared_library("libffrt") {
"src/dfx/dump/dump.cpp",
"src/dfx/log/ffrt_log.cpp",
"src/dfx/trace/ffrt_trace.cpp",
"src/dfx/watchdog/watchdog.cpp",
"src/dfx/watchdog/watchdog_util.cpp",
"src/dm/dependence_manager.cpp",
"src/dm/sdependence_manager.cpp",

View File

@ -21,5 +21,11 @@ typedef enum {
DUMP_INFO_ALL = 0,
} ffrt_dump_cmd_t;
FFRT_C_API int ffrt_dump(uint32_t cmd, char *buf, uint32_t len);
typedef void(*ffrt_task_timeout_cb)(uint64_t gid, const char *msg, uint32_t size);
FFRT_C_API int ffrt_dump(ffrt_dump_cmd_t cmd, char *buf, uint32_t len);
FFRT_C_API ffrt_task_timeout_cb ffrt_task_timeout_get_cb(void);
FFRT_C_API void ffrt_task_timeout_set_cb(ffrt_task_timeout_cb cb);
FFRT_C_API uint32_t ffrt_task_timeout_get_threshold(void);
FFRT_C_API void ffrt_task_timeout_set_threshold(uint32_t threshold_ms);
#endif /* FFRT_API_C_FFRT_DUMP_H */

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2023 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 FFRT_WATCHDOG_H
#define FFRT_WATCHDOG_H
#include <stdint.h>
#include "type_def_ext.h"
typedef void(*ffrt_watchdog_cb)(uint64_t, const char *, uint32_t);
FFRT_C_API int ffrt_watchdog_dumpinfo(char *buf, uint32_t len);
FFRT_C_API void ffrt_watchdog_register(ffrt_watchdog_cb cb, uint32_t timeout_ms, uint32_t interval_ms);
FFRT_C_API ffrt_watchdog_cb ffrt_watchdog_get_cb(void);
FFRT_C_API uint32_t ffrt_watchdog_get_timeout(void);
FFRT_C_API uint32_t ffrt_watchdog_get_interval(void);
#endif /* FFRT_WATCHDOG_H */

View File

@ -28,7 +28,6 @@
#include "c/task_ext.h"
#include "c/queue_ext.h"
#include "c/thread.h"
#include "c/ffrt_watchdog.h"
#include "c/executor_task.h"
#include "c/shared_mutex.h"
#include "c/ffrt_dump.h"

View File

@ -17,7 +17,7 @@ file(GLOB_RECURSE FFRT_SRC_LIST
"${FFRT_CODE_PATH}/dfx/bbox/bbox.cpp"
"${FFRT_CODE_PATH}/dfx/log/ffrt_log.cpp"
"${FFRT_CODE_PATH}/dfx/log/${FFRT_LOG_PLAT}/log_base.cpp"
"${FFRT_CODE_PATH}/dfx/watchdog/watchdog.cpp"
"${FFRT_CODE_PATH}/dfx/dump/dump.cpp"
"${FFRT_CODE_PATH}/dfx/watchdog/watchdog_util.cpp"
)

View File

@ -12,28 +12,97 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <securec.h>
#include "c/ffrt_dump.h"
#include "c/ffrt_watchdog.h"
#include "dfx/bbox/bbox.h"
#include "internal_inc/osal.h"
#include "dfx/log/ffrt_log_api.h"
namespace ffrt {
constexpr uint32_t DEFAULT_TIMEOUT_MS = 30000;
struct TimeoutCfg {
static inline TimeoutCfg* Instance()
{
static TimeoutCfg inst;
return &inst;
}
uint32_t timeout = DEFAULT_TIMEOUT_MS;
ffrt_task_timeout_cb callback = nullptr;
};
}
#ifdef __cplusplus
extern "C" {
#endif
#endif //__cplusplus
API_ATTRIBUTE((visibility("default")))
int ffrt_dump(uint32_t cmd, char *buf, uint32_t len)
int dump_info_all(char *buf, uint32_t len)
{
#ifdef FFRT_CO_BACKTRACE_OH_ENABLE
if (FFRTIsWork()) {
std::string dumpInfo;
dumpInfo += "|-> Launcher proc ffrt, pid:" + std::to_string(GetPid()) + "\n";
dumpInfo += SaveTaskCounterInfo();
dumpInfo += SaveWorkerStatusInfo();
dumpInfo += SaveReadyQueueStatusInfo();
dumpInfo += SaveTaskStatusInfo();
if (dumpInfo.length() > (len - 1)) {
FFRT_LOGW("dumpInfo exceeds the buffer length, length:%d", dumpInfo.length());
}
int printed_num = snprintf_s(buf, len, len - 1, "%s", dumpInfo.c_str());
if (printed_num == -1) {
return snprintf_s(buf, len, len - 1, "|-> watchdog fail to print dumpinfo, pid: %s\n",
std::to_string(GetPid()).c_str());
}
return printed_num;
} else {
return snprintf_s(buf, len, len - 1, "|-> FFRT has done all tasks, pid: %s\n",
std::to_string(GetPid()).c_str());
}
#else
return -1;
#endif
}
API_ATTRIBUTE((visibility("default")))
int ffrt_dump(ffrt_dump_cmd_t cmd, char *buf, uint32_t len)
{
#ifdef FFRT_CO_BACKTRACE_OH_ENABLE
switch (static_cast<ffrt_dump_cmd_t>(cmd)) {
case ffrt_dump_cmd_t::DUMP_INFO_ALL: {
return ffrt_watchdog_dumpinfo(buf, len);
return dump_info_all(buf, len);
}
default: {
FFRT_LOGE("ffr_dump unsupport cmd[%d]", cmd);
return -1;
}
}
#endif // FFRT_CO_BACKTRACE_OH_ENABLE
return -1;
}
API_ATTRIBUTE((visibility("default")))
ffrt_task_timeout_cb ffrt_task_timeout_get_cb(void)
{
return ffrt::TimeoutCfg::Instance()->callback;
}
API_ATTRIBUTE((visibility("default")))
void ffrt_task_timeout_set_cb(ffrt_task_timeout_cb cb)
{
ffrt::TimeoutCfg::Instance()->callback = cb;
}
API_ATTRIBUTE((visibility("default")))
uint32_t ffrt_task_timeout_get_threshold(void)
{
return ffrt::TimeoutCfg::Instance()->timeout;
}
API_ATTRIBUTE((visibility("default")))
void ffrt_task_timeout_set_threshold(uint32_t threshold_ms)
{
ffrt::TimeoutCfg::Instance()->timeout = threshold_ms;
}
#ifdef __cplusplus
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) 2023 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 <securec.h>
#include "c/ffrt_watchdog.h"
#include "internal_inc/osal.h"
#include "dfx/bbox/bbox.h"
#include "dfx/log/ffrt_log_api.h"
namespace ffrt {
constexpr uint32_t DEFAULT_TIMEOUT_MS = 30000;
struct WatchdogCfg {
static inline WatchdogCfg* Instance()
{
static WatchdogCfg inst;
return &inst;
}
uint32_t timeout = DEFAULT_TIMEOUT_MS;
uint32_t interval = DEFAULT_TIMEOUT_MS;
ffrt_watchdog_cb callback = nullptr;
};
}
#ifdef __cplusplus
extern "C" {
#endif
API_ATTRIBUTE((visibility("default")))
int ffrt_watchdog_dumpinfo(char *buf, uint32_t len)
{
#ifdef FFRT_CO_BACKTRACE_OH_ENABLE
if (FFRTIsWork()) {
std::string dumpInfo;
dumpInfo += "|-> Launcher proc ffrt, pid:" + std::to_string(GetPid()) + "\n";
dumpInfo += SaveTaskCounterInfo();
dumpInfo += SaveWorkerStatusInfo();
dumpInfo += SaveReadyQueueStatusInfo();
dumpInfo += SaveTaskStatusInfo();
if (dumpInfo.length() > (len - 1)) {
FFRT_LOGW("dumpInfo exceeds the buffer length, length:%d", dumpInfo.length());
}
int printed_num = snprintf_s(buf, len, len - 1, "%s", dumpInfo.c_str());
if (printed_num == -1) {
return snprintf_s(buf, len, len - 1, "|-> watchdog fail to print dumpinfo, pid: %s\n",
std::to_string(GetPid()).c_str());
}
return printed_num;
} else {
return snprintf_s(buf, len, len - 1, "|-> FFRT has done all tasks, pid: %s\n",
std::to_string(GetPid()).c_str());
}
#else
return -1;
#endif
}
API_ATTRIBUTE((visibility("default")))
void ffrt_watchdog_register(ffrt_watchdog_cb cb, uint32_t timeout_ms, uint32_t interval_ms)
{
ffrt::WatchdogCfg::Instance()->callback = cb;
ffrt::WatchdogCfg::Instance()->timeout = timeout_ms;
ffrt::WatchdogCfg::Instance()->interval = interval_ms;
}
API_ATTRIBUTE((visibility("default")))
ffrt_watchdog_cb ffrt_watchdog_get_cb(void)
{
return ffrt::WatchdogCfg::Instance()->callback;
}
API_ATTRIBUTE((visibility("default")))
uint32_t ffrt_watchdog_get_timeout(void)
{
return ffrt::WatchdogCfg::Instance()->timeout;
}
API_ATTRIBUTE((visibility("default")))
uint32_t ffrt_watchdog_get_interval(void)
{
return ffrt::WatchdogCfg::Instance()->interval;
}
#ifdef __cplusplus
}
#endif

View File

@ -18,7 +18,7 @@
#include <map>
#include "sync/sync.h"
#ifdef FFRT_OH_WATCHDOG_ENABLE
#include "c/ffrt_watchdog.h"
#include "c/ffrt_dump.h"
#endif
namespace {
constexpr uint64_t VALID_TIMEOUT_MIN = 10000;
@ -93,7 +93,7 @@ namespace ffrt {
ss << "parallel task gid=" << gid << " execution time exceeds " << timeout << " ms";
std::string msg = ss.str();
FFRT_LOGE("%s", msg.c_str());
ffrt_watchdog_cb func = ffrt_watchdog_get_cb();
ffrt_task_timeout_cb func = ffrt_task_timeout_get_cb();
if (func) {
func(gid, msg.c_str(), msg.size());
}

View File

@ -16,7 +16,7 @@
#include <sstream>
#include "dfx/log/ffrt_log_api.h"
#include "sync/sync.h"
#include "c/ffrt_watchdog.h"
#include "c/ffrt_dump.h"
namespace {
constexpr uint32_t INVALID_TASK_ID = 0;
@ -36,7 +36,7 @@ QueueMonitor::QueueMonitor()
{
queuesRunningInfo_.reserve(QUEUE_INFO_INITIAL_CAPACITY);
queuesStructInfo_.reserve(QUEUE_INFO_INITIAL_CAPACITY);
uint64_t timeout = ffrt_watchdog_get_timeout() * TIME_CONVERT_UNIT;
uint64_t timeout = ffrt_task_timeout_get_threshold() * TIME_CONVERT_UNIT;
if (timeout < MIN_TIMEOUT_THRESHOLD_US) {
timeoutUs_ = 0;
FFRT_LOGE("failed to setup watchdog because [%llu] us less than precision threshold", timeout);
@ -169,7 +169,7 @@ void QueueMonitor::CheckQueuesStatus()
}
FFRT_LOGE("%s", ss.str().c_str());
ffrt_watchdog_cb func = ffrt_watchdog_get_cb();
ffrt_task_timeout_cb func = ffrt_task_timeout_get_cb();
if (func) {
func(taskId, ss.str().c_str(), ss.str().size());
}