mirror of
https://github.com/openharmony/multimedia_drm_framework.git
synced 2026-07-19 17:13:35 -04:00
Refactor the code that reports statistics event to reduce memory.
Signed-off-by: jiangchunli <jiangchunli1@huawei.com>
This commit is contained in:
@@ -31,13 +31,11 @@
|
||||
"c_utils",
|
||||
"hilog",
|
||||
"hidumper",
|
||||
"access_token",
|
||||
"hicollie",
|
||||
"hdf_core",
|
||||
"eventhandler",
|
||||
"bundle_framework",
|
||||
"drivers_interface_drm",
|
||||
"media_foundation",
|
||||
"memmgr",
|
||||
"hiappevent",
|
||||
"json"
|
||||
|
||||
@@ -76,11 +76,9 @@ ohos_fuzztest("drmserviceFuzzTest") {
|
||||
"hidumper:lib_dump_usage",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"hitrace:libhitracechain",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"memmgr:memmgrclient",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
|
||||
@@ -69,7 +69,6 @@ ohos_fuzztest("mediakeydecryptndkFuzzTest") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
subsystem_name = "multimedia"
|
||||
|
||||
@@ -70,7 +70,6 @@ ohos_fuzztest("mediakeysessionndkFuzzTest") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
subsystem_name = "multimedia"
|
||||
|
||||
@@ -69,7 +69,6 @@ ohos_fuzztest("mediakeysystemndkFuzzTest") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
subsystem_name = "multimedia"
|
||||
|
||||
@@ -68,7 +68,6 @@ ohos_fuzztest("mediakeysystemndkfactoryFuzzTest") {
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
subsystem_name = "multimedia"
|
||||
|
||||
@@ -71,10 +71,8 @@ ohos_unittest("drm_framework_capi_unittest_v1_0") {
|
||||
"hidumper:lib_dump_usage",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"hitrace:libhitracechain",
|
||||
"ipc:ipc_core",
|
||||
"media_foundation:media_foundation",
|
||||
]
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "drm_framework"
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "native_drm_common.h"
|
||||
#include "native_drm_err.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "meta/meta.h"
|
||||
#include "native_drm_base.h"
|
||||
#include "native_drm_object.h"
|
||||
#include "native_mediakeysession.h"
|
||||
@@ -164,30 +163,5 @@ HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_ReportCertificateBehaviorEvent, Test
|
||||
serverResult);
|
||||
}
|
||||
|
||||
HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_HiSysWriteStatistic, TestSize.Level0)
|
||||
{
|
||||
int32_t errNo = DRM_ERR_UNKNOWN;
|
||||
int32_t uid = 324442;
|
||||
int32_t instanceId = 324442;
|
||||
errNo = DrmEvent::GetInstance().CreateMediaInfo(uid, instanceId);
|
||||
EXPECT_EQ(errNo, DRM_ERR_OK);
|
||||
std::shared_ptr<OHOS::Media::Meta> meta = std::make_shared<Media::Meta>();
|
||||
meta->SetData(Media::Tag::DRM_ERROR_MESG, "errMessage");
|
||||
errNo = DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId);
|
||||
EXPECT_EQ(errNo, DRM_ERR_OK);
|
||||
errNo = DrmEvent::GetInstance().ReportMediaInfo(instanceId);
|
||||
EXPECT_EQ(errNo, DRM_ERR_OK);
|
||||
}
|
||||
|
||||
HWTEST_F(DrmFrameworkUnitTest, Drm_unittest_HiSysWriteStatisticAbNormal, TestSize.Level0)
|
||||
{
|
||||
int32_t errNo = DRM_ERR_UNKNOWN;
|
||||
int32_t uid = 324442;
|
||||
int32_t instanceId = 324442;
|
||||
DrmEvent::GetInstance().CreateMediaInfo(uid, instanceId);
|
||||
std::shared_ptr<OHOS::Media::Meta> meta = std::make_shared<Media::Meta>();
|
||||
errNo = DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId);
|
||||
EXPECT_NE(errNo, DRM_ERR_OK);
|
||||
}
|
||||
} // DrmStandard
|
||||
} // OHOS
|
||||
|
||||
@@ -59,12 +59,10 @@ ohos_shared_library("drm_napi") {
|
||||
external_deps = [
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:napi_base_context",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"hiappevent:hiappevent_innerapi",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"hitrace:libhitracechain",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
|
||||
@@ -51,8 +51,6 @@ ohos_shared_library("drm_service") {
|
||||
"ability_base:want",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:napi_base_context",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libprivacy_sdk",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
@@ -69,7 +67,6 @@ ohos_shared_library("drm_service") {
|
||||
"hitrace:libhitracechain",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_single",
|
||||
"media_foundation:media_foundation",
|
||||
"memmgr:memmgrclient",
|
||||
"napi:ace_napi",
|
||||
"safwk:system_ability_fwk",
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
#define OHOS_DRM_MEDIADECRYPTMODULESERVICE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <refbase.h>
|
||||
#include "drm_host_manager.h"
|
||||
#include "drm_log.h"
|
||||
#include "drm_dfx.h"
|
||||
#include "drm_dfx_utils.h"
|
||||
#include "media_decrypt_module_service_stub.h"
|
||||
#include "v1_0/media_decrypt_module_proxy.h"
|
||||
|
||||
@@ -27,21 +28,12 @@ namespace OHOS {
|
||||
namespace DrmStandard {
|
||||
using namespace OHOS::HDI::Drm::V1_0;
|
||||
using namespace OHOS::HDI;
|
||||
struct DecryptStatistics {
|
||||
uint32_t decryptTimes = 0;
|
||||
uint64_t decryptSumSize = 0;
|
||||
uint64_t decryptSumDuration = 0;
|
||||
uint32_t decryptMaxSize = 0;
|
||||
uint32_t decryptMaxDuration = 0;
|
||||
uint64_t errorDecryptTimes = 0;
|
||||
int32_t errCode = 0;
|
||||
std::string errMessage = "no error";
|
||||
std::priority_queue<int, std::vector<int>, std::greater<int>> topThree;
|
||||
};
|
||||
|
||||
class MediaDecryptModuleService : public MediaDecryptModuleServiceStub {
|
||||
public:
|
||||
MediaDecryptModuleService(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> hdiMediaDecryptModule);
|
||||
MediaDecryptModuleService(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> hdiMediaDecryptModule,
|
||||
StatisticsInfo statisticsInfo);
|
||||
~MediaDecryptModuleService();
|
||||
int32_t Release() override;
|
||||
int32_t DecryptMediaData(bool secureDecodrtState, IMediaDecryptModuleService::CryptInfo &cryptInfo,
|
||||
@@ -56,11 +48,12 @@ private:
|
||||
uint32_t bufLen);
|
||||
void UpdateDecryptionStatistics(int32_t decryptionResult, uint32_t bufLen, uint32_t curDuration);
|
||||
const std::string GetTopThreeDecryptionDurations();
|
||||
void ReportDecryptionStatisticEvent();
|
||||
|
||||
std::mutex moduleLock_;
|
||||
sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> hdiMediaDecryptModule_;
|
||||
StatisticsInfo statisticsInfo_;
|
||||
std::mutex statisticsMutex_;
|
||||
DecryptStatistics decryptStatistics_;
|
||||
DecryptionStatistics decryptStatistics_;
|
||||
uint64_t instanceId_;
|
||||
};
|
||||
} // DrmStandard
|
||||
|
||||
@@ -105,9 +105,6 @@ int32_t MediaKeySessionService::GenerateMediaKeyRequest(
|
||||
{
|
||||
DrmTrace trace("MediaKeySessionService::GenerateMediaKeyRequest");
|
||||
DRM_INFO_LOG("MediaKeySessionService::GenerateMediaKeyRequest enter.");
|
||||
DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n"
|
||||
"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;
|
||||
OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo hdiMediaKeyRequestInfo;
|
||||
|
||||
@@ -148,9 +145,6 @@ int32_t MediaKeySessionService::ProcessMediaKeyResponse(std::vector<uint8_t> &li
|
||||
{
|
||||
DrmTrace trace("MediaKeySessionService::ProcessMediaKeyResponse");
|
||||
DRM_INFO_LOG("MediaKeySessionService::ProcessMediaKeyResponse enter.");
|
||||
DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n"
|
||||
"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;
|
||||
auto timeBefore = std::chrono::system_clock::now();
|
||||
ret = hdiMediaKeySession_->ProcessMediaKeyResponse(licenseResponse, licenseId);
|
||||
@@ -228,9 +222,6 @@ int32_t MediaKeySessionService::CheckMediaKeyStatus(std::map<std::string, std::s
|
||||
int32_t MediaKeySessionService::RestoreOfflineMediaKeys(std::vector<uint8_t> &licenseId)
|
||||
{
|
||||
DRM_INFO_LOG("MediaKeySessionService::RestoreOfflineMediaKeys enter.");
|
||||
DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n"
|
||||
"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;
|
||||
ret = hdiMediaKeySession_->RestoreOfflineMediaKeys(licenseId);
|
||||
if (ret != DRM_OK) {
|
||||
@@ -293,7 +284,7 @@ int32_t MediaKeySessionService::GetMediaDecryptModule(sptr<IMediaDecryptModuleSe
|
||||
DRM_ERR_LOG("MediaKeySessionService:: hdiDecryptModule allocation failed.");
|
||||
return DRM_SERVICE_ERROR;
|
||||
}
|
||||
decryptModule_ = new (std::nothrow) MediaDecryptModuleService(hdiDecryptModule);
|
||||
decryptModule_ = new (std::nothrow) MediaDecryptModuleService(hdiDecryptModule, statisticsInfo_);
|
||||
if (decryptModule_ == nullptr) {
|
||||
DRM_ERR_LOG("MediaKeySessionService:: new MediaDecryptModuleService allocation failed.");
|
||||
return DRM_ALLOC_ERROR;
|
||||
|
||||
@@ -16,18 +16,17 @@
|
||||
#include <memory>
|
||||
#include <unistd.h>
|
||||
#include <securec.h>
|
||||
#include <algorithm>
|
||||
#include "ashmem.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "mem_mgr_client.h"
|
||||
#include "mem_mgr_proxy.h"
|
||||
#include "drm_dfx.h"
|
||||
#include "drm_trace.h"
|
||||
#include "drm_dfx_utils.h"
|
||||
#include "drm_error_code.h"
|
||||
#include "hitrace/tracechain.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "media_decrypt_module_service.h"
|
||||
#include "meta/meta.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DrmStandard {
|
||||
@@ -42,9 +41,16 @@ MediaDecryptModuleService::MediaDecryptModuleService(
|
||||
{
|
||||
DRM_INFO_LOG("MediaDecryptModuleService 0x%{public}06" PRIXPTR " Instances create.", FAKE_POINTER(this));
|
||||
hdiMediaDecryptModule_ = hdiMediaDecryptModule;
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
}
|
||||
|
||||
MediaDecryptModuleService::MediaDecryptModuleService(
|
||||
sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> hdiMediaDecryptModule,
|
||||
StatisticsInfo statisticsInfo)
|
||||
{
|
||||
DRM_INFO_LOG("MediaDecryptModuleService 0x%{public}06" PRIXPTR " Instances create.", FAKE_POINTER(this));
|
||||
hdiMediaDecryptModule_ = hdiMediaDecryptModule;
|
||||
statisticsInfo_ = statisticsInfo;
|
||||
instanceId_ = HiTraceChain::GetId().GetChainId();
|
||||
DrmEvent::GetInstance().CreateMediaInfo(uid, instanceId_);
|
||||
}
|
||||
|
||||
MediaDecryptModuleService::~MediaDecryptModuleService()
|
||||
@@ -54,7 +60,7 @@ MediaDecryptModuleService::~MediaDecryptModuleService()
|
||||
if (hdiMediaDecryptModule_ != nullptr) {
|
||||
Release();
|
||||
}
|
||||
ReportDecryptionStatisticEvent();
|
||||
ReportDecryptionStatisticsEvent(instanceId_, statisticsInfo_.bundleName, decryptStatistics_);
|
||||
DRM_INFO_LOG("MediaDecryptModuleService::~MediaDecryptModuleService exit.");
|
||||
}
|
||||
|
||||
@@ -141,29 +147,6 @@ void MediaDecryptModuleService::SetDrmBufferInfo(OHOS::HDI::Drm::V1_0::DrmBuffer
|
||||
drmDstBuffer->sharedMemType = dstBuffer.sharedMemType;
|
||||
}
|
||||
|
||||
void MediaDecryptModuleService::ReportDecryptionStatisticEvent()
|
||||
{
|
||||
std::shared_ptr<Media::Meta> meta = std::make_shared<Media::Meta>();
|
||||
meta->SetData(Media::Tag::DRM_APP_NAME, GetClientBundleName(IPCSkeleton::GetCallingUid()));
|
||||
meta->SetData(Media::Tag::DRM_INSTANCE_ID, std::to_string(instanceId_));
|
||||
meta->SetData(Media::Tag::DRM_ERROR_CODE, decryptStatistics_.errCode);
|
||||
meta->SetData(Media::Tag::DRM_ERROR_MESG, decryptStatistics_.errMessage);
|
||||
meta->SetData(Media::Tag::DRM_DECRYPT_TIMES, decryptStatistics_.decryptTimes);
|
||||
if (decryptStatistics_.decryptTimes != 0) {
|
||||
meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE,
|
||||
static_cast<uint32_t>(decryptStatistics_.decryptSumSize / decryptStatistics_.decryptTimes));
|
||||
meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION,
|
||||
static_cast<uint32_t>(decryptStatistics_.decryptSumDuration / decryptStatistics_.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, decryptStatistics_.decryptMaxSize);
|
||||
meta->SetData(Media::Tag::DRM_DECRYPT_MAX_DURATION, decryptStatistics_.decryptMaxDuration);
|
||||
DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId_);
|
||||
DrmEvent::GetInstance().ReportMediaInfo(instanceId_);
|
||||
}
|
||||
|
||||
void MediaDecryptModuleService::UpdateDecryptionStatistics(int32_t decryptionResult,
|
||||
uint32_t bufLen, uint32_t curDuration)
|
||||
{
|
||||
@@ -173,9 +156,9 @@ void MediaDecryptModuleService::UpdateDecryptionStatistics(int32_t decryptionRes
|
||||
decryptStatistics_.topThree.pop();
|
||||
}
|
||||
|
||||
if (decryptStatistics_.decryptMaxSize < bufLen) {
|
||||
decryptStatistics_.decryptMaxSize = bufLen;
|
||||
}
|
||||
decryptStatistics_.decryptMaxSize = std::max(decryptStatistics_.decryptMaxSize, bufLen);
|
||||
decryptStatistics_.decryptMaxDuration = std::max(decryptStatistics_.decryptMaxDuration, curDuration);
|
||||
|
||||
if (decryptionResult != DRM_OK) {
|
||||
decryptStatistics_.errorDecryptTimes++;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "system_ability_definition.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "access_token.h"
|
||||
#include "drm_dfx_utils.h"
|
||||
#include "drm_host_manager.h"
|
||||
#include "drm_log.h"
|
||||
@@ -87,9 +86,6 @@ int32_t MediaKeySystemService::CloseMediaKeySystemServiceByCallback()
|
||||
int32_t MediaKeySystemService::Release()
|
||||
{
|
||||
DRM_INFO_LOG("MediaKeySystemService::Release enter.");
|
||||
DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n"
|
||||
"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 currentPid = IPCSkeleton::GetCallingPid();
|
||||
DRM_DEBUG_LOG("MediaKeySystemService GetCallingPID: %{public}d", currentPid);
|
||||
if (keySystemOperatoersCallback_ != nullptr) {
|
||||
@@ -114,9 +110,6 @@ int32_t MediaKeySystemService::GenerateKeySystemRequest(std::vector<uint8_t> &re
|
||||
{
|
||||
DrmTrace trace("MediaKeySystemService::GenerateKeySystemRequest");
|
||||
DRM_INFO_LOG("MediaKeySystemService::GenerateKeySystemRequest enter.");
|
||||
DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n"
|
||||
"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;
|
||||
auto timeBefore = std::chrono::system_clock::now();
|
||||
ret = hdiKeySystem_->GenerateKeySystemRequest(defaultUrl, request);
|
||||
@@ -139,9 +132,6 @@ int32_t MediaKeySystemService::ProcessKeySystemResponse(const std::vector<uint8_
|
||||
{
|
||||
DrmTrace trace("MediaKeySystemService::ProcessKeySystemResponse");
|
||||
DRM_INFO_LOG("MediaKeySystemService::ProcessKeySystemResponse enter.");
|
||||
DRM_DEBUG_LOG("pluginName:%{public}s, pluginUuid:%{public}s\nbundleName:%{public}s,\nvendor:%{public}s,\n"
|
||||
"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;
|
||||
auto timeBefore = std::chrono::system_clock::now();
|
||||
ret = hdiKeySystem_->ProcessKeySystemResponse(response);
|
||||
@@ -225,9 +215,6 @@ int32_t MediaKeySystemService::CreateMediaKeySession(IMediaKeySessionService::Co
|
||||
{
|
||||
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"
|
||||
"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;
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
sptr<MediaKeySessionService> keySessionService = nullptr;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "mem_mgr_client.h"
|
||||
#include "mem_mgr_proxy.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "access_token.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "drm_dfx_utils.h"
|
||||
#include "drm_log.h"
|
||||
@@ -128,10 +127,10 @@ void MediaKeySystemFactoryService::DistroyForClientDied(pid_t pid)
|
||||
DRM_DEBUG_LOG("MediaKeySystemFactoryService ReleaseMediaKeySystem.");
|
||||
drmHostManager_->ReleaseMediaKeySystem(hdiMediaKeySystem);
|
||||
}
|
||||
}
|
||||
// decrease in dfx.
|
||||
if (CurrentMediaKeySystemNum_.find((*it)->GetPluginName()) != CurrentMediaKeySystemNum_.end()) {
|
||||
CurrentMediaKeySystemNum_[(*it)->GetPluginName()]--;
|
||||
// decrease in dfx.
|
||||
if (CurrentMediaKeySystemNum_.find((*it)->GetPluginName()) != CurrentMediaKeySystemNum_.end()) {
|
||||
CurrentMediaKeySystemNum_[(*it)->GetPluginName()]--;
|
||||
}
|
||||
}
|
||||
it = mediaKeySystemForPid_[pid].erase(it);
|
||||
}
|
||||
@@ -283,8 +282,11 @@ void MediaKeySystemFactoryService::InitStatisticsInfo(const sptr<IMediaKeySystem
|
||||
(void)hdiMediaKeySystem->GetConfigurationString("vendor", statisticsInfo.vendorName);
|
||||
(void)hdiMediaKeySystem->GetConfigurationString("version", statisticsInfo.versionName);
|
||||
}
|
||||
DRM_INFO_LOG("InitStatisticsInfo %{public}s %{public}s %{public}s %{public}s %{public}s.",
|
||||
statisticsInfo.pluginName.c_str(), statisticsInfo.pluginUuid.c_str(), statisticsInfo.bundleName.c_str(),
|
||||
DRM_INFO_LOG("InitStatisticsInfo uid: %{public}d, appName: %{public}s.",
|
||||
IPCSkeleton::GetCallingUid(), statisticsInfo.bundleName.c_str());
|
||||
DRM_INFO_LOG("InitStatisticsInfo pluginName: %{public}s, pluginUUID: %{public}s",
|
||||
statisticsInfo.pluginName.c_str(), statisticsInfo.pluginUuid.c_str());
|
||||
DRM_INFO_LOG("InitStatisticsInfo vendorName: %{public}s, versionName: %{public}s",
|
||||
statisticsInfo.vendorName.c_str(), statisticsInfo.versionName.c_str());
|
||||
}
|
||||
|
||||
|
||||
+33
-210
@@ -23,24 +23,13 @@
|
||||
#include "securec.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "hitrace/tracechain.h"
|
||||
#include "meta/any.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
constexpr int64_t HOURS_BETWEEN_REPORTS = 4;
|
||||
constexpr int64_t MAX_MAP_SIZE = 100;
|
||||
std::mutex collectMut_;
|
||||
std::mutex reportMut_;
|
||||
std::chrono::system_clock::time_point currentTime_ = std::chrono::system_clock::now();
|
||||
std::map<uint64_t, int32_t> idMap_;
|
||||
std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>>>> mediaInfoMap_;
|
||||
std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>>>> reportMediaInfoMap_;
|
||||
bool g_reachMaxMapSize {false};
|
||||
}
|
||||
namespace OHOS {
|
||||
namespace DrmStandard {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using json = nlohmann::json;
|
||||
constexpr uint32_t MIN_DECRYPTION_TIMES = 1000;
|
||||
|
||||
DrmEvent& DrmEvent::GetInstance()
|
||||
{
|
||||
@@ -48,204 +37,6 @@ DrmEvent& DrmEvent::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DrmEvent::DrmStatisicsEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
const std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<Media::Meta>>>>& infoMap)
|
||||
{
|
||||
DRM_INFO_LOG("DrmEvent::DrmStatisicsEventWrite.");
|
||||
if (infoMap.empty()) {
|
||||
DRM_INFO_LOG("DrmEvent infoMap is empty.");
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> infoArr;
|
||||
for (const auto& kv : infoMap) {
|
||||
json jsonArray;
|
||||
json eventInfoJson;
|
||||
json drmEvents;
|
||||
for (const auto& listPair : kv.second) {
|
||||
json metaInfoJson;
|
||||
ParseOneEvent(listPair, metaInfoJson);
|
||||
drmEvents.push_back(metaInfoJson);
|
||||
}
|
||||
eventInfoJson["appName"] = GetClientBundleName(kv.first);
|
||||
eventInfoJson["drmStatistics"] = drmEvents;
|
||||
jsonArray.push_back(eventInfoJson);
|
||||
infoArr.push_back(jsonArray.dump());
|
||||
}
|
||||
StatisicsHiSysEventWrite(type, infoArr);
|
||||
}
|
||||
|
||||
void DrmEvent::ParseOneEvent(const std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> &listPair,
|
||||
json& metaInfoJson)
|
||||
{
|
||||
for (auto it = listPair.second->begin(); it != listPair.second->end(); ++it) {
|
||||
Media::Any valueType = OHOS::Media::GetDefaultAnyValue(it->first);
|
||||
if (Media::Any::IsSameTypeWith<int32_t>(valueType)) {
|
||||
int32_t intVal;
|
||||
if (listPair.second->GetData(it->first, intVal)) {
|
||||
metaInfoJson[it->first] = std::to_string(intVal);
|
||||
}
|
||||
} else if (Media::Any::IsSameTypeWith<uint32_t>(valueType)) {
|
||||
uint32_t uintVal;
|
||||
if (listPair.second->GetData(it->first, uintVal)) {
|
||||
metaInfoJson[it->first] = std::to_string(uintVal);
|
||||
}
|
||||
} else if (Media::Any::IsSameTypeWith<std::string>(valueType)) {
|
||||
metaInfoJson[it->first] = Media::AnyCast<std::string>(it->second);
|
||||
} else if (Media::Any::IsSameTypeWith<int8_t>(valueType)) {
|
||||
int8_t intVal;
|
||||
if (listPair.second->GetData(it->first, intVal)) {
|
||||
metaInfoJson[it->first] = std::to_string(intVal);
|
||||
}
|
||||
} else if (Media::Any::IsSameTypeWith<bool>(valueType)) {
|
||||
bool isTrue;
|
||||
if (listPair.second->GetData(it->first, isTrue)) {
|
||||
metaInfoJson[it->first] = isTrue ? "true" : "false";
|
||||
}
|
||||
} else {
|
||||
DRM_INFO_LOG("not found type matched with it->first: %{public}s.", it->first.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrmEvent::StatisicsHiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
const std::vector<std::string>& infoArr)
|
||||
{
|
||||
DRM_INFO_LOG("DrmEvent::StatisicsHiSysEventWrite.");
|
||||
std::string eventName = "DRM_STATISTICS";
|
||||
HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA, eventName, type,
|
||||
"EVENTS", infoArr);
|
||||
}
|
||||
|
||||
int32_t DrmEvent::AppendMediaInfo(const std::shared_ptr<Media::Meta>& meta, uint64_t instanceId)
|
||||
{
|
||||
DRM_INFO_LOG("AppendMediaInfo.");
|
||||
if (meta == nullptr || meta->Empty()) {
|
||||
DRM_INFO_LOG("Insert meta is empty.");
|
||||
return DRM_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(collectMut_);
|
||||
auto idMapIt = idMap_.find(instanceId);
|
||||
if (idMapIt == idMap_.end()) {
|
||||
DRM_INFO_LOG("Not found instanceId.");
|
||||
return DRM_ERR_INVALID_VAL;
|
||||
}
|
||||
int32_t uid = idMapIt->second;
|
||||
auto it = mediaInfoMap_.find(uid);
|
||||
if (it == mediaInfoMap_.end()) {
|
||||
DRM_INFO_LOG("Not found uid.");
|
||||
return DRM_ERR_INVALID_STATE;
|
||||
}
|
||||
auto& instanceList = it->second;
|
||||
for (const auto& instancePair : instanceList) {
|
||||
if (instancePair.first == instanceId) {
|
||||
auto arg = meta->begin();
|
||||
while (arg != meta->end()) {
|
||||
instancePair.second->SetData(arg->first, arg->second);
|
||||
++arg;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return DRM_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t DrmEvent::CreateMediaInfo(int32_t uid, uint64_t instanceId)
|
||||
{
|
||||
DRM_INFO_LOG("CreateMediaInfo.");
|
||||
std::lock_guard<std::mutex> lock(collectMut_);
|
||||
DRM_INFO_LOG("CreateMediaInfo uid is: %{public}" PRId32 " instanceId is: %{public}." PRIu64, uid, instanceId);
|
||||
auto instanceIdMap = idMap_.find(instanceId);
|
||||
if (instanceIdMap != idMap_.end()) {
|
||||
DRM_INFO_LOG("instanceId already exists.");
|
||||
return DRM_ERR_INVALID_VAL;
|
||||
} else {
|
||||
idMap_[instanceId] = uid;
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::Meta> meta = std::make_shared<Media::Meta>();
|
||||
std::pair<uint64_t, std::shared_ptr<Media::Meta>> metaAppIdPair(instanceId, meta);
|
||||
auto it = mediaInfoMap_.find(uid);
|
||||
if (it != mediaInfoMap_.end()) {
|
||||
it->second.push_back(metaAppIdPair);
|
||||
} else {
|
||||
mediaInfoMap_[uid].push_back(metaAppIdPair);
|
||||
}
|
||||
return DRM_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t DrmEvent::ReportMediaInfo(uint64_t instanceId)
|
||||
{
|
||||
auto currentTime = std::chrono::system_clock::now();
|
||||
auto diff = currentTime - currentTime_;
|
||||
auto hour = std::chrono::duration_cast<std::chrono::hours>(diff).count();
|
||||
CollectReportMediaInfo(instanceId);
|
||||
std::lock_guard<std::mutex> lock(reportMut_);
|
||||
if (g_reachMaxMapSize) {
|
||||
DRM_INFO_LOG("Event data size exceeds 100, report the event");
|
||||
g_reachMaxMapSize = false;
|
||||
return StatisticsEventReport();
|
||||
}
|
||||
if (hour >= HOURS_BETWEEN_REPORTS) {
|
||||
DRM_INFO_LOG("Over 4 hours, report the event.");
|
||||
return StatisticsEventReport();
|
||||
}
|
||||
return DRM_ERR_OK;
|
||||
}
|
||||
|
||||
void DrmEvent::CollectReportMediaInfo(uint64_t instanceId)
|
||||
{
|
||||
int32_t uid;
|
||||
std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> metaAppIdPair;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(collectMut_);
|
||||
DRM_INFO_LOG("CollectReportMediaInfo.");
|
||||
auto idMapIt = idMap_.find(instanceId);
|
||||
if (idMapIt == idMap_.end()) {
|
||||
DRM_INFO_LOG("Not found instanceId in idMap, instanceId is : %{public}." PRIu64, instanceId);
|
||||
return;
|
||||
}
|
||||
uid = idMapIt->second;
|
||||
idMap_.erase(idMapIt);
|
||||
auto uidToMediaInfo = mediaInfoMap_.find(uid);
|
||||
if (uidToMediaInfo == mediaInfoMap_.end()) {
|
||||
return;
|
||||
}
|
||||
auto& instanceList = uidToMediaInfo->second;
|
||||
for (const auto& instancePair : instanceList) {
|
||||
if (instancePair.first == instanceId) {
|
||||
metaAppIdPair = instancePair;
|
||||
instanceList.remove(instancePair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(reportMut_);
|
||||
auto reportUidToMediaInfo = reportMediaInfoMap_.find(uid);
|
||||
if (reportUidToMediaInfo != reportMediaInfoMap_.end()) {
|
||||
reportUidToMediaInfo->second.push_back(metaAppIdPair);
|
||||
} else {
|
||||
reportMediaInfoMap_[uid].push_back(metaAppIdPair);
|
||||
}
|
||||
g_reachMaxMapSize = (reportMediaInfoMap_.size() >= MAX_MAP_SIZE);
|
||||
}
|
||||
|
||||
int32_t DrmEvent::StatisticsEventReport()
|
||||
{
|
||||
DRM_INFO_LOG("StatisticsEventReport.");
|
||||
if (reportMediaInfoMap_.empty()) {
|
||||
DRM_INFO_LOG("reportMediaInfoMap_ is empty, can't report.");
|
||||
return DRM_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
DrmStatisicsEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, reportMediaInfoMap_);
|
||||
auto currentTime = std::chrono::system_clock::now();
|
||||
currentTime_ = currentTime;
|
||||
reportMediaInfoMap_.clear();
|
||||
return DRM_ERR_OK;
|
||||
}
|
||||
|
||||
void DrmEvent::WriteServiceEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
DrmServiveInfo &info)
|
||||
{
|
||||
@@ -454,5 +245,37 @@ DownLoadInfo InitDownLoadInfo(uint32_t generationDuration, std::string generatio
|
||||
};
|
||||
return downLoadInfo;
|
||||
}
|
||||
|
||||
void ReportDecryptionStatisticsEvent(uint64_t instanceId, std::string appName,
|
||||
DecryptionStatistics &statistics)
|
||||
{
|
||||
DRM_INFO_LOG("ReportDecryptionStatisticsEvent.");
|
||||
|
||||
int32_t res = DRM_ERR_OK;
|
||||
if (statistics.decryptTimes < MIN_DECRYPTION_TIMES) {
|
||||
return;
|
||||
}
|
||||
uint32_t avgSize = statistics.decryptSumSize / statistics.decryptTimes;
|
||||
uint32_t avgDuration = statistics.decryptSumDuration / statistics.decryptTimes;
|
||||
|
||||
res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA,
|
||||
"DRM_STATISTICS",
|
||||
HiviewDFX::HiSysEvent::EventType::STATISTIC,
|
||||
"APP_NAME", appName,
|
||||
"INSTANCE_ID", instanceId,
|
||||
"ERROR_CODE", statistics.errCode,
|
||||
"ERROR_MESG", statistics.errMessage,
|
||||
"DECRYPT_TIMES", statistics.decryptTimes,
|
||||
"DECRYPT_AVG_SIZE", avgSize,
|
||||
"DECRYPT_AVG_DURATION", avgDuration,
|
||||
"DECRYPT_MAX_SIZE", statistics.decryptMaxSize,
|
||||
"DECRYPT_MAX_DURATION", statistics.decryptMaxDuration);
|
||||
if (res != DRM_ERR_OK) {
|
||||
DRM_ERR_LOG("DRM_STATISTICS Event Write failed, res = %d", res);
|
||||
} else {
|
||||
DRM_INFO_LOG("DRM_STATISTICS Event Write success");
|
||||
}
|
||||
DRM_INFO_LOG("ReportDecryptionStatisticsEvent done!");
|
||||
}
|
||||
} // namespace DrmStandard
|
||||
} // namespace OHOS
|
||||
@@ -18,11 +18,11 @@
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <refbase.h>
|
||||
#include "drm_dfx_utils.h"
|
||||
#include "nocopyable.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "meta/meta.h"
|
||||
#include "hisysevent.h"
|
||||
#include "hitrace/tracechain.h"
|
||||
#include <chrono>
|
||||
@@ -98,21 +98,21 @@ struct DownLoadInfo {
|
||||
std::string processResult;
|
||||
};
|
||||
|
||||
struct DecryptionStatistics {
|
||||
uint32_t decryptTimes = 0;
|
||||
uint64_t decryptSumSize = 0;
|
||||
uint64_t decryptSumDuration = 0;
|
||||
uint32_t decryptMaxSize = 0;
|
||||
uint32_t decryptMaxDuration = 0;
|
||||
uint64_t errorDecryptTimes = 0;
|
||||
int32_t errCode = 0;
|
||||
std::string errMessage = "no error";
|
||||
std::priority_queue<int, std::vector<int>, std::greater<int>> topThree;
|
||||
};
|
||||
|
||||
class DrmEvent {
|
||||
public:
|
||||
static DrmEvent& GetInstance();
|
||||
|
||||
void DrmStatisicsEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
const std::map<int32_t, std::list<std::pair<uint64_t, std::shared_ptr<Media::Meta>>>>& infoMap);
|
||||
void StatisicsHiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
const std::vector<std::string>& infoArr);
|
||||
void ParseOneEvent(const std::pair<uint64_t, std::shared_ptr<OHOS::Media::Meta>> &listPair,
|
||||
nlohmann::json& metaInfoJson);
|
||||
void CollectReportMediaInfo(uint64_t instanceId);
|
||||
int32_t AppendMediaInfo(const std::shared_ptr<Media::Meta>& meta, uint64_t instanceId);
|
||||
int32_t CreateMediaInfo(int32_t uid, uint64_t instanceId);
|
||||
int32_t ReportMediaInfo(uint64_t instanceId);
|
||||
int32_t StatisticsEventReport();
|
||||
void WriteServiceEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmServiveInfo &info);
|
||||
void WriteLicenseEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type, DrmLicenseInfo &info);
|
||||
void WriteCertificateEvent(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
@@ -133,6 +133,8 @@ __attribute__((visibility("default"))) void ReportDecryptionFaultEvent(int32_t e
|
||||
std::string decryptAlgo, std::string decryptKeyid, std::string decryptIv);
|
||||
__attribute__((visibility("default"))) DownLoadInfo InitDownLoadInfo(uint32_t generationDuration,
|
||||
std::string generationResult, uint32_t processDuration, std::string processResult);
|
||||
__attribute__((visibility("default"))) void ReportDecryptionStatisticsEvent(uint64_t instanceId, std::string appName,
|
||||
DecryptionStatistics &statistics);
|
||||
} // namespace DrmStandard
|
||||
} // namespace OHOS
|
||||
#endif // DRM_DFX_H
|
||||
@@ -32,8 +32,6 @@ namespace DrmStandard {
|
||||
uint32_t __attribute__((visibility("default"))) CalculateTimeDiff(std::chrono::system_clock::time_point timeBefore,
|
||||
std::chrono::system_clock::time_point timeAfter);
|
||||
const int minimumDigit = 2;
|
||||
const std::string version = "version";
|
||||
const std::string vendor = "vendor";
|
||||
} // namespace DrmStandard
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user