From 9d1e0a5a7d9d3ec44fa96f2d976f466a5ed87cc1 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Wed, 8 Jun 2022 10:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0hitrace=E6=89=93=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chen0088 --- common/BUILD.gn | 2 + .../include/utils/dcamera_hitrace_adapter.h | 40 +++++++++++++++++++ common/src/utils/dcamera_hitrace_adapter.cpp | 35 ++++++++++++++++ services/cameraservice/sourceservice/BUILD.gn | 1 + .../distributed_camera_source_service.cpp | 2 + .../dcamera_source_dev.cpp | 4 ++ .../dcamera_source_controller.cpp | 3 ++ .../dcameradata/dcamera_source_input.cpp | 3 ++ .../dcamera_stream_data_process_producer.cpp | 2 + services/data_process/BUILD.gn | 1 + .../src/pipeline/dcamera_pipeline_sink.cpp | 3 ++ .../src/pipeline/dcamera_pipeline_source.cpp | 3 ++ 12 files changed, 99 insertions(+) create mode 100644 common/include/utils/dcamera_hitrace_adapter.h create mode 100644 common/src/utils/dcamera_hitrace_adapter.cpp diff --git a/common/BUILD.gn b/common/BUILD.gn index c8fdcf7..72344ca 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("distributed_camera_utils") { sources = [ "src/utils/data_buffer.cpp", "src/utils/dcamera_hisysevent_adapter.cpp", + "src/utils/dcamera_hitrace_adapter.cpp", "src/utils/dcamera_sa_process_state.cpp", "src/utils/dcamera_utils_tools.cpp", ] @@ -51,6 +52,7 @@ ohos_shared_library("distributed_camera_utils") { external_deps = [ "dsoftbus_standard:softbus_client", "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", ] diff --git a/common/include/utils/dcamera_hitrace_adapter.h b/common/include/utils/dcamera_hitrace_adapter.h new file mode 100644 index 0000000..e26dbe1 --- /dev/null +++ b/common/include/utils/dcamera_hitrace_adapter.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_DCAMERA_HITRACE_ADAPTER_H +#define OHOS_DCAMERA_HITRACE_ADAPTER_H + +#include + +#include "hitrace_meter.h" + +namespace OHOS { +namespace DistributedHardware { +constexpr uint64_t DCAMERA_HITRACE_LABEL = HITRACE_TAG_DISTRIBUTED_CAMERA; +const std::string DCAMERA_OPEN_CHANNEL_START = "DCAMERA_OPEN_CHANNEL_START"; +const std::string DCAMERA_INPUT_OPEN_START = "DCAMERA_INPUT_OPEN_START"; +const std::string DCAMERA_CAPTURE_FIRST_FRAME = "DCAMERA_CAPTURE_GET_FIRST_FRAME"; +enum DcameraTaskId { + DCAMERA_OPEN_CHANNEL_TASKID = 0, + DCAMERA_INPUT_OPEN_TASKID = 1, + DCAMERA_CAPTURE_FIRST_FRAM_TASKID = 2, +}; + +void DcameraSyncTrace(); +void DcameraStartAsyncTrace(const std::string& str, int32_t taskId); +void DcameraFinishAsyncTrace(const std::string& str, int32_t taskId); +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_HITRACE_ADAPTER_H \ No newline at end of file diff --git a/common/src/utils/dcamera_hitrace_adapter.cpp b/common/src/utils/dcamera_hitrace_adapter.cpp new file mode 100644 index 0000000..c9be808 --- /dev/null +++ b/common/src/utils/dcamera_hitrace_adapter.cpp @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#include "dcamera_hitrace_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +void DcameraSyncTrace() +{ + HITRACE_METER(DCAMERA_HITRACE_LABEL); +} + +void DcameraStartAsyncTrace(const std::string& str, int32_t taskId) +{ + StartAsyncTrace(DCAMERA_HITRACE_LABEL, str, taskId, -1); +} + +void DcameraFinishAsyncTrace(const std::string& str, int32_t taskId) +{ + FinishAsyncTrace(DCAMERA_HITRACE_LABEL, str, taskId); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 0449bf6..1f42750 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -107,6 +107,7 @@ ohos_shared_library("distributed_camera_source") { "device_driver_framework:libhdf_utils", "device_driver_framework:libhdi", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index db1905f..4de7a15 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -25,6 +25,7 @@ #include "anonymous_string.h" #include "dcamera_hdf_operate.h" #include "dcamera_hisysevent_adapter.h" +#include "dcamera_hitrace_adapter.h" #include "dcamera_service_state_listener.h" #include "dcamera_source_service_ipc.h" #include "distributed_camera_errno.h" @@ -194,6 +195,7 @@ int32_t DistributedCameraSourceService::DCameraNotify(const std::string& devId, int32_t DistributedCameraSourceService::LoadDCameraHDF() { + DcameraSyncTrace(); DHLOGI("load hdf driver start"); int32_t ret = DCameraHdfOperate::GetInstance().LoadDcameraHDFImpl(); if (ret != DCAMERA_OK) { diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp index b8ce763..9992e15 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamera_source_dev.cpp @@ -17,6 +17,7 @@ #include "anonymous_string.h" #include "dcamera_hisysevent_adapter.h" +#include "dcamera_hitrace_adapter.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -214,6 +215,7 @@ void DCameraSourceDev::OnEvent(DCameraSourceEvent& event) int32_t DCameraSourceDev::ExecuteRegister(std::shared_ptr& param) { + DcameraSyncTrace(); DHLOGI("DCameraSourceDev Execute Register devId: %s dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); ReportRegisterCameraEvent(REGIST_CAMERA_EVENT, GetAnonyString(devId_), dhId_, @@ -259,6 +261,7 @@ int32_t DCameraSourceDev::ExecuteRegister(std::shared_ptr& p int32_t DCameraSourceDev::ExecuteUnRegister(std::shared_ptr& param) { + DcameraSyncTrace(); DHLOGI("DCameraSourceDev Execute UnRegister devId: %s dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); ReportRegisterCameraEvent(UNREGIST_CAMERA_EVENT, GetAnonyString(devId_), dhId_, @@ -403,6 +406,7 @@ int32_t DCameraSourceDev::ExecuteReleaseAllStreams() int32_t DCameraSourceDev::ExecuteStartCapture(std::vector>& captureInfos) { + DcameraStartAsyncTrace(DCAMERA_CAPTURE_FIRST_FRAME, DCAMERA_CAPTURE_FIRST_FRAM_TASKID); DHLOGI("DCameraSourceDev Execute StartCapture devId %s dhId %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); int32_t ret = input_->StartCapture(captureInfos); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 9bc9f9c..3cc3fb0 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -20,6 +20,7 @@ #include "dcamera_capture_info_cmd.h" #include "dcamera_channel_source_impl.h" +#include "dcamera_hitrace_adapter.h" #include "dcamera_metadata_setting_cmd.h" #include "dcamera_protocol.h" #include "dcamera_source_controller_channel_listener.h" @@ -264,6 +265,7 @@ int32_t DCameraSourceController::GetCameraInfo(std::shared_ptr& cam int32_t DCameraSourceController::OpenChannel(std::shared_ptr& openInfo) { + DcameraStartAsyncTrace(DCAMERA_OPEN_CHANNEL_START, DCAMERA_OPEN_CHANNEL_TASKID); if (indexs_.size() > DCAMERA_MAX_NUM) { DHLOGE("DCameraSourceController OpenChannel not support operate %d camera", indexs_.size()); return DCAMERA_BAD_OPERATE; @@ -381,6 +383,7 @@ void DCameraSourceController::OnSessionState(int32_t state) channelState_ = state; switch (state) { case DCAMERA_CHANNEL_STATE_CONNECTED: { + DcameraFinishAsyncTrace(DCAMERA_OPEN_CHANNEL_START, DCAMERA_OPEN_CHANNEL_TASKID); stateMachine_->UpdateState(DCAMERA_STATE_OPENED); std::shared_ptr camEvent = std::make_shared(); camEvent->eventType_ = DCAMERA_MESSAGE; diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp index 84322cf..8eaa40d 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_source_input.cpp @@ -16,6 +16,7 @@ #include "dcamera_source_input.h" #include "anonymous_string.h" +#include "dcamera_hitrace_adapter.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -179,6 +180,7 @@ int32_t DCameraSourceInput::StopCapture(std::vector& streamIds, bool& isAll int32_t DCameraSourceInput::OpenChannel(std::vector& indexs) { + DcameraStartAsyncTrace(DCAMERA_INPUT_OPEN_START, DCAMERA_INPUT_OPEN_TASKID); DHLOGI("DCameraSourceInput OpenChannel devId %s dhId %s continue state: %d, snapshot state: %d", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), channelState_[CONTINUOUS_FRAME], channelState_[SNAPSHOT_FRAME]); @@ -324,6 +326,7 @@ void DCameraSourceInput::OnSessionState(DCStreamType streamType, int32_t state) break; } default: { + DcameraFinishAsyncTrace(DCAMERA_INPUT_OPEN_START, DCAMERA_INPUT_OPEN_TASKID); DHLOGI("DCameraSourceInput OnSessionState state %d", state); break; } diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp index 134dac4..41cad24 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp @@ -19,6 +19,7 @@ #include #include "anonymous_string.h" +#include "dcamera_hitrace_adapter.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -175,6 +176,7 @@ void DCameraStreamDataProcessProducer::LooperSnapShot() GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId_, state_); continue; } + DcameraFinishAsyncTrace(DCAMERA_CAPTURE_FIRST_FRAME, DCAMERA_CAPTURE_FIRST_FRAM_TASKID); int32_t ret = FeedStreamToDriver(dhBase, buffer); if (ret != DCAMERA_OK) { std::this_thread::sleep_for(std::chrono::milliseconds(DCAMERA_PRODUCER_RETRY_SLEEP_MS)); diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index 2712354..4fd4944 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -84,6 +84,7 @@ ohos_shared_library("distributed_camera_data_process") { external_deps = [ "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "multimedia_media_standard:media_client", ] diff --git a/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp b/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp index a6119a0..b4d4536 100644 --- a/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp +++ b/services/data_process/src/pipeline/dcamera_pipeline_sink.cpp @@ -15,6 +15,7 @@ #include "dcamera_pipeline_sink.h" +#include "dcamera_hitrace_adapter.h" #include "distributed_hardware_log.h" #include "encode_data_process.h" @@ -35,6 +36,7 @@ int32_t DCameraPipelineSink::CreateDataProcessPipeline(PipelineType piplineType, const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig, const std::shared_ptr& listener) { + DcameraSyncTrace(); DHLOGD("Create sink data process pipeline."); switch (piplineType) { case PipelineType::VIDEO: @@ -146,6 +148,7 @@ int32_t DCameraPipelineSink::ProcessData(std::vector void DCameraPipelineSink::DestroyDataProcessPipeline() { + DcameraSyncTrace(); DHLOGD("Destroy sink data process pipeline start."); isProcess_ = false; if (pipelineHead_ != nullptr) { diff --git a/services/data_process/src/pipeline/dcamera_pipeline_source.cpp b/services/data_process/src/pipeline/dcamera_pipeline_source.cpp index 2bdd225..d03e70e 100644 --- a/services/data_process/src/pipeline/dcamera_pipeline_source.cpp +++ b/services/data_process/src/pipeline/dcamera_pipeline_source.cpp @@ -15,6 +15,7 @@ #include "dcamera_pipeline_source.h" +#include "dcamera_hitrace_adapter.h" #include "distributed_hardware_log.h" #include "color_format_process.h" @@ -37,6 +38,7 @@ int32_t DCameraPipelineSource::CreateDataProcessPipeline(PipelineType piplineTyp const VideoConfigParams& sourceConfig, const VideoConfigParams& targetConfig, const std::shared_ptr& listener) { + DcameraSyncTrace(); DHLOGD("Create source data process pipeline."); switch (piplineType) { case PipelineType::VIDEO: @@ -168,6 +170,7 @@ int32_t DCameraPipelineSource::ProcessData(std::vector