diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index db1f6a0..1b0b2f4 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -183,6 +183,14 @@ namespace DistributedInput { const std::string DINPUT_LOG_TITLE_TAG = "DINPUT"; + constexpr const char* LATENCY_COUNT_THREAD_NAME = "latencyCount"; + + constexpr const char* EVENT_INJECT_THREAD_NAME = "eventInject"; + + constexpr const char* COLLECT_EVENT_THREAD_NAME = "collectEvents"; + + constexpr const char* CHECK_KEY_STATUS_THREAD_NAME = "checkKeyStatus"; + constexpr int32_t LOG_MAX_LEN = 4096; constexpr uint32_t SCREEN_ID_DEFAULT = 0; diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index b16cd60..4126246 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -177,6 +178,10 @@ bool DistributedInputHandler::InitCollectEventsThread() void *DistributedInputHandler::CollectEventsThread(void *param) { + int32_t ret = pthread_setname_np(pthread_self(), COLLECT_EVENT_THREAD_NAME); + if (ret != 0) { + DHLOGE("CollectEventsThread setname failed."); + } DistributedInputHandler *pThis = reinterpret_cast(param); std::string deviceId; diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 1743a9d..31c72d7 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,10 @@ bool DistributedInputCollector::InitCollectEventsThread() void *DistributedInputCollector::CollectEventsThread(void *param) { + int32_t ret = pthread_setname_np(pthread_self(), COLLECT_EVENT_THREAD_NAME); + if (ret != 0) { + DHLOGE("CollectEventsThread setname failed."); + } DistributedInputCollector *pThis = reinterpret_cast(param); pThis->StartCollectEventsThread(); DHLOGW("DistributedInputCollector::CollectEventsThread exist!"); diff --git a/services/sink/sinkmanager/include/distributed_input_sink_manager.h b/services/sink/sinkmanager/include/distributed_input_sink_manager.h index 74c32fd..1fd3bda 100644 --- a/services/sink/sinkmanager/include/distributed_input_sink_manager.h +++ b/services/sink/sinkmanager/include/distributed_input_sink_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -84,6 +84,7 @@ public: } void SleepTimeMs(); void StringSplit(const std::string &str, const char split, std::vector &vecStr); + void CreateCheckThread(const int32_t &sessionId, const std::string &strDhids); void CheckKeyState(const int32_t &sessionId, const std::string &strDhids); }; diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 6fcbfa5..31d3a15 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -210,8 +211,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInput( deviceInfos); for (auto deviceInfo : deviceInfos) { DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str()); - std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId, - deviceInfo.second).detach(); + CreateCheckThread(sessionId, deviceInfo.second); } } } @@ -269,7 +269,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInputDhid(con return; } - std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId, strDhids).detach(); + CreateCheckThread(sessionId, strDhids); // add the dhids if (startRes == DH_SUCCESS) { std::vector vecStr; @@ -337,8 +337,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartDhidRemoteInpu return; } - std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, - toSinkSessionId, strDhids).detach(); + CreateCheckThread(toSinkSessionId, strDhids); // add the dhids if (startRes == DH_SUCCESS) { @@ -434,8 +433,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartTypeRemoteInpu deviceInfos); for (auto deviceInfo : deviceInfos) { DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str()); - std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, toSinkSessionId, - deviceInfo.second).detach(); + CreateCheckThread(toSinkSessionId, deviceInfo.second); } } @@ -497,6 +495,18 @@ void DistributedInputSinkManager::DInputSinkListener::SleepTimeMs() std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS)); } +void DistributedInputSinkManager::DInputSinkListener::CreateCheckThread(const int32_t &sessionId, + const std::string &strDhids) +{ + std::thread checkKeyStateThread = + std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId, strDhids); + int32_t ret = pthread_setname_np(checkKeyStateThread.native_handle(), CHECK_KEY_STATUS_THREAD_NAME); + if (ret != 0) { + DHLOGE("CreateCheckThread setname failed."); + } + checkKeyStateThread.detach(); +} + void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_t &sessionId, const std::string &strDhids) { diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 3edd385..55b9559 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -19,6 +19,7 @@ #include #include +#include #include #include "anonymous_string.h" @@ -247,6 +248,10 @@ void DistributedInputNodeManager::ReportEvent(const RawEvent rawEvent) void DistributedInputNodeManager::InjectEvent() { + int32_t ret = pthread_setname_np(pthread_self(), EVENT_INJECT_THREAD_NAME); + if (ret != 0) { + DHLOGE("InjectEvent setname failed."); + } DHLOGI("start"); while (isInjectThreadRunning_.load()) { std::shared_ptr event = nullptr; diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 2ce3a0c..5fa6c90 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -17,6 +17,7 @@ #include #include +#include #include "anonymous_string.h" #include "distributed_hardware_fwk_kit.h" @@ -652,6 +653,10 @@ int32_t DistributedInputSourceTransport::LatencyCount(const std::string& deviceI void DistributedInputSourceTransport::StartLatencyCount(const std::string& deviceId) { + int32_t ret = pthread_setname_np(pthread_self(), LATENCY_COUNT_THREAD_NAME); + if (ret != 0) { + DHLOGE("StartLatencyCount setname failed."); + } DHLOGI("start"); while (isLatencyThreadRunning_.load()) { if (sendNum_ >= INPUT_LATENCY_DELAY_TIMES) {