From 21f0a7731288e02cdb28a43a32e3f2ae554ecf49 Mon Sep 17 00:00:00 2001 From: houpengfei Date: Mon, 21 Mar 2022 14:57:44 +0000 Subject: [PATCH] Signed-off-by:hhh2 Signed-off-by: houpengfei Change-Id: I88cc1470ea4b456dfb64a01c2ac1c509205e7f01 --- .../sensor/src/sensor_service_client.cpp | 20 +++++++++---------- utils/include/sensors_errors.h | 18 +++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index ff57ee06..f813f235 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -40,7 +40,7 @@ constexpr uint32_t WAIT_MS = 200; int32_t SensorServiceClient::InitServiceClient() { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; std::lock_guard clientLock(clientMutex_); if (sensorServer_ != nullptr) { HiLog::Debug(LABEL, "%{public}s already init", __func__); @@ -91,7 +91,7 @@ bool SensorServiceClient::IsValidSensorId(uint32_t sensorId) int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -110,7 +110,7 @@ int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPer int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -129,7 +129,7 @@ int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int32_t params) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; if (!IsValidSensorId(sensorId)) { HiLog::Error(LABEL, "%{public}s sensorId is invalid", __func__); return SENSOR_NATIVE_SAM_ERR; @@ -149,7 +149,7 @@ int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int3 std::vector SensorServiceClient::GetSensorList() { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s InitServiceClient failed, ret : %{public}d", __func__, ret); @@ -163,7 +163,7 @@ std::vector SensorServiceClient::GetSensorList() int32_t SensorServiceClient::TransferDataChannel(sptr sensorDataChannel) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; dataChannel_ = sensorDataChannel; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { @@ -175,7 +175,7 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD int32_t SensorServiceClient::DestroyDataChannel() { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { HiLog::Error(LABEL, "%{public}s InitServiceClient failed, ret : %{public}d", __func__, ret); @@ -186,7 +186,7 @@ int32_t SensorServiceClient::DestroyDataChannel() void SensorServiceClient::ProcessDeathObserver(const wptr &object) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; (void)object; if (dataChannel_ == nullptr) { HiLog::Error(LABEL, "%{public}s dataChannel_ cannot be null", __func__); @@ -222,7 +222,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; std::lock_guard mapLock(mapMutex_); SensorBasicInfo sensorInfo; sensorInfo.SetSamplingPeriodNs(samplingPeriod); @@ -234,7 +234,7 @@ void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplin void SensorServiceClient::DeleteSensorInfoItem(uint32_t sensorId) { - HiLog::Debug(LABEL, "%{public}s begin", __func__); + CALL_LOG_ENTER; std::lock_guard mapLock(mapMutex_); auto it = sensorInfoMap_.find(sensorId); if (it != sensorInfoMap_.end()) { diff --git a/utils/include/sensors_errors.h b/utils/include/sensors_errors.h index 38a2d16b..d6e5ec6f 100644 --- a/utils/include/sensors_errors.h +++ b/utils/include/sensors_errors.h @@ -17,6 +17,7 @@ #define SENSORS_ERRORS_H #include +#include "hilog/log.h" namespace OHOS { namespace Sensors { @@ -105,6 +106,23 @@ enum { SENSOR_NATIVE_GET_SERVICE_ERR = SENSOR_NATIVE_SAM_ERR + 1, SENSOR_NATIVE_REGSITER_CB_ERR = SENSOR_NATIVE_GET_SERVICE_ERR + 1, }; + +class InnerFunctionTracer { +public: + InnerFunctionTracer(const OHOS::HiviewDFX::HiLogLabel& label, const char *func) + : label_ { label }, func_ { func } + { + OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, enter", func_); + } + ~InnerFunctionTracer() + { + OHOS::HiviewDFX::HiLog::Debug(label_, "in %{public}s, leave", func_); + } +private: + const OHOS::HiviewDFX::HiLogLabel& label_; + const char* func_ { nullptr }; +}; } // namespace Sensors } // namespace OHOS +#define CALL_LOG_ENTER InnerFunctionTracer ___innerFuncTracer___ { LABEL, __FUNCTION__ } #endif // SENSORS_ERRORS_H -- Gitee