From a063aff676da6bb44e6f519555acd61d66cdaaf8 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 31 May 2022 09:10:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?sensorHiTrace=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- frameworks/native/sensor/BUILD.gn | 1 + .../sensor/src/sensor_service_client.cpp | 15 +++++++++-- services/sensor/BUILD.gn | 1 + .../interface/src/sensor_hdi_connection.cpp | 15 +++++++++++ utils/BUILD.gn | 1 + utils/include/sensor_trace.h | 27 +++++++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 utils/include/sensor_trace.h diff --git a/frameworks/native/sensor/BUILD.gn b/frameworks/native/sensor/BUILD.gn index 9374dd92..cccdd3b7 100644 --- a/frameworks/native/sensor/BUILD.gn +++ b/frameworks/native/sensor/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("libsensor_native") { external_deps = [ "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", + "hitrace_native:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index 84f2b2a5..1dafb8cb 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,9 @@ int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPer SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + HITRACE_BEGIN("EnableSensor"); ret = sensorServer_->EnableSensor(sensorId, samplingPeriod, maxReportDelay); + HITRACE_END(); if (ret == ERR_OK) { UpdateSensorInfoMap(sensorId, samplingPeriod, maxReportDelay); } @@ -122,7 +125,9 @@ int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + HITRACE_BEGIN("DisableSensor"); ret = sensorServer_->DisableSensor(sensorId); + HITRACE_END(); if (ret == ERR_OK) { DeleteSensorInfoItem(sensorId); } @@ -172,7 +177,10 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } - return sensorServer_->TransferDataChannel(sensorDataChannel, sensorClientStub_); + HITRACE_BEGIN("TransferDataChannel"); + ret = sensorServer_->TransferDataChannel(sensorDataChannel, sensorClientStub_); + HITRACE_END(); + return ret; } int32_t SensorServiceClient::DestroyDataChannel() @@ -183,7 +191,10 @@ int32_t SensorServiceClient::DestroyDataChannel() SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } - return sensorServer_->DestroySensorChannel(sensorClientStub_); + 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 13b52bfd..120beea5 100644 --- a/services/sensor/BUILD.gn +++ b/services/sensor/BUILD.gn @@ -55,6 +55,7 @@ ohos_shared_library("libsensor_service") { "bundle_framework:appexecfwk_core", "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", + "hitrace_native:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", 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 43306461..39858c3f 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 47a848e2..7fbdc4a1 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 00000000..70e0e1bc --- /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 -- Gitee From 5fb52acffa10a5e2b006bec4dca1cd97fae523cc Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 31 May 2022 09:18:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?HiTrace=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- frameworks/native/sensor/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/BUILD.gn b/frameworks/native/sensor/BUILD.gn index cccdd3b7..59063bb7 100644 --- a/frameworks/native/sensor/BUILD.gn +++ b/frameworks/native/sensor/BUILD.gn @@ -41,8 +41,8 @@ ohos_shared_library("libsensor_native") { external_deps = [ "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", -- Gitee From 35b7a3ff8fc212d6278c44e6cd9cf64464555fb3 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 31 May 2022 09:32:47 +0800 Subject: [PATCH 3/4] =?UTF-8?q?HiTrace=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- services/sensor/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/sensor/BUILD.gn b/services/sensor/BUILD.gn index 120beea5..ee9b2841 100644 --- a/services/sensor/BUILD.gn +++ b/services/sensor/BUILD.gn @@ -54,8 +54,8 @@ ohos_shared_library("libsensor_service") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "hisysevent_native:libhisysevent", - "hiviewdfx_hilog_native:libhilog", "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", -- Gitee From 7b4d123893b352820f924a29f46bcc46958b7b79 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 31 May 2022 10:40:00 +0800 Subject: [PATCH 4/4] =?UTF-8?q?HiTrace=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cff-gite --- frameworks/native/sensor/src/sensor_service_client.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index 1dafb8cb..11ca407d 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -104,6 +104,7 @@ 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(); @@ -125,6 +126,7 @@ 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(); @@ -146,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; @@ -177,6 +182,7 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + CHKPR(sensorServer_, ERROR); HITRACE_BEGIN("TransferDataChannel"); ret = sensorServer_->TransferDataChannel(sensorDataChannel, sensorClientStub_); HITRACE_END(); @@ -191,6 +197,7 @@ int32_t SensorServiceClient::DestroyDataChannel() SEN_HILOGE("InitServiceClient failed, ret : %{public}d", ret); return ret; } + CHKPR(sensorServer_, ERROR); HITRACE_BEGIN("DestroyDataChannel"); ret = sensorServer_->DestroySensorChannel(sensorClientStub_); HITRACE_END(); -- Gitee