diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index dd5176e7bdb90a8ae1d0bcc401b832ee8a1e4476..6ee82e32020891ea186fbe049166a66b5e5d6304 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -56,7 +56,6 @@ ohos_shared_library("libsensor_client") { "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_single", "samgr:samgr_proxy", ] @@ -65,6 +64,10 @@ ohos_shared_library("libsensor_client") { external_deps += [ "hisysevent:libhisysevent" ] } + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + innerapi_tags = [ "platformsdk_indirect" ] part_name = "sensor" subsystem_name = "sensors" diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index a616d42a9a69413f1104e74f8100d6dea19354ad..1dc3da36b9d783baf2746d8bf6cd407872bed0d8 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -59,6 +59,7 @@ private: int32_t InitServiceClient(); void UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); void DeleteSensorInfoItem(int32_t sensorId); + int32_t CreateSocketClientFd(int32_t &clientFd); int32_t CreateSocketChannel(); std::mutex clientMutex_; sptr serviceDeathObserver_ = nullptr; diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 4afdbe6c3c090c3b95026b389cb1f0a24b9aa86a..f3a329cfefca696a36baf01cfefe5fc671efaff2 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -24,7 +24,9 @@ #ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" #endif // HIVIEWDFX_HISYSEVENT_ENABLE +#ifdef HIVIEWDFX_HITRACE_ENABLE #include "hitrace_meter.h" +#endif // HIVIEWDFX_HITRACE_ENABLE #include "ipc_skeleton.h" #include "sensor_errors.h" #include "sensor_service_proxy.h" @@ -136,9 +138,13 @@ int32_t SensorServiceClient::EnableSensor(int32_t sensorId, int64_t samplingPeri } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "EnableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->EnableSensor(sensorId, samplingPeriod, maxReportDelay); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret == ERR_OK) { UpdateSensorInfoMap(sensorId, samplingPeriod, maxReportDelay); } @@ -155,9 +161,13 @@ int32_t SensorServiceClient::DisableSensor(int32_t sensorId) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DisableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->DisableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret == ERR_OK) { DeleteSensorInfoItem(sensorId); } @@ -194,12 +204,16 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "TransferDataChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(sensorClientStub_, INVALID_POINTER); auto remoteObject = sensorClientStub_->AsObject(); CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->TransferDataChannel(sensorDataChannel, remoteObject); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -213,12 +227,16 @@ int32_t SensorServiceClient::DestroyDataChannel() } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DestroyDataChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(sensorClientStub_, INVALID_POINTER); auto remoteObject = sensorClientStub_->AsObject(); CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->DestroySensorChannel(remoteObject); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -307,9 +325,13 @@ int32_t SensorServiceClient::SuspendSensors(int32_t pid) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "SuspendSensors"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->SuspendSensors(pid); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -323,9 +345,13 @@ int32_t SensorServiceClient::ResumeSensors(int32_t pid) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "ResumeSensors"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->ResumeSensors(pid); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -339,9 +365,13 @@ int32_t SensorServiceClient::GetActiveInfoList(int32_t pid, std::vector clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "GetActiveInfoList"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->GetActiveInfoList(pid, activeInfoList); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -382,20 +412,28 @@ int32_t SensorServiceClient::Unregister(SensorActiveInfoCB callback) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DisableActiveInfoCB"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->DisableActiveInfoCB(); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Disable active info callback failed, ret:%{public}d", ret); return ret; } Disconnect(); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DestroySocketChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(sensorClientStub_, INVALID_POINTER); auto remoteObject = sensorClientStub_->AsObject(); CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->DestroySocketChannel(remoteObject); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Destroy socket channel failed, ret:%{public}d", ret); return ret; @@ -414,9 +452,13 @@ int32_t SensorServiceClient::ResetSensors() } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "ResetSensors"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->ResetSensors(); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -482,6 +524,21 @@ void SensorServiceClient::Disconnect() Close(); } +int32_t SensorServiceClient::CreateSocketClientFd(int32_t &clientFd) +{ +#ifdef HIVIEWDFX_HITRACE_ENABLE + StartTrace(HITRACE_TAG_SENSORS, "CreateSocketChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE + CHKPR(sensorClientStub_, INVALID_POINTER); + auto remoteObject = sensorClientStub_->AsObject(); + CHKPR(remoteObject, INVALID_POINTER); + int ret = sensorServer_->CreateSocketChannel(remoteObject, clientFd); +#ifdef HIVIEWDFX_HITRACE_ENABLE + FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE + return ret; +} + int32_t SensorServiceClient::CreateSocketChannel() { CALL_LOG_ENTER; @@ -493,12 +550,7 @@ int32_t SensorServiceClient::CreateSocketChannel() std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); int32_t clientFd = -1; - StartTrace(HITRACE_TAG_SENSORS, "CreateSocketChannel"); - CHKPR(sensorClientStub_, INVALID_POINTER); - auto remoteObject = sensorClientStub_->AsObject(); - CHKPR(remoteObject, INVALID_POINTER); - ret = sensorServer_->CreateSocketChannel(remoteObject, clientFd); - FinishTrace(HITRACE_TAG_SENSORS); + ret = CreateSocketClientFd(clientFd); if (ret != ERR_OK || clientFd < 0) { Close(); SEN_HILOGE("Create socket channel failed, ret:%{public}d", ret); @@ -519,9 +571,13 @@ int32_t SensorServiceClient::CreateSocketChannel() return ERROR; } } +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "EnableActiveInfoCB"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->EnableActiveInfoCB(); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Enable active info callback failed, ret:%{public}d", ret); Disconnect(); diff --git a/sensor.gni b/sensor.gni index 22c912e207614db9382d04b06570ff336038943f..0f548ad66c61beecf5874fd2033d21671fddba51 100644 --- a/sensor.gni +++ b/sensor.gni @@ -16,6 +16,7 @@ import("//build/ohos.gni") declare_args() { hiviewdfx_hisysevent_enable = false sensor_rust_socket_ipc = false + hiviewdfx_hitrace_enable = false } SUBSYSTEM_DIR = "//base/sensors/sensor" @@ -55,3 +56,9 @@ if (defined(global_parts_info) && hiviewdfx_hisysevent_enable = true sensor_default_defines += [ "HIVIEWDFX_HISYSEVENT_ENABLE" ] } + +if (defined(global_parts_info) && + defined(global_parts_info.hiviewdfx_hitrace)) { + hiviewdfx_hitrace_enable = true + sensor_default_defines += [ "HIVIEWDFX_HITRACE_ENABLE" ] +} diff --git a/services/BUILD.gn b/services/BUILD.gn index 685063ba0a9d14884f24aca2f3603681ea92332d..31681dd02c5090dc878a5515ff493f69f6d68b49 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -59,7 +59,6 @@ ohos_shared_library("libsensor_service") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", @@ -74,6 +73,10 @@ ohos_shared_library("libsensor_service") { external_deps += [ "hisysevent:libhisysevent" ] } + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", @@ -151,7 +154,6 @@ ohos_static_library("libsensor_service_static") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", @@ -166,6 +168,10 @@ ohos_static_library("libsensor_service_static") { external_deps += [ "hisysevent:libhisysevent" ] } + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 0f755ac9b2e107648309d81c8906864799afcf31..65568e3377af5302aa06c9739a232a1c1b510612 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -19,7 +19,9 @@ #endif // BUILD_VARIANT_ENG #include "hdi_connection.h" +#ifdef HIVIEWDFX_HITRACE_ENABLE #include "hitrace_meter.h" +#endif // HIVIEWDFX_HITRACE_ENABLE #include "sensor_errors.h" #undef LOG_TAG @@ -230,13 +232,17 @@ int32_t SensorHdiConnection::GetSensorList(std::vector &sensorList) int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "EnableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = ENABLE_SENSOR_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, ENABLE_SENSOR_ERR); ret = iSensorCompatibleHdiConnection_->EnableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Enable sensor failed in compatible, sensorId:%{public}d", sensorId); return ENABLE_SENSOR_ERR; @@ -246,7 +252,9 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, ENABLE_SENSOR_ERR); ret = iSensorHdiConnection_->EnableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Enable sensor failed, sensorId:%{public}d", sensorId); return ENABLE_SENSOR_ERR; @@ -256,13 +264,17 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DisableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = DISABLE_SENSOR_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, DISABLE_SENSOR_ERR); ret = iSensorCompatibleHdiConnection_->DisableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Disable sensor failed in compatible, sensorId:%{public}d", sensorId); return DISABLE_SENSOR_ERR; @@ -272,7 +284,9 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, DISABLE_SENSOR_ERR); ret = iSensorHdiConnection_->DisableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Disable sensor failed, sensorId:%{public}d", sensorId); return DISABLE_SENSOR_ERR; @@ -282,13 +296,17 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "SetBatch"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = SET_SENSOR_CONFIG_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_CONFIG_ERR); ret = iSensorCompatibleHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set batch failed in compatible, sensorId:%{public}d", sensorId); return SET_SENSOR_CONFIG_ERR; @@ -298,7 +316,9 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, SET_SENSOR_CONFIG_ERR); ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set batch failed, sensorId:%{public}d", sensorId); return SET_SENSOR_CONFIG_ERR; @@ -308,13 +328,17 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "SetMode"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = SET_SENSOR_MODE_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_MODE_ERR); ret = iSensorCompatibleHdiConnection_->SetMode(sensorId, mode); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set mode failed, sensorId:%{public}d", sensorId); return SET_SENSOR_MODE_ERR; @@ -324,7 +348,9 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, SET_SENSOR_MODE_ERR); ret = iSensorHdiConnection_->SetMode(sensorId, mode); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set mode failed, sensorId:%{public}d", sensorId); return SET_SENSOR_MODE_ERR; @@ -334,7 +360,9 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "RegisterDataReport"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(iSensorHdiConnection_, REGIST_CALLBACK_ERR); int32_t ret = iSensorHdiConnection_->RegisterDataReport(cb, reportDataCallback); if (ret != ERR_OK) { @@ -350,7 +378,9 @@ int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr