fix log repeat

Signed-off-by: lixiangpeng5 <lixiangpeng5@huawei.com>
Change-Id: I8fd161c0308d0c3de2a2130311168b783b18a72c
This commit is contained in:
lixiangpeng5 2024-01-28 08:52:56 +00:00
parent 378c7ff8a0
commit 1226c355ac
3 changed files with 13 additions and 7 deletions

View File

@ -15,6 +15,7 @@
#include "sensor_data_processer.h"
#include <cinttypes>
#include <sys/prctl.h>
#include <sys/socket.h>
#include <thread>
@ -208,7 +209,8 @@ void SensorDataProcesser::SendRawData(std::unordered_map<int32_t, SensorData> &c
size_t eventSize = events.size();
auto ret = channel->SendData(events.data(), eventSize * sizeof(SensorData));
if (ret != ERR_OK) {
SEN_HILOGE("Send data failed, ret:%{public}d", ret);
SEN_HILOGE("Send data failed, ret:%{public}d, sensorId:%{public}d, timestamp:%{public}" PRId64,
ret, events[eventSize - 1].sensorTypeId, events[eventSize - 1].timestamp);
int32_t sensorId = events[eventSize - 1].sensorTypeId;
cacheBuf[sensorId] = events[eventSize - 1];
}
@ -223,13 +225,16 @@ int32_t SensorDataProcesser::CacheSensorEvent(const SensorData &data, sptr<Senso
auto cacheEvent = cacheBuf.find(sensorId);
if (cacheEvent != cacheBuf.end()) {
// Try to send the last failed value, if it still fails, replace the previous cache directly
ret = channel->SendData(&cacheEvent->second, sizeof(SensorData));
const SensorData &cacheData = cacheEvent->second;
ret = channel->SendData(&cacheData, sizeof(SensorData));
if (ret != ERR_OK) {
SEN_HILOGE("ret:%{public}d", ret);
SEN_HILOGE("retry send cache data failed, ret:%{public}d, sensorId:%{public}d, timestamp:%{public}" PRId64,
ret, cacheData.sensorTypeId, cacheData.timestamp);
}
ret = channel->SendData(&data, sizeof(SensorData));
if (ret != ERR_OK) {
SEN_HILOGE("ret:%{public}d", ret);
SEN_HILOGE("retry send data failed, ret:%{public}d, sensorId:%{public}d, timestamp:%{public}" PRId64,
ret, data.sensorTypeId, data.timestamp);
cacheBuf[sensorId] = data;
} else {
cacheBuf.erase(cacheEvent);
@ -237,7 +242,8 @@ int32_t SensorDataProcesser::CacheSensorEvent(const SensorData &data, sptr<Senso
} else {
ret = channel->SendData(&data, sizeof(SensorData));
if (ret != ERR_OK) {
SEN_HILOGE("ret:%{public}d", ret);
SEN_HILOGE("directly retry failed, ret:%{public}d, sensorId:%{public}d, timestamp:%{public}" PRId64,
ret, data.sensorTypeId, data.timestamp);
cacheBuf[sensorId] = data;
}
}

View File

@ -155,7 +155,7 @@ bool SensorManager::IsOtherClientUsingSensor(int32_t sensorId, int32_t clientPid
{
CALL_LOG_ENTER;
if (clientInfo_.OnlyCurPidSensorEnabled(sensorId, clientPid)) {
SEN_HILOGW("Only current client using this sensor");
SEN_HILOGD("Only current client using this sensor");
return false;
}
clientInfo_.ClearCurPidSensorInfo(sensorId, clientPid);

View File

@ -151,7 +151,7 @@ int32_t SensorBasicDataChannel::SendData(const void *vaddr, size_t size)
length = send(sendFd_, vaddr, size, MSG_DONTWAIT | MSG_NOSIGNAL);
} while (errno == EINTR);
if (length < 0) {
SEN_HILOGE("Send fail:%{public}d, length:%{public}d", errno, (int32_t)length);
SEN_HILOGD("Send fail:%{public}d, length:%{public}d", errno, (int32_t)length);
return SENSOR_CHANNEL_SEND_DATA_ERR;
}
return ERR_OK;