diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index b699f301..1d672825 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -58,6 +58,7 @@ ohos_shared_library("drm_framework") { "-fPIC", "-Wall", ] + cflags += [ "-DENABLE_DRM_SYSEVENT_CONTROL" ] if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] @@ -89,6 +90,7 @@ ohos_shared_library("drm_framework") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "hitrace:libhitracechain", "ipc:ipc_core", "napi:ace_napi", "safwk:system_ability_fwk", diff --git a/frameworks/native/drm/media_key_system_factory_impl.cpp b/frameworks/native/drm/media_key_system_factory_impl.cpp index e785d685..3a91438e 100644 --- a/frameworks/native/drm/media_key_system_factory_impl.cpp +++ b/frameworks/native/drm/media_key_system_factory_impl.cpp @@ -20,17 +20,24 @@ namespace OHOS { namespace DrmStandard { +using namespace OHOS::HiviewDFX; sptr MediaKeySystemFactoryImpl::mediaKeySystemFactoryImpl_; MediaKeySystemFactoryImpl::MediaKeySystemFactoryImpl() { DRM_DEBUG_LOG("MediaKeySystemFactoryImpl:0x%{public}06" PRIXPTR "MediaKeySystemFactoryImpl Instances create", FAKE_POINTER(this)); + #ifdef ENABLE_DRM_SYSEVENT_CONTROL + traceId_ = HiTraceChain::Begin("MediaKeySystemFactory", HITRACE_FLAG_DEFAULT); + #endif Init(); } MediaKeySystemFactoryImpl::~MediaKeySystemFactoryImpl() { DRM_INFO_LOG("MediaKeySystemFactoryImpl::~MediaKeySystemFactoryImpl enter."); + #ifdef ENABLE_DRM_SYSEVENT_CONTROL + HiTraceChain::End(traceId_); + #endif serviceProxy_ = nullptr; DRM_INFO_LOG("MediaKeySystemFactoryImpl::~MediaKeySystemFactoryImpl exit."); deathRecipient_ = nullptr; @@ -94,7 +101,9 @@ void MediaKeySystemFactoryImpl::Init() if (!result) { DRM_ERR_LOG("failed to add deathRecipient"); } - + #ifdef ENABLE_DRM_SYSEVENT_CONTROL + HiTraceChain::SetId(traceId_); + #endif CreateListenerObject(); DRM_INFO_LOG("MediaKeySystemFactoryImpl::Init exit."); } diff --git a/interfaces/inner_api/native/drm/media_key_system_factory_impl.h b/interfaces/inner_api/native/drm/media_key_system_factory_impl.h index 793a1e72..f5da4aad 100644 --- a/interfaces/inner_api/native/drm/media_key_system_factory_impl.h +++ b/interfaces/inner_api/native/drm/media_key_system_factory_impl.h @@ -24,6 +24,9 @@ #include "i_mediakeysystemfactory_service.h" #include "drm_death_recipient.h" #include "drm_log.h" +#ifdef ENABLE_DRM_SYSEVENT_CONTROL +#include "hitrace/tracechain.h" +#endif namespace OHOS { namespace DrmStandard { @@ -49,6 +52,9 @@ private: sptr serviceProxy_; sptr deathRecipient_ = nullptr; sptr listenerStub_ = nullptr; + #ifdef ENABLE_DRM_SYSEVENT_CONTROL + HiviewDFX::HiTraceId traceId_; + #endif }; } // DrmStandard } // OHOS diff --git a/services/drm_service/server/include/key_session_service.h b/services/drm_service/server/include/key_session_service.h index 91528f13..23d04fa0 100644 --- a/services/drm_service/server/include/key_session_service.h +++ b/services/drm_service/server/include/key_session_service.h @@ -74,7 +74,6 @@ private: wptr sessionOperatorsCallback_; sptr hdiMediaKeySession_; StatisticsInfo statisticsInfo_; - HiviewDFX::HiTraceId traceId_; std::string generationResult_; std::string mediaKeyType_; uint32_t generationDuration_; diff --git a/services/drm_service/server/include/mediakeysystem_service.h b/services/drm_service/server/include/mediakeysystem_service.h index 4d825622..dd561809 100644 --- a/services/drm_service/server/include/mediakeysystem_service.h +++ b/services/drm_service/server/include/mediakeysystem_service.h @@ -87,7 +87,6 @@ private: std::set> sessionsSet_; sptr hdiKeySystem_; StatisticsInfo statisticsInfo_; - HiviewDFX::HiTraceId traceId_; std::string generationResult_; uint32_t generationDuration_; }; diff --git a/services/drm_service/server/src/key_session_service.cpp b/services/drm_service/server/src/key_session_service.cpp index d312100f..c1dbc60b 100644 --- a/services/drm_service/server/src/key_session_service.cpp +++ b/services/drm_service/server/src/key_session_service.cpp @@ -24,6 +24,7 @@ namespace OHOS { namespace DrmStandard { +using namespace OHOS::HiviewDFX; static std::mutex sessionMutex_; MediaKeySessionService::MediaKeySessionService(sptr hdiMediaKeySession) @@ -31,7 +32,6 @@ MediaKeySessionService::MediaKeySessionService(sptr hdiMediaKeySession, @@ -53,7 +53,6 @@ MediaKeySessionService::~MediaKeySessionService() if (hdiMediaKeySession_ != nullptr) { DRM_ERR_LOG("hdiMediaKeySession_ != nullptr"); } - HiTraceChain::End(traceId_); DRM_INFO_LOG("MediaKeySessionService::~MediaKeySessionService exit."); } @@ -129,13 +128,12 @@ int32_t MediaKeySessionService::GenerateMediaKeyRequest( auto duration = timeAfter - timeBefore; generationDuration_ = duration.count(); auto callTime = std::chrono::duration_cast(timeBefore.time_since_epoch()).count(); - HiTraceChain::SetId(traceId_); if (ret != DRM_OK) { generationResult_ = "failed"; DRM_ERR_LOG("MediaKeySessionService::GenerateMediaKeyRequest failed."); HISYSEVENT_FAULT("DRM_COMMON_FAILURE", "APP_NAME", statisticsInfo_.bundleName, "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), "ERROR_CODE", ret, - "ERROR_MESG", "GenerateMediaKeyRequest failed", "EXTRA_MESG", "GenerateMediaKeyRequest failed"); + "ERROR_MESG", "GenerateMediaKeyRequest failed", "EXTRA_MESG", ""); HISYSEVENT_BEHAVIOR("DRM_LICENSE_DOWNLOAD_INFO", "MODULE", "DRM_SERVICE", "TIME", callTime, "APP_NAME", statisticsInfo_.bundleName, "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), "DRM_name", statisticsInfo_.pluginName, "DRM_uuid", statisticsInfo_.pluginUuid, @@ -167,7 +165,6 @@ int32_t MediaKeySessionService::ProcessMediaKeyResponse(std::vector &li auto callTime = std::chrono::duration_cast(timeBefore.time_since_epoch()).count(); auto duration = timeAfter - timeBefore; auto processDuration = duration.count(); - HiTraceChain::SetId(traceId_); if (ret != DRM_OK) { DRM_ERR_LOG("MediaKeySessionService::ProcessMediaKeyResponse failed."); std::string responseString = std::string(reinterpret_cast(licenseResponse.data()), diff --git a/services/drm_service/server/src/media_decrypt_module_service.cpp b/services/drm_service/server/src/media_decrypt_module_service.cpp index 8afcbd9e..5cfe4083 100644 --- a/services/drm_service/server/src/media_decrypt_module_service.cpp +++ b/services/drm_service/server/src/media_decrypt_module_service.cpp @@ -50,9 +50,15 @@ MediaDecryptModuleService::~MediaDecryptModuleService() meta->SetData(Media::Tag::DRM_ERROR_CODE, errCode_); meta->SetData(Media::Tag::DRM_ERROR_MESG, errMessage_); meta->SetData(Media::Tag::DRM_DECRYPT_TIMES, decryptStatustics_.decryptTimes); - meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE, decryptStatustics_.decryptSumSize/decryptStatustics_.decryptTimes); - meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION, - decryptStatustics_.decryptSumDuration/decryptStatustics_.decryptTimes); + if (decryptStatustics_.decryptTimes != 0) { + meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE, + decryptStatustics_.decryptSumSize/decryptStatustics_.decryptTimes); + meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION, + decryptStatustics_.decryptSumDuration/decryptStatustics_.decryptTimes); + } else { + meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE, 0); + meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION, 0); + } meta->SetData(Media::Tag::DRM_DECRYPT_MAX_SIZE, decryptStatustics_.decryptMaxSize); meta->SetData(Media::Tag::DRM_DECRYPT_MAX_DURATION, decryptStatustics_.decryptMaxDuration); DrmEvent::GetInstance().AppendMediaInfo(meta); diff --git a/services/drm_service/server/src/mediakeysystem_service.cpp b/services/drm_service/server/src/mediakeysystem_service.cpp index 064e97c7..943531bb 100644 --- a/services/drm_service/server/src/mediakeysystem_service.cpp +++ b/services/drm_service/server/src/mediakeysystem_service.cpp @@ -29,12 +29,12 @@ namespace OHOS { namespace DrmStandard { +using namespace OHOS::HiviewDFX; MediaKeySystemService::MediaKeySystemService(sptr hdiKeySystem) { DRM_DEBUG_LOG("MediaKeySystemService::MediaKeySystemService enter."); keySystemOperatoersCallback_ = nullptr; hdiKeySystem_ = hdiKeySystem; - traceId_ = HiTraceChain::Begin("hiPlayerImpl", HITRACE_FLAG_DEFAULT); } MediaKeySystemService::MediaKeySystemService(sptr hdiKeySystem, @@ -54,7 +54,6 @@ MediaKeySystemService::~MediaKeySystemService() if (hdiKeySystem_ != nullptr) { DRM_ERR_LOG("hdiKeySystem != nullptr"); } - HiTraceChain::End(traceId_); } int32_t MediaKeySystemService::CloseMediaKeySystemServiceByCallback() @@ -115,7 +114,6 @@ int32_t MediaKeySystemService::GenerateKeySystemRequest(std::vector &re "version:%{public}s,\n", statisticsInfo_.pluginName.c_str(), statisticsInfo_.pluginUuid.c_str(), statisticsInfo_.bundleName.c_str(), statisticsInfo_.vendorName.c_str(), statisticsInfo_.versionName.c_str()); int32_t ret = DRM_OK; - HiTraceChain::SetId(traceId_); auto timeBefore = std::chrono::system_clock::now(); ret = hdiKeySystem_->GenerateKeySystemRequest(defaultUrl, request); auto timeAfter = std::chrono::system_clock::now(); @@ -126,7 +124,7 @@ int32_t MediaKeySystemService::GenerateKeySystemRequest(std::vector &re DRM_ERR_LOG("MediaKeySystemService::GenerateKeySystemRequest failed."); HISYSEVENT_FAULT("DRM_COMMON_FAILURE", "APP_NAME", statisticsInfo_.bundleName, "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), "ERROR_CODE", ret, - "ERROR_MESG", "CreateMediaKeySystem failed", "EXTRA_MESG", "CreateMediaKeySystem failed"); + "ERROR_MESG", "CreateMediaKeySystem failed", "EXTRA_MESG", ""); auto callTime = std::chrono::duration_cast(timeBefore.time_since_epoch()).count(); HISYSEVENT_BEHAVIOR("DRM_CERTIFICATE_DOWNLOAD_INFO", "MODULE", "DRM_SERVICE", "TIME", callTime, "APP_NAME", statisticsInfo_.bundleName, "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), @@ -136,7 +134,7 @@ int32_t MediaKeySystemService::GenerateKeySystemRequest(std::vector &re "SERVER_COST_DURATION", 0, "SERVER_RESULT", ""); return ret; } - generationResult_ = "seccess"; + generationResult_ = "success"; DRM_INFO_LOG("MediaKeySystemService::GenerateKeySystemRequest exit."); return ret; } @@ -155,7 +153,6 @@ int32_t MediaKeySystemService::ProcessKeySystemResponse(const std::vector(timeBefore.time_since_epoch()).count(); auto duration = timeAfter - timeBefore; auto processDuration = duration.count(); - HiTraceChain::SetId(traceId_); if (ret != DRM_OK) { DRM_ERR_LOG("MediaKeySystemService::ProcessKeySystemResponse failed."); std::string responseString = std::string(reinterpret_cast(response.data()), response.size()); @@ -241,7 +238,6 @@ int32_t MediaKeySystemService::GetConfigurationByteArray(std::string &configName int32_t MediaKeySystemService::CreateMediaKeySession(IMediaKeySessionService::ContentProtectionLevel securityLevel, sptr &keySessionProxy) { - HiTraceChain::SetId(traceId_); DrmTrace trace("MediaKeySystemService::CreateMediaKeySession"); DRM_INFO_LOG("MediaKeySystemService::CreateMediaKeySession enter, securityLevel:%{public}d.", securityLevel); DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n" @@ -257,7 +253,7 @@ int32_t MediaKeySystemService::CreateMediaKeySession(IMediaKeySessionService::Co DRM_ERR_LOG("hdiKeySystem_ CreateMediaKeySession failed."); HISYSEVENT_FAULT("DRM_COMMON_FAILURE", "APP_NAME", statisticsInfo_.bundleName, "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), "ERROR_CODE", DRM_SERVICE_ERROR, - "ERROR_MESG", "CreateMediaKeySession failed", "EXTRA_MESG", "CreateMediaKeySystem failed"); + "ERROR_MESG", "CreateMediaKeySession failed", "EXTRA_MESG", ""); return DRM_SERVICE_ERROR; } keySessionService = new (std::nothrow) MediaKeySessionService(hdiMediaKeySession, statisticsInfo_); @@ -265,7 +261,7 @@ int32_t MediaKeySystemService::CreateMediaKeySession(IMediaKeySessionService::Co DRM_ERR_LOG("MediaKeySystemService::CreateMediaKeySession allocation failed."); HISYSEVENT_FAULT("DRM_COMMON_FAILURE", "APP_NAME", statisticsInfo_.bundleName, "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), "ERROR_CODE", DRM_ALLOC_ERROR, - "ERROR_MESG", "CreateMediaKeySession failed", "EXTRA_MESG", "CreateMediaKeySystem failed"); + "ERROR_MESG", "CreateMediaKeySession failed", "EXTRA_MESG", ""); return DRM_ALLOC_ERROR; } keySessionService->SetMediaKeySessionServiceOperatorsCallback(this); diff --git a/services/drm_service/server/src/mediakeysystemfactory_service.cpp b/services/drm_service/server/src/mediakeysystemfactory_service.cpp index 31de3612..a58850ad 100644 --- a/services/drm_service/server/src/mediakeysystemfactory_service.cpp +++ b/services/drm_service/server/src/mediakeysystemfactory_service.cpp @@ -33,15 +33,12 @@ namespace OHOS { namespace DrmStandard { using namespace OHOS::HiviewDFX; -HiviewDFX::HiTraceId traceId; REGISTER_SYSTEM_ABILITY_BY_ID(MediaKeySystemFactoryService, MEDIA_KEY_SYSTEM_SERVICE_ID, true) MediaKeySystemFactoryService::MediaKeySystemFactoryService(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate), drmHostManager_(nullptr) { - traceId = HiTraceChain::Begin("hiPlayerImpl", HITRACE_FLAG_DEFAULT); - HiTraceChain::SetId(traceId); } MediaKeySystemFactoryService::~MediaKeySystemFactoryService() @@ -136,7 +133,7 @@ int32_t MediaKeySystemFactoryService::CreateMediaKeySystem(std::string &uuid, DRM_ERR_LOG("MediaKeySystemFactoryService:: drmHostManager_ return hdiMediaKeySystem nullptr"); HISYSEVENT_FAULT("DRM_COMMON_FAILURE", "APP_NAME", GetClientBundleName(IPCSkeleton::GetCallingUid()), "INSTANCE_ID", std::to_string(HiTraceChain::GetId().GetChainId()), "ERROR_CODE", DRM_SERVICE_ERROR, - "ERROR_MESG", "CreateMediaKeySystem failed", "EXTRA_MESG", "CreateMediaKeySystem failed"); + "ERROR_MESG", "CreateMediaKeySystem failed", "EXTRA_MESG", ""); return DRM_SERVICE_ERROR; } StatisticsInfo statisticsInfo; @@ -288,6 +285,7 @@ int32_t MediaKeySystemFactoryService::WriteDumpInfo(int32_t fd, std::string &dum iter->GetStatistics(metrics); DumpMetricsInfo(dumpString, metrics); dumpString += "\n"; + metrics.clear(); } } if (fd != -1) { @@ -304,7 +302,7 @@ int32_t MediaKeySystemFactoryService::DumpMetricsInfo(std::string &dumpString, std::vector metrics) { for (auto &iter : metrics) { - if (iter.name == currentSessionNum || iter.name == decryptNumber || iter.name == errorDecryptNumber) { + if (iter.name == currentSessionNum || iter.name == decryptTimes || iter.name == errorDecryptNumber) { dumpString += iter.name + ":" + iter.value + " "; } }