diff --git a/frameworks/native/sensor/BUILD.gn b/frameworks/native/sensor/BUILD.gn index 9374dd92f1b05984d8f34cc13d55bd7500d80e7a..59063bb7ac122dc2a6bcb644aa57031e479f1d4b 100644 --- a/frameworks/native/sensor/BUILD.gn +++ b/frameworks/native/sensor/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("libsensor_native") { external_deps = [ "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index 84f2b2a596f4424a0950cef86346f4b66acb4bb0..11ca407dc6b563b0b6188f0185d464e8b9e0bae0 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -24,6 +24,7 @@ #include "dmd_report.h" #include "ipc_skeleton.h" #include "sensor_service_proxy.h" +#include "sensor_trace.h" #include "sensors_errors.h" #include "sensors_log_domain.h" #include "system_ability_definition.h" @@ -103,7 +104,10 @@ int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPer SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + CHKPR(sensorServer_, ERROR); + HITRACE_BEGIN("EnableSensor"); ret = sensorServer_->EnableSensor(sensorId, samplingPeriod, maxReportDelay); + HITRACE_END(); if (ret == ERR_OK) { UpdateSensorInfoMap(sensorId, samplingPeriod, maxReportDelay); } @@ -122,7 +126,10 @@ int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + CHKPR(sensorServer_, ERROR); + HITRACE_BEGIN("DisableSensor"); ret = sensorServer_->DisableSensor(sensorId); + HITRACE_END(); if (ret == ERR_OK) { DeleteSensorInfoItem(sensorId); } @@ -141,7 +148,10 @@ int32_t SensorServiceClient::RunCommand(uint32_t sensorId, int32_t cmdType, int3 SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + CHKPR(sensorServer_, ERROR); + HITRACE_BEGIN("RunCommand"); ret = sensorServer_->RunCommand(sensorId, cmdType, params); + HITRACE_END(); if (ret != ERR_OK) { SEN_HILOGE("RunCommand failed"); return ret; @@ -172,7 +182,11 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } - return sensorServer_->TransferDataChannel(sensorDataChannel, sensorClientStub_); + CHKPR(sensorServer_, ERROR); + HITRACE_BEGIN("TransferDataChannel"); + ret = sensorServer_->TransferDataChannel(sensorDataChannel, sensorClientStub_); + HITRACE_END(); + return ret; } int32_t SensorServiceClient::DestroyDataChannel() @@ -183,7 +197,11 @@ int32_t SensorServiceClient::DestroyDataChannel() SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } - return sensorServer_->DestroySensorChannel(sensorClientStub_); + CHKPR(sensorServer_, ERROR); + HITRACE_BEGIN("DestroyDataChannel"); + ret = sensorServer_->DestroySensorChannel(sensorClientStub_); + HITRACE_END(); + return ret; } void SensorServiceClient::ProcessDeathObserver(const wptr &object) diff --git a/services/sensor/BUILD.gn b/services/sensor/BUILD.gn index 13b52bfdb16140a2279c6d1f79c85ebe6fa9faa6..ee9b2841c0b97a124abbbb7a139721e45b7059f9 100644 --- a/services/sensor/BUILD.gn +++ b/services/sensor/BUILD.gn @@ -54,6 +54,7 @@ ohos_shared_library("libsensor_service") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp index 43306461770d106bd9b4f9c4d7feb3d17d7aa3f7..39858c3fae95b8a8c724560fca6235fc66295a37 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -16,6 +16,7 @@ #include "compatible_connection.h" #include "hdi_connection.h" +#include "sensor_trace.h" #include "sensors_errors.h" #include "sensors_log_domain.h" @@ -65,7 +66,9 @@ int32_t SensorHdiConnection::GetSensorList(std::vector& sensorList) int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) { + HITRACE_BEGIN("EnableSensor"); int32_t ret = iSensorHdiConnection_->EnableSensor(sensorId); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("enable sensor failed, sensorId: %{public}d", sensorId); return ENABLE_SENSOR_ERR; @@ -75,7 +78,9 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) { + HITRACE_BEGIN("DisableSensor"); int32_t ret = iSensorHdiConnection_->DisableSensor(sensorId); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("disable sensor failed, sensorId: %{public}d", sensorId); return DISABLE_SENSOR_ERR; @@ -85,7 +90,9 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) { + HITRACE_BEGIN("SetBatch"); int32_t ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("set batch failed, sensorId: %{public}d", sensorId); return SET_SENSOR_CONFIG_ERR; @@ -95,7 +102,9 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) { + HITRACE_BEGIN("SetMode"); int32_t ret = iSensorHdiConnection_->SetMode(sensorId, mode); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("set mode failed, sensorId: %{public}d", sensorId); return SET_SENSOR_MODE_ERR; @@ -105,7 +114,9 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) int32_t SensorHdiConnection::SetOption(int32_t sensorId, int32_t option) { + HITRACE_BEGIN("SetOption"); int32_t ret = iSensorHdiConnection_->SetOption(sensorId, option); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("set option failed, sensorId: %{public}d", sensorId); return SET_SENSOR_OPTION_ERR; @@ -115,7 +126,9 @@ int32_t SensorHdiConnection::SetOption(int32_t sensorId, int32_t option) int32_t SensorHdiConnection::RunCommand(int32_t sensorId, int32_t cmd, int32_t params) { + HITRACE_BEGIN("RunCommand"); int32_t ret = iSensorHdiConnection_->RunCommand(sensorId, cmd, params); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("run command failed, sensorId: %{public}d", sensorId); return RUN_COMMAND_ERR; @@ -125,7 +138,9 @@ int32_t SensorHdiConnection::RunCommand(int32_t sensorId, int32_t cmd, int32_t p int32_t SensorHdiConnection::RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) { + HITRACE_BEGIN("RegisteDataReport"); int32_t ret = iSensorHdiConnection_->RegisteDataReport(cb, reportDataCallback); + HITRACE_END(); if (ret != 0) { SEN_HILOGI("registe dataReport failed"); return REGIST_CALLBACK_ERR; diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 47a848e29302856c49a1aa2ba58373826648422d..7fbdc4a1cf42246d0e8e86a2a21be7697b09ddef 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -36,6 +36,7 @@ ohos_shared_library("libsensor_utils") { external_deps = [ "access_token:libaccesstoken_sdk", "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/utils/include/sensor_trace.h b/utils/include/sensor_trace.h new file mode 100644 index 0000000000000000000000000000000000000000..70e0e1bc4ec0cc5eedd666e15aaef032ff0a6a12 --- /dev/null +++ b/utils/include/sensor_trace.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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 SENSOR_TRACE_H +#define SENSOR_TRACE_H + +#include "hitrace_meter.h" + +namespace OHOS { +namespace Sensors { +#define HITRACE_BEGIN(name) StartTrace(HITRACE_TAG_SENSORS, name) +#define HITRACE_END() FinishTrace(HITRACE_TAG_SENSORS) +} // namespace Sensors +} // namespace OHOS +#endif // SENSOR_TRACE_H \ No newline at end of file