diff --git a/frameworks/native/screen_capture/screen_capture_impl.cpp b/frameworks/native/screen_capture/screen_capture_impl.cpp index 7346be8c8636e56e6439d66011db699f20b9716c..0477438ccfee05008aa343583702d71e627aab5b 100644 --- a/frameworks/native/screen_capture/screen_capture_impl.cpp +++ b/frameworks/native/screen_capture/screen_capture_impl.cpp @@ -39,6 +39,7 @@ std::shared_ptr ScreenCaptureFactory::CreateScreenCapture() int32_t ScreenCaptureImpl::Init() { MEDIA_LOGD("ScreenCaptureImpl:0x%{public}06" PRIXPTR " Init in", FAKE_POINTER(this)); + HiTraceChain::SetId(traceId_); screenCaptureService_ = MediaServiceFactory::GetInstance().CreateScreenCaptureService(); CHECK_AND_RETURN_RET_LOG(screenCaptureService_ != nullptr, MSERR_UNKNOWN, "failed to create ScreenCapture service"); @@ -58,7 +59,6 @@ ScreenCaptureImpl::ScreenCaptureImpl() { MEDIA_LOGD("ScreenCaptureImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this)); traceId_ = HiTraceChain::Begin("AVScreenCapture", HITRACE_FLAG_DEFAULT); - HiTraceChain::SetId(traceId_); } ScreenCaptureImpl::~ScreenCaptureImpl() diff --git a/services/services/BUILD.gn b/services/services/BUILD.gn index 546fd6eaf8085ae565a6cc473b9c7ff0af6af2d3..a444ef0fc55aa2e6e9b4d15474417f02b05487aa 100644 --- a/services/services/BUILD.gn +++ b/services/services/BUILD.gn @@ -202,6 +202,7 @@ ohos_shared_library("media_service") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "hitrace:libhitracechain", "image_framework:image_native", "init:libbegetutil", "ipc:ipc_single", diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index 672853412de2726043befcdfc42d8167ee5f239c..58d76f0032f2d029ba8fa028a8040c50d5af72f6 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -31,6 +31,7 @@ #include "param_wrapper.h" #include #include +#include "hitrace/tracechain.h" using OHOS::Rosen::DMError; @@ -229,15 +230,16 @@ void ScreenCaptureServer::SetMetaDataReport() meta->SetData(Tag::SCREEN_CAPTURE_VIDEO_RESOLUTION, statisticalEventInfo_.videoResolution); meta->SetData(Tag::SCREEN_CAPTURE_STOP_REASON, statisticalEventInfo_.stopReason); meta->SetData(Tag::SCREEN_CAPTURE_START_LATENCY, statisticalEventInfo_.startLatency); - AppendMediaInfo(meta); - ReportMediaInfo(); + AppendMediaInfo(meta, instanceId_); + ReportMediaInfo(instanceId_); } ScreenCaptureServer::ScreenCaptureServer() { MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this)); InitAppInfo(); - CreateMediaInfo(SCREEN_CAPTRUER, IPCSkeleton::GetCallingUid()); + instanceId_ = OHOS::HiviewDFX::HiTraceChain::GetId().GetChainId(); + CreateMediaInfo(SCREEN_CAPTRUER, IPCSkeleton::GetCallingUid(), instanceId_); } ScreenCaptureServer::~ScreenCaptureServer() @@ -292,13 +294,13 @@ int32_t ScreenCaptureServer::SetRecorderInfo(RecorderInfo recorderInfo) fileFormat_ = OutputFormatType::FORMAT_MPEG_4; } else if (M4A.compare(recorderInfo.fileFormat) == 0) { MEDIA_LOGI("only recorder audio, still not support"); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNSUPPORT, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNSUPPORT, "only recorder audio, still not support"); return MSERR_UNSUPPORT; } else { MEDIA_LOGE("invalid fileFormat type"); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, - "invalid fileFormat type"); + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, + SCREEN_CAPTURE_ERR_INVALID_VAL, "invalid fileFormat type"); return MSERR_INVALID_VAL; } MEDIA_LOGI("ScreenCaptureServer: 0x%{public}06" PRIXPTR "SetRecorderInfo OK.", FAKE_POINTER(this)); @@ -313,21 +315,21 @@ int32_t ScreenCaptureServer::SetOutputFile(int32_t outputFd) MEDIA_LOGI("ScreenCaptureServer::SetOutputFile start"); if (outputFd < 0) { MEDIA_LOGI("invalid outputFd"); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, - "invalid outputFd"); + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, + SCREEN_CAPTURE_ERR_INVALID_VAL, "invalid outputFd"); return MSERR_INVALID_VAL; } int flags = fcntl(outputFd, F_GETFL); if (flags == -1) { MEDIA_LOGE("Fail to get File Status Flags"); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "Fail to get File Status Flags"); return MSERR_INVALID_VAL; } if ((static_cast(flags) & (O_RDWR | O_WRONLY)) == 0) { MEDIA_LOGE("File descriptor is not in read-write mode or write-only mode"); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "File descriptor is not in read-write mode or write-only mode"); return MSERR_INVALID_VAL; } @@ -628,25 +630,25 @@ int32_t ScreenCaptureServer::CheckCaptureStreamParams() // surface mode, surface must not nullptr and videoCapInfo must valid. if (surface_ == nullptr || captureConfig_.videoInfo.videoCapInfo.state != AVScreenCaptureParamValidationState::VALIDATION_VALID) { - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "video Cap state fault, videoCapInfo is invalid"); return MSERR_INVALID_VAL; } } if (captureConfig_.audioInfo.innerCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID || captureConfig_.videoInfo.videoCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID) { - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "audio inner cap or video cap state invalid"); return MSERR_INVALID_VAL; } if (captureConfig_.audioInfo.innerCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_IGNORE && captureConfig_.videoInfo.videoCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_IGNORE) { - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "audio inner cap or video cap state ignore"); return MSERR_INVALID_VAL; } if (captureConfig_.audioInfo.innerCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID) { - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "audio inner cap state invalid"); return MSERR_INVALID_VAL; } @@ -675,12 +677,12 @@ int32_t ScreenCaptureServer::CheckCaptureFileParams() captureConfig_.videoInfo.videoCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID || captureConfig_.audioInfo.audioEncInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID || captureConfig_.videoInfo.videoEncInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID) { - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "innerCap audioEnc videoCap videoEnc state invalid"); return MSERR_INVALID_VAL; } if (captureConfig_.audioInfo.micCapInfo.state == AVScreenCaptureParamValidationState::VALIDATION_INVALID) { - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "audio mic cap state invalid"); return MSERR_INVALID_VAL; } @@ -694,7 +696,7 @@ int32_t ScreenCaptureServer::CheckCaptureFileParams() return MSERR_OK; } MEDIA_LOGE("CheckCaptureFileParams failed, inner and mic param not consistent"); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_INVALID_VAL, "CheckCaptureFileParams failed, inner and mic param not consistent"); return MSERR_INVALID_VAL; } @@ -1069,7 +1071,7 @@ int32_t ScreenCaptureServer::InitRecorder() MEDIA_LOGE("InitRecorder not VALIDATION_VALID"); return MSERR_UNKNOWN; } - + ret = recorder_->SetVideoSource(captureConfig_.videoInfo.videoCapInfo.videoSource, videoSourceId_); CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "SetVideoSource failed"); @@ -1121,7 +1123,7 @@ int32_t ScreenCaptureServer::StartScreenCaptureInner(bool isPrivacyAuthorityEnab if (InCallObserver::GetInstance().IsInCall()) { MEDIA_LOGI("ScreenCaptureServer Start InCall Abort"); screenCaptureCb_->OnStateChange(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_STOPPED_BY_CALL); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNSUPPORT, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNSUPPORT, "ScreenCaptureServer Start InCall Abort"); return MSERR_UNSUPPORT; } else { @@ -1181,7 +1183,7 @@ int32_t ScreenCaptureServer::StartPrivacyWindow() comStr += "\",\"appLabel\":\""; comStr += callingLabel_.c_str(); comStr += "\"}"; - + AAFwk::Want want; want.SetElementName(BUNDLE_NAME, ABILITY_NAME); auto connection_ = sptr(new (std::nothrow) UIExtensionAbilityConnection(comStr)); @@ -1471,7 +1473,7 @@ int32_t ScreenCaptureServer::CreateVirtualScreen(const std::string &name, sptr &au return innerAudioCapture_->AcquireAudioBuffer(audioBuffer); } MEDIA_LOGE("AcquireAudioBuffer failed, source type not support, type:%{public}d", type); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNKNOWN, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNKNOWN, "AcquireAudioBuffer failed, source type not support"); return MSERR_UNKNOWN; } @@ -1658,7 +1660,7 @@ int32_t ScreenCaptureServer::ReleaseAudioBuffer(AudioCaptureSourceType type) return innerAudioCapture_->ReleaseAudioBuffer(); } MEDIA_LOGE("ReleaseAudioBuffer failed, source type not support, type:%{public}d", type); - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNKNOWN, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNKNOWN, "ReleaseAudioBuffer failed, source type not support"); return MSERR_UNKNOWN; } @@ -1737,7 +1739,7 @@ int32_t ScreenCaptureServer::AcquireVideoBuffer(sptr &surfa MEDIA_LOGD("getcurrent surfaceBuffer info, size:%{public}u", surfaceBuffer->GetSize()); return MSERR_OK; } - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNKNOWN, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNKNOWN, "AcquireVideoBuffer fault"); MEDIA_LOGD("ScreenCaptureServer: 0x%{public}06" PRIXPTR "AcquireVideoBuffer end.", FAKE_POINTER(this)); return MSERR_UNKNOWN; @@ -1769,7 +1771,7 @@ int32_t ScreenCaptureServer::ExcludeContent(ScreenCaptureContentFilter &contentF // For the moment, not support: // For STREAM, should call AudioCapturer interface to make effect when start // For CAPTURE FILE, should call Recorder interface to make effect when start - FaultScreenCaptureEventWrite(appName_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNSUPPORT, + FaultScreenCaptureEventWrite(appName_, instanceId_, avType_, dataMode_, SCREEN_CAPTURE_ERR_UNSUPPORT, "ExcludeContent failed, capture is not STARTED"); return MSERR_UNSUPPORT; } @@ -2148,7 +2150,7 @@ int32_t AudioDataSource::GetSize(int64_t &size) size = static_cast(bufferLen); return ret; } - + void AudioDataSource::MixAudio(char** srcData, char* mixData, int channels, int bufferSize) { MEDIA_LOGD("AudioDataSource MixAudio"); diff --git a/services/services/screen_capture/server/screen_capture_server.h b/services/services/screen_capture/server/screen_capture_server.h index b4c2ca7408de3c2d5044f7d87c0b260f343aa840..8e8b44e74778108a69b7a26c193ce9cc4d2c46f8 100644 --- a/services/services/screen_capture/server/screen_capture_server.h +++ b/services/services/screen_capture/server/screen_capture_server.h @@ -266,7 +266,7 @@ private: void InitAppInfo(); void CloseFd(); void ReleaseInner(); - + VirtualScreenOption InitVirtualScreenOption(const std::string &name, sptr consumer); int32_t GetMissionIds(std::vector &missionIds); int32_t MakeVirtualScreenMirror(); @@ -340,6 +340,9 @@ private: int32_t audioSourceId_ = 0; int32_t videoSourceId_ = 0; std::shared_ptr audioSource_ = nullptr; + + /* used for DFX events */ + int64_t instanceId_ = 0; private: static int32_t CheckAudioCapParam(const AudioCaptureInfo &audioCapInfo); static int32_t CheckVideoCapParam(const VideoCaptureInfo &videoCapInfo); diff --git a/services/utils/include/media_dfx.h b/services/utils/include/media_dfx.h index 9c8617503901204bafaecbb5c9aa6ddf427136df..114232e6c2d110446739756afea262ff1d2ad482 100644 --- a/services/utils/include/media_dfx.h +++ b/services/utils/include/media_dfx.h @@ -59,12 +59,13 @@ public: void EventWriteBundleName(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, std::string module, std::string status, int32_t appUid, int32_t appPid, std::string bundleName); void SourceEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, const std::string& - appName, const std::string& callerType, int8_t sourceType, const std::string& sourceUrl, + appName, uint64_t instanceId, const std::string& callerType, int8_t sourceType, const std::string& sourceUrl, const std::string& errMsg); void RecordAudioEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::string& appName, int8_t sourceType, const std::string& errorMessage); + const std::string& appName, uint64_t instanceId, int8_t sourceType, const std::string& errorMessage); void ScreenCaptureEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::string& appName, int8_t captureMode, int8_t dataMode, int32_t errorCode, const std::string& errMsg); + const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode, + const std::string& errMsg); void CommonStatisicsEventWrite(CallType callType, OHOS::HiviewDFX::HiSysEvent::EventType type, const std::map>>>& infoMap); private: @@ -81,15 +82,15 @@ __attribute__((visibility("default"))) void BehaviorEventWriteForScreenCapture(s __attribute__((visibility("default"))) void StatisticEventWriteBundleName(std::string status, std::string module); __attribute__((visibility("default"))) void FaultEventWrite(std::string msg, std::string module); -__attribute__((visibility("default"))) void FaultSourceEventWrite(const std::string& appName, +__attribute__((visibility("default"))) void FaultSourceEventWrite(const std::string& appName, uint64_t instanceId, const std::string& callerType, int8_t sourceType, const std::string& sourceUrl, const std::string& errorMessage); -__attribute__((visibility("default"))) void FaultRecordAudioEventWrite(const std::string& appName, int8_t sourceType, - const std::string& errorMessage); -__attribute__((visibility("default"))) void FaultScreenCaptureEventWrite(const std::string& appName, int8_t captureMode, - int8_t dataMode, int32_t errorCode, const std::string& errorMessage); -__attribute__((visibility("default"))) int32_t CreateMediaInfo(CallType callType, int32_t uid); -__attribute__((visibility("default"))) int32_t AppendMediaInfo(const std::shared_ptr& meta); -__attribute__((visibility("default"))) int32_t ReportMediaInfo(); +__attribute__((visibility("default"))) void FaultRecordAudioEventWrite(const std::string& appName, uint64_t instanceId, + int8_t sourceType, const std::string& errorMessage); +__attribute__((visibility("default"))) void FaultScreenCaptureEventWrite(const std::string& appName, + uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode, const std::string& errorMessage); +__attribute__((visibility("default"))) int32_t CreateMediaInfo(CallType callType, int32_t uid, uint64_t instanceId); +__attribute__((visibility("default"))) int32_t AppendMediaInfo(const std::shared_ptr& meta, uint64_t instanceId); +__attribute__((visibility("default"))) int32_t ReportMediaInfo(uint64_t instanceId); class __attribute__((visibility("default"))) MediaTrace : public NoCopyable { public: diff --git a/services/utils/media_dfx.cpp b/services/utils/media_dfx.cpp index bab1a172bcca34c1b0a2814e590497c4b632131a..066c1c6feef5f451ba302e62cbd600f88d715e91 100644 --- a/services/utils/media_dfx.cpp +++ b/services/utils/media_dfx.cpp @@ -91,7 +91,7 @@ namespace { g_reachMaxMapSize = (reportMediaInfoMap_[ct].size() >= MAX_MAP_SIZE); return true; } - + int32_t StatisticsEventReport() { MEDIA_LOG_I("StatisticsEventReport."); @@ -168,14 +168,13 @@ void MediaEvent::EventWriteBundleName(std::string eventName, OHOS::HiviewDFX::Hi } void MediaEvent::SourceEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::string& appName, const std::string& callerType, int8_t sourceType, const std::string& sourceUrl, - const std::string& errMsg) + const std::string& appName, uint64_t instanceId, const std::string& callerType, int8_t sourceType, + const std::string& sourceUrl, const std::string& errMsg) { - uint64_t traceId = HiTraceChain::GetId().GetChainId(); - std::string traceIdStr = std::to_string(traceId); + std::string instanceIdStr = std::to_string(instanceId); HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type, "APP_NAME", appName, - "INSTANCE_ID", traceIdStr, + "INSTANCE_ID", instanceIdStr, "CALLER_TYPE", callerType, "SOURCE_TYPE", sourceType, "SOURCE_URI", sourceUrl, @@ -183,25 +182,24 @@ void MediaEvent::SourceEventWrite(const std::string& eventName, OHOS::HiviewDFX: } void MediaEvent::RecordAudioEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::string& appName, int8_t sourceType, const std::string& errorMessage) + const std::string& appName, uint64_t instanceId, int8_t sourceType, const std::string& errorMessage) { - uint64_t traceId = HiTraceChain::GetId().GetChainId(); - std::string traceIdStr = std::to_string(traceId); + std::string instanceIdStr = std::to_string(instanceId); HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type, "APP_NAME", appName, - "INSTANCE_ID", traceIdStr, + "INSTANCE_ID", instanceIdStr, "AUDIO_SOURCE_TYPE", sourceType, "ERROR_MESG", errorMessage); } void MediaEvent::ScreenCaptureEventWrite(const std::string& eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, - const std::string& appName, int8_t captureMode, int8_t dataMode, int32_t errorCode, const std::string& errorMessage) + const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode, int32_t errorCode, + const std::string& errorMessage) { - uint64_t traceId = HiTraceChain::GetId().GetChainId(); - std::string traceIdStr = std::to_string(traceId); + std::string instanceIdStr = std::to_string(instanceId); HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type, "APP_NAME", appName, - "INSTANCE_ID", traceIdStr, + "INSTANCE_ID", instanceIdStr, "CAPTURE_MODE", captureMode, "DATA_MODE", dataMode, "ERROR_CODE", errorCode, @@ -327,33 +325,32 @@ void FaultEventWrite(std::string msg, std::string module) } } -void FaultSourceEventWrite(const std::string& appName, const std::string& callerType, int8_t sourceType, - const std::string& sourceUrl, const std::string& errorMessage) +void FaultSourceEventWrite(const std::string& appName, uint64_t instanceId, const std::string& callerType, + int8_t sourceType, const std::string& sourceUrl, const std::string& errorMessage) { MediaEvent event; - event.SourceEventWrite("SOURCE_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, appName, callerType, - sourceType, sourceUrl, errorMessage); + event.SourceEventWrite("SOURCE_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, appName, instanceId, + callerType, sourceType, sourceUrl, errorMessage); } -void FaultRecordAudioEventWrite(const std::string& appName, int8_t sourceType, const std::string& errorMessage) +void FaultRecordAudioEventWrite(const std::string& appName, uint64_t instanceId, int8_t sourceType, + const std::string& errorMessage) { MediaEvent event; event.RecordAudioEventWrite("RECORD_AUDIO_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, appName, - sourceType, errorMessage); + instanceId, sourceType, errorMessage); } -void FaultScreenCaptureEventWrite(const std::string& appName, int8_t captureMode, int8_t dataMode, int32_t errorCode, - const std::string& errorMessage) +void FaultScreenCaptureEventWrite(const std::string& appName, uint64_t instanceId, int8_t captureMode, int8_t dataMode, + int32_t errorCode, const std::string& errorMessage) { MediaEvent event; event.ScreenCaptureEventWrite("SCREEN_CAPTURE_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, appName, - captureMode, dataMode, errorCode, errorMessage); + instanceId, captureMode, dataMode, errorCode, errorMessage); } -int32_t CreateMediaInfo(CallType callType, int32_t uid) +int32_t CreateMediaInfo(CallType callType, int32_t uid, uint64_t instanceId) { - MEDIA_LOG_I("CreateMediaInfo."); - uint64_t instanceId = HiTraceChain::GetId().GetChainId(); MEDIA_LOG_I("CreateMediaInfo uid is: %{public}" PRId32 " instanceId is: %{public}" PRIu64, uid, instanceId); std::lock_guard lock(collectMut_); auto instanceIdMap = idMap_.find(instanceId); @@ -384,14 +381,13 @@ int32_t CreateMediaInfo(CallType callType, int32_t uid) return MSERR_OK; } -int32_t AppendMediaInfo(const std::shared_ptr& meta) +int32_t AppendMediaInfo(const std::shared_ptr& meta, uint64_t instanceId) { MEDIA_LOG_I("AppendMediaInfo."); if (meta == nullptr || meta->Empty()) { MEDIA_LOG_I("Insert meta is empty."); return MSERR_INVALID_OPERATION; } - uint64_t instanceId = HiTraceChain::GetId().GetChainId(); std::lock_guard lock(collectMut_); auto idMapIt = idMap_.find(instanceId); if (idMapIt == idMap_.end()) { @@ -424,10 +420,9 @@ int32_t AppendMediaInfo(const std::shared_ptr& meta) return MSERR_OK; } -int32_t ReportMediaInfo() +int32_t ReportMediaInfo(uint64_t instanceId) { MEDIA_LOG_I("Report."); - uint64_t instanceId = HiTraceChain::GetId().GetChainId(); MEDIA_LOG_I("Delete media info instanceId is: %{public}" PRIu64, instanceId); if (!CollectReportMediaInfo(instanceId)) { MEDIA_LOG_I("Collect media info fail.");