From 1e4f025db4366e104cb302796763b69d40aa7793 Mon Sep 17 00:00:00 2001 From: tangfan Date: Mon, 15 Apr 2024 10:19:08 +0800 Subject: [PATCH 1/7] short log Signed-off-by: tangfan --- common/include/constants_dinput.h | 2 + common/include/input_hub.cpp | 70 ++++++++++++++++++++++--------- common/include/input_hub.h | 1 + 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index f4b2a44..6979e83 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -223,6 +223,8 @@ namespace DistributedInput { constexpr int32_t SINK_SCREEN_INFO_SIZE = 4; + constexpr int32_t MAX_LOG_TIMES = 20; + enum class EHandlerMsgType { DINPUT_SINK_EVENT_HANDLER_MSG = 1, DINPUT_SOURCE_EVENT_HANDLER_MSG = 2 diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index f6190e4..e8e9cd9 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -559,7 +559,10 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) if (MakeDevice(fd, std::move(device)) < 0) { CloseFd(fd); - DHLOGI("Opening device error: %{public}s", devicePath.c_str()); + if (logCountMap_.count(device->identifier.descriptor) == 0 || + logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGI("Opening device error: %{public}s", devicePath.c_str()); + } return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; } @@ -635,11 +638,21 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr &device) void InputHub::QueryEventInfo(int fd, std::unique_ptr &device) { - DHLOGI("QueryEventInfo: devName: %{public}s, dhId: %{public}s!", device->identifier.name.c_str(), - GetAnonyString(device->identifier.descriptor).c_str()); + if (device == nullptr) { + DHLOGE("device is nullptr!"); + return; + } + if (logCountMap_.count(device->identifier.descriptor) == 0 || + logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGI("QueryEventInfo: devName: %{public}s, dhId: %{public}s!", device->identifier.name.c_str(), + GetAnonyString(device->identifier.descriptor).c_str()); + } struct libevdev *dev = GetLibEvDev(fd); if (dev == nullptr) { - DHLOGE("dev is nullptr"); + if (logCountMap_.count(device->identifier.descriptor) == 0 || + logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGE("dev is nullptr"); + } return; } GetEventTypes(dev, device->identifier); @@ -742,7 +755,10 @@ void InputHub::GetEventTypes(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetEventKeys(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_KEY)) { - DHLOGE("The device doesn't has EV_KEY type!"); + if (logCountMap_.count(identifier.descriptor) == 0 || + logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGE("The device doesn't has EV_KEY type!"); + } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } for (uint32_t eventKey = 0; eventKey < KEY_CNT; eventKey++) { @@ -758,7 +774,10 @@ int32_t InputHub::GetEventKeys(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetABSInfo(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_ABS)) { - DHLOGE("The device doesn't has EV_ABS type!"); + if (logCountMap_.count(identifier.descriptor) == 0 || + logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGE("The device doesn't has EV_ABS type!"); + } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } DHLOGI("The device has abs info, devName: %{public}s, dhId: %{public}s!", @@ -787,7 +806,10 @@ int32_t InputHub::GetABSInfo(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetRELTypes(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_REL)) { - DHLOGE("The device doesn't has EV_REL type!"); + if (logCountMap_.count(identifier.descriptor) == 0 || + logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGE("The device doesn't has EV_REL type!"); + } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } for (uint32_t code = 0; code < REL_CNT; code++) { @@ -844,7 +866,10 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) // If the device isn't recognized as something we handle, don't monitor it. if (device->classes == 0) { - DHLOGI("Dropping device: name='%{public}s'", device->identifier.name.c_str()); + if (logCountMap_.count(device->identifier.descriptor) == 0 || + logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGI("Dropping device: name='%{public}s'", device->identifier.name.c_str()); + } return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; } @@ -953,8 +978,11 @@ void InputHub::GenerateDescriptor(InputDevice &identifier) const } identifier.descriptor = DH_ID_PREFIX + Sha256(rawDescriptor); - DHLOGI("Created descriptor: raw=%{public}s, cooked=%{public}s", rawDescriptor.c_str(), - GetAnonyString(identifier.descriptor).c_str()); + if (logCountMap_.count(identifier.descriptor) == 0 || logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGI("Created descriptor: raw=%{public}s, cooked=%{public}s", rawDescriptor.c_str(), + GetAnonyString(identifier.descriptor).c_str()); + } + logCountMap_[identifier.descriptor]++; } int32_t InputHub::RegisterDeviceForEpollLocked(const Device &device) @@ -1322,16 +1350,18 @@ bool InputHub::IsAllDevicesStoped() void InputHub::RecordDeviceLog(const std::string &devicePath, const InputDevice &identifier) { - DHLOGI("add device: %{public}s\n", devicePath.c_str()); - DHLOGI(" bus: %{public}04x\n" - " vendor %{public}04x\n" - " product %{public}04x\n" - " version %{public}04x\n", - identifier.bus, identifier.vendor, identifier.product, identifier.version); - DHLOGI(" name: \"%{public}s\"\n", identifier.name.c_str()); - DHLOGI(" physicalPath: \"%{public}s\"\n", identifier.physicalPath.c_str()); - DHLOGI(" unique id: \"%{public}s\"\n", identifier.uniqueId.c_str()); - DHLOGI(" descriptor: \"%{public}s\"\n", GetAnonyString(identifier.descriptor).c_str()); + if (logCountMap_.count(identifier.descriptor) == 0 || logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + DHLOGI("add device: %{public}s\n", devicePath.c_str()); + DHLOGI(" bus: %{public}04x\n" + " vendor %{public}04x\n" + " product %{public}04x\n" + " version %{public}04x\n", + identifier.bus, identifier.vendor, identifier.product, identifier.version); + DHLOGI(" name: \"%{public}s\"\n", identifier.name.c_str()); + DHLOGI(" physicalPath: \"%{public}s\"\n", identifier.physicalPath.c_str()); + DHLOGI(" unique id: \"%{public}s\"\n", identifier.uniqueId.c_str()); + DHLOGI(" descriptor: \"%{public}s\"\n", GetAnonyString(identifier.descriptor).c_str()); + } } void InputHub::RecordChangeEventLog(const RawEvent &event) diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 6e7f67d..d057ac7 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -240,6 +240,7 @@ private: std::atomic isStartCollectEvent_; std::atomic isStartCollectHandler_; std::unordered_map sharedDHIds_; + std::unordered_map logCountMap_; }; } // namespace DistributedInput } // namespace DistributedHardware -- Gitee From 33fd8039dda92e66d3d3fd10ef6048a92229177e Mon Sep 17 00:00:00 2001 From: tangfan Date: Mon, 15 Apr 2024 11:05:49 +0800 Subject: [PATCH 2/7] short log Signed-off-by: tangfan --- common/include/input_hub.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index e8e9cd9..ae01049 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -554,7 +554,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } GenerateDescriptor(device->identifier); - + logCountMap_[device->identifier.descriptor]++; RecordDeviceLog(devicePath, device->identifier); if (MakeDevice(fd, std::move(device)) < 0) { @@ -978,11 +978,10 @@ void InputHub::GenerateDescriptor(InputDevice &identifier) const } identifier.descriptor = DH_ID_PREFIX + Sha256(rawDescriptor); - if (logCountMap_.count(identifier.descriptor) == 0 || logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + if (logCountMap_.count(identifier.descriptor) == 0 || logCountMap_.at(identifier.descriptor) <= MAX_LOG_TIMES) { DHLOGI("Created descriptor: raw=%{public}s, cooked=%{public}s", rawDescriptor.c_str(), GetAnonyString(identifier.descriptor).c_str()); } - logCountMap_[identifier.descriptor]++; } int32_t InputHub::RegisterDeviceForEpollLocked(const Device &device) -- Gitee From 8703e8014f49f10209bdf056943714aa8f0ee8b2 Mon Sep 17 00:00:00 2001 From: tangfan Date: Mon, 15 Apr 2024 17:15:12 +0800 Subject: [PATCH 3/7] short log print Signed-off-by: tangfan --- common/include/input_hub.cpp | 31 +++++++++++++++---------------- common/include/input_hub.h | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index ae01049..784b57f 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -109,6 +109,7 @@ int32_t InputHub::Release() } sharedDHIds_.clear(); + logCountMap_.clear(); return DH_SUCCESS; } @@ -559,8 +560,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) if (MakeDevice(fd, std::move(device)) < 0) { CloseFd(fd); - if (logCountMap_.count(device->identifier.descriptor) == 0 || - logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(device->identifier.descriptor)) { DHLOGI("Opening device error: %{public}s", devicePath.c_str()); } return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; @@ -582,6 +582,11 @@ bool InputHub::IsSkipDevicePath(const std::string &path) return skipDevicePaths_.find(path) != skipDevicePaths_.end(); } +bool InputHub::IsNeedPrintLog(const std::string& dhId) const +{ + return logCountMap_.count(dhId) == 0 || logCountMap_.at(dhId) <= MAX_LOG_TIMES; +} + int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr &device) { char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; @@ -642,15 +647,13 @@ void InputHub::QueryEventInfo(int fd, std::unique_ptr &device) DHLOGE("device is nullptr!"); return; } - if (logCountMap_.count(device->identifier.descriptor) == 0 || - logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(device->identifier.descriptor)) { DHLOGI("QueryEventInfo: devName: %{public}s, dhId: %{public}s!", device->identifier.name.c_str(), GetAnonyString(device->identifier.descriptor).c_str()); } struct libevdev *dev = GetLibEvDev(fd); if (dev == nullptr) { - if (logCountMap_.count(device->identifier.descriptor) == 0 || - logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(device->identifier.descriptor)) { DHLOGE("dev is nullptr"); } return; @@ -755,8 +758,7 @@ void InputHub::GetEventTypes(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetEventKeys(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_KEY)) { - if (logCountMap_.count(identifier.descriptor) == 0 || - logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(identifier.descriptor)) { DHLOGE("The device doesn't has EV_KEY type!"); } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; @@ -774,8 +776,7 @@ int32_t InputHub::GetEventKeys(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetABSInfo(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_ABS)) { - if (logCountMap_.count(identifier.descriptor) == 0 || - logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(identifier.descriptor)) { DHLOGE("The device doesn't has EV_ABS type!"); } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; @@ -806,8 +807,7 @@ int32_t InputHub::GetABSInfo(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::GetRELTypes(struct libevdev *dev, InputDevice &identifier) { if (!libevdev_has_event_type(dev, EV_REL)) { - if (logCountMap_.count(identifier.descriptor) == 0 || - logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(identifier.descriptor)) { DHLOGE("The device doesn't has EV_REL type!"); } return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; @@ -866,8 +866,7 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) // If the device isn't recognized as something we handle, don't monitor it. if (device->classes == 0) { - if (logCountMap_.count(device->identifier.descriptor) == 0 || - logCountMap_[device->identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(device->identifier.descriptor)) { DHLOGI("Dropping device: name='%{public}s'", device->identifier.name.c_str()); } return ERR_DH_INPUT_HUB_MAKE_DEVICE_FAIL; @@ -978,7 +977,7 @@ void InputHub::GenerateDescriptor(InputDevice &identifier) const } identifier.descriptor = DH_ID_PREFIX + Sha256(rawDescriptor); - if (logCountMap_.count(identifier.descriptor) == 0 || logCountMap_.at(identifier.descriptor) <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(identifier.descriptor)) { DHLOGI("Created descriptor: raw=%{public}s, cooked=%{public}s", rawDescriptor.c_str(), GetAnonyString(identifier.descriptor).c_str()); } @@ -1349,7 +1348,7 @@ bool InputHub::IsAllDevicesStoped() void InputHub::RecordDeviceLog(const std::string &devicePath, const InputDevice &identifier) { - if (logCountMap_.count(identifier.descriptor) == 0 || logCountMap_[identifier.descriptor] <= MAX_LOG_TIMES) { + if (IsNeedPrintLog(identifier.descriptor)) { DHLOGI("add device: %{public}s\n", devicePath.c_str()); DHLOGI(" bus: %{public}04x\n" " vendor %{public}04x\n" diff --git a/common/include/input_hub.h b/common/include/input_hub.h index d057ac7..264c255 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -206,6 +206,7 @@ private: void RecordSkipDevicePath(std::string path); bool IsSkipDevicePath(const std::string &path); + bool IsNeedPrintLog(const std::string& dhId) const; private: int epollFd_; -- Gitee From 45a1b3c9d45d6064c9d5135c7f7fbb824876f020 Mon Sep 17 00:00:00 2001 From: tangfan Date: Tue, 16 Apr 2024 19:26:21 +0800 Subject: [PATCH 4/7] short log print Signed-off-by: tangfan --- common/include/input_hub.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 784b57f..ea75322 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -555,6 +555,9 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } GenerateDescriptor(device->identifier); + if (logCountMap_[device->identifier.descriptor] >= INT32_MAX - 1) { + logCountMap_[device->identifier.descriptor] = 0; + } logCountMap_[device->identifier.descriptor]++; RecordDeviceLog(devicePath, device->identifier); -- Gitee From e1280eaad630a2c00f4d5212fa42de1e29d607d4 Mon Sep 17 00:00:00 2001 From: tangfan Date: Tue, 16 Apr 2024 19:30:29 +0800 Subject: [PATCH 5/7] short log Signed-off-by: tangfan --- common/include/input_hub.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index ea75322..b9350f3 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -555,7 +555,8 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } GenerateDescriptor(device->identifier); - if (logCountMap_[device->identifier.descriptor] >= INT32_MAX - 1) { + if (logCountMap_.count(device->identifier.descriptor) != 0 && logCountMap_[device->identifier.descriptor] >= + INT32_MAX - 1) { logCountMap_[device->identifier.descriptor] = 0; } logCountMap_[device->identifier.descriptor]++; -- Gitee From f8b971310dbf5719ffa7032a05658eb9b13babd4 Mon Sep 17 00:00:00 2001 From: tangfan Date: Tue, 16 Apr 2024 19:44:46 +0800 Subject: [PATCH 6/7] short log Signed-off-by: tangfan --- common/include/input_hub.cpp | 19 ++++++++++++------- common/include/input_hub.h | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index b9350f3..31b25ec 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -109,7 +109,7 @@ int32_t InputHub::Release() } sharedDHIds_.clear(); - logCountMap_.clear(); + logTimesMap_.clear(); return DH_SUCCESS; } @@ -555,11 +555,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } GenerateDescriptor(device->identifier); - if (logCountMap_.count(device->identifier.descriptor) != 0 && logCountMap_[device->identifier.descriptor] >= - INT32_MAX - 1) { - logCountMap_[device->identifier.descriptor] = 0; - } - logCountMap_[device->identifier.descriptor]++; + IncreaseLogTimes(device->identifier.descriptor); RecordDeviceLog(devicePath, device->identifier); if (MakeDevice(fd, std::move(device)) < 0) { @@ -586,9 +582,18 @@ bool InputHub::IsSkipDevicePath(const std::string &path) return skipDevicePaths_.find(path) != skipDevicePaths_.end(); } +void InputHub::IncreaseLogTimes(const std::string& dhId) +{ + if (logTimesMap_.count(dhId) != 0 && logTimesMap_[dhId] >= INT32_MAX - 1) { + logTimesMap_[dhId] = 0; + } else { + logTimesMap_[dhId]++; + } +} + bool InputHub::IsNeedPrintLog(const std::string& dhId) const { - return logCountMap_.count(dhId) == 0 || logCountMap_.at(dhId) <= MAX_LOG_TIMES; + return logTimesMap_.count(dhId) == 0 || logTimesMap_.at(dhId) <= MAX_LOG_TIMES; } int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr &device) diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 264c255..6448976 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -206,6 +206,7 @@ private: void RecordSkipDevicePath(std::string path); bool IsSkipDevicePath(const std::string &path); + void IncreaseLogTimes(const std::string& dhId); bool IsNeedPrintLog(const std::string& dhId) const; private: @@ -241,7 +242,7 @@ private: std::atomic isStartCollectEvent_; std::atomic isStartCollectHandler_; std::unordered_map sharedDHIds_; - std::unordered_map logCountMap_; + std::unordered_map logTimesMap_; }; } // namespace DistributedInput } // namespace DistributedHardware -- Gitee From 33ee5aaf9cae4e09d4f8a0c95128319b7b01cd76 Mon Sep 17 00:00:00 2001 From: tangfan Date: Wed, 17 Apr 2024 15:37:21 +0800 Subject: [PATCH 7/7] short log print Signed-off-by: tangfan --- common/include/input_hub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 31b25ec..50a4f88 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -584,7 +584,7 @@ bool InputHub::IsSkipDevicePath(const std::string &path) void InputHub::IncreaseLogTimes(const std::string& dhId) { - if (logTimesMap_.count(dhId) != 0 && logTimesMap_[dhId] >= INT32_MAX - 1) { + if (logTimesMap_.find(dhId) != logTimesMap_.end() && logTimesMap_[dhId] >= INT32_MAX - 1) { logTimesMap_[dhId] = 0; } else { logTimesMap_[dhId]++; @@ -593,7 +593,7 @@ void InputHub::IncreaseLogTimes(const std::string& dhId) bool InputHub::IsNeedPrintLog(const std::string& dhId) const { - return logTimesMap_.count(dhId) == 0 || logTimesMap_.at(dhId) <= MAX_LOG_TIMES; + return logTimesMap_.find(dhId) == logTimesMap_.end() || logTimesMap_.at(dhId) <= MAX_LOG_TIMES; } int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr &device) -- Gitee