mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-23 06:50:35 +00:00
增加UDMF行为事件打点
Signed-off-by: anqi <anqi20@huawei.com>
This commit is contained in:
parent
b3c800599f
commit
e61443fce0
@ -100,6 +100,15 @@ DATABASE_BEHAVIOUR:
|
||||
STORE_ID: {type: STRING, desc: store id }
|
||||
BEHAVIOUR_INFO: {type: STRING, desc: behaviour type and behaviour resulte }
|
||||
|
||||
UDMF_DATA_BEHAVIOR:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: The event is behaviour record }
|
||||
APP_ID: {type: STRING, desc: app id }
|
||||
CHANNEL: {type: STRING, desc: channel name }
|
||||
DATA_SIZE: {type: INT64, desc: data size }
|
||||
DATA_TYPE: {type: STRING, desc: data type }
|
||||
OPERATION: {type: STRING, desc: data operation }
|
||||
RESULT: {type: STRING, desc: data operation result }
|
||||
|
||||
OPEN_DATABASE_FAILED:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: The database open failed}
|
||||
APP_ID: {type: STRING, desc: app id }
|
||||
|
@ -12,7 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "behaviour_reporter_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -22,6 +21,13 @@ ReportStatus BehaviourReporterImpl::Report(const BehaviourMsg &msg)
|
||||
HiViewAdapter::ReportBehaviour(DfxCodeConstant::DATABASE_BEHAVIOUR, msg, executors_);
|
||||
return ReportStatus::SUCCESS;
|
||||
}
|
||||
|
||||
ReportStatus BehaviourReporterImpl::UDMFReport(const UDMFBehaviourMsg &msg)
|
||||
{
|
||||
HiViewAdapter::ReportUDMFBehaviour(DfxCodeConstant::UDMF_DATA_BEHAVIOR, msg, executors_);
|
||||
return ReportStatus::SUCCESS;
|
||||
}
|
||||
|
||||
void BehaviourReporterImpl::SetThreadPool(std::shared_ptr<ExecutorPool> executors)
|
||||
{
|
||||
executors_ = executors;
|
||||
|
@ -25,6 +25,7 @@ class BehaviourReporterImpl : public BehaviourReporter {
|
||||
public:
|
||||
virtual ~BehaviourReporterImpl() {}
|
||||
ReportStatus Report(const struct BehaviourMsg &msg) override;
|
||||
ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) override;
|
||||
void SetThreadPool(std::shared_ptr<ExecutorPool> executors);
|
||||
|
||||
private:
|
||||
|
@ -32,5 +32,6 @@ public:
|
||||
static inline const int DATABASE_CORRUPTED_FAILED = 950001113;
|
||||
static inline const int DATABASE_REKEY_FAILED = 950001114;
|
||||
static inline const int DATABASE_BEHAVIOUR = 950001115;
|
||||
static inline const int UDMF_DATA_BEHAVIOR = 950001116;
|
||||
};
|
||||
#endif // DISTRIBUTEDDATAMGR_DFX_CODE_CONSTANT_H
|
||||
|
@ -47,6 +47,11 @@ constexpr const char *TAG = "TAG";
|
||||
constexpr const char *POWERSTATS = "PowerStats";
|
||||
// behaviour key
|
||||
constexpr const char *BEHAVIOUR_INFO = "BEHAVIOUR_INFO";
|
||||
constexpr const char *CHANNEL = "CHANNEL";
|
||||
constexpr const char *DATA_SIZE = "DATA_SIZE";
|
||||
constexpr const char *DATA_TYPE = "DATA_TYPE";
|
||||
constexpr const char *OPERATION = "OPERATION";
|
||||
constexpr const char *RESULT = "RESULT";
|
||||
|
||||
const std::map<int, std::string> EVENT_COVERT_TABLE = {
|
||||
{ DfxCodeConstant::SERVICE_FAULT, "SERVICE_FAULT" },
|
||||
@ -63,6 +68,7 @@ const std::map<int, std::string> EVENT_COVERT_TABLE = {
|
||||
{ DfxCodeConstant::DATABASE_CORRUPTED_FAILED, "DATABASE_CORRUPTED_FAILED" },
|
||||
{ DfxCodeConstant::DATABASE_REKEY_FAILED, "DATABASE_REKEY_FAILED" },
|
||||
{ DfxCodeConstant::DATABASE_BEHAVIOUR, "DATABASE_BEHAVIOUR" },
|
||||
{ DfxCodeConstant::UDMF_DATA_BEHAVIOR, "UDMF_DATA_BEHAVIOR" },
|
||||
};
|
||||
}
|
||||
using OHOS::HiviewDFX::HiSysEvent;
|
||||
@ -298,6 +304,23 @@ void HiViewAdapter::ReportApiPerformanceStatistic(int dfxCode, const ApiPerforma
|
||||
StartTimerThread(executors);
|
||||
}
|
||||
|
||||
void HiViewAdapter::ReportUDMFBehaviour(
|
||||
int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors)
|
||||
{
|
||||
ExecutorPool::Task task([dfxCode, msg]() {
|
||||
HiSysEventWrite(HiSysEvent::Domain::DISTRIBUTED_DATAMGR,
|
||||
CoverEventID(dfxCode),
|
||||
HiSysEvent::EventType::BEHAVIOR,
|
||||
APP_ID, msg.appId,
|
||||
CHANNEL, msg.channel,
|
||||
DATA_SIZE, msg.dataSize,
|
||||
DATA_TYPE, msg.dataType,
|
||||
OPERATION, msg.operation,
|
||||
RESULT, msg.result);
|
||||
});
|
||||
executors->Execute(std::move(task));
|
||||
}
|
||||
|
||||
void HiViewAdapter::InvokeApiPerformance()
|
||||
{
|
||||
std::string message;
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
static void ReportApiPerformanceStatistic(int dfxCode, const ApiPerformanceStat &stat,
|
||||
std::shared_ptr<ExecutorPool> executors);
|
||||
static void ReportBehaviour(int dfxCode, const BehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors);
|
||||
static void ReportUDMFBehaviour(int dfxCode, const UDMFBehaviourMsg &msg, std::shared_ptr<ExecutorPool> executors);
|
||||
static void StartTimerThread(std::shared_ptr<ExecutorPool> executors);
|
||||
|
||||
private:
|
||||
|
@ -23,6 +23,7 @@ namespace DistributedDataDfx {
|
||||
class BehaviourReporter {
|
||||
public:
|
||||
KVSTORE_API virtual ReportStatus Report(const BehaviourMsg &msg) = 0;
|
||||
KVSTORE_API virtual ReportStatus UDMFReport(const UDMFBehaviourMsg &msg) = 0;
|
||||
KVSTORE_API virtual ~BehaviourReporter() {}
|
||||
};
|
||||
} // namespace DistributedDataDfx
|
||||
|
@ -131,6 +131,15 @@ struct BehaviourMsg {
|
||||
std::string extensionInfo;
|
||||
};
|
||||
|
||||
struct UDMFBehaviourMsg {
|
||||
std::string appId;
|
||||
std::string channel;
|
||||
int64_t dataSize;
|
||||
std::string dataType;
|
||||
std::string operation;
|
||||
std::string result;
|
||||
};
|
||||
|
||||
struct VisitStat {
|
||||
std::string appId;
|
||||
std::string interfaceName;
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
void SetThreadPool(std::shared_ptr<ExecutorPool> executors)
|
||||
{
|
||||
executors_ = executors;
|
||||
if (executors == nullptr) {
|
||||
if (executors != nullptr) {
|
||||
ServiceFault();
|
||||
RuntimeFault();
|
||||
DatabaseFault();
|
||||
|
@ -17,19 +17,21 @@ config("module_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"${udmf_path}/framework/common",
|
||||
"${udmf_path}/interfaces/innerkits/common",
|
||||
"${udmf_path}/interfaces/innerkits/data",
|
||||
"${data_service_path}/framework/include",
|
||||
"${data_service_path}/adapter/include/communicator",
|
||||
"${data_service_path}/adapter/include/dfx",
|
||||
"${data_service_path}/service/udmf/lifecycle",
|
||||
"${data_service_path}/service/udmf/permission",
|
||||
"${data_service_path}/service/udmf/preprocess",
|
||||
"${data_service_path}/service/udmf/store",
|
||||
"${data_service_path}/service/udmf",
|
||||
"${kv_store_path}/frameworks/common",
|
||||
"${file_service_path}/interfaces/innerkits/native/remote_file_share/include",
|
||||
"${device_manager_path}/interfaces/inner_kits/native_cpp/include",
|
||||
"${data_service_path}/adapter/include/communicator",
|
||||
"${file_service_path}/interfaces/innerkits/native/remote_file_share/include",
|
||||
"${kv_store_path}/interfaces/innerkits/distributeddata/include",
|
||||
"${kv_store_common_path}",
|
||||
"${udmf_path}/framework/common",
|
||||
"${udmf_path}/interfaces/innerkits/common",
|
||||
"${udmf_path}/interfaces/innerkits/data",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "data_manager.h"
|
||||
|
||||
#include "checker_manager.h"
|
||||
#include "dfx_types.h"
|
||||
#include "file.h"
|
||||
#include "lifecycle/lifecycle_manager.h"
|
||||
#include "log_print.h"
|
||||
@ -151,6 +152,7 @@ int32_t DataManager::RetrieveData(const QueryOption &query, UnifiedData &unified
|
||||
ZLOGE("Remove data failed, intention: %{public}s.", key.intention.c_str());
|
||||
return E_DB_ERROR;
|
||||
}
|
||||
PreProcessUtils::SetRemoteData(unifiedData);
|
||||
return E_OK;
|
||||
}
|
||||
std::string DataManager::ConvertUri(std::shared_ptr<UnifiedRecord> record, const std::string &localDevId,
|
||||
@ -181,7 +183,8 @@ int32_t DataManager::RetrieveBatchData(const QueryOption &query, std::vector<Uni
|
||||
ZLOGW("DataSet has no data, key: %{public}s, intention: %{public}d.", query.key.c_str(), query.intention);
|
||||
return E_OK;
|
||||
}
|
||||
for (const auto &data : dataSet) {
|
||||
for (auto &data : dataSet) {
|
||||
PreProcessUtils::SetRemoteData(data);
|
||||
unifiedDataSet.push_back(data);
|
||||
}
|
||||
return E_OK;
|
||||
|
@ -12,23 +12,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "preprocess_utils"
|
||||
#define LOG_TAG "PreProcessUtils"
|
||||
|
||||
#include "preprocess_utils.h"
|
||||
|
||||
#include <sstream>
|
||||
#include "error_code.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "bundlemgr/bundle_mgr_client_impl.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "device_manager_adapter.h"
|
||||
#include "error_code.h"
|
||||
#include "file.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "log_print.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
static constexpr int ID_LEN = 32;
|
||||
const char SPECIAL = '^';
|
||||
using namespace Security::AccessToken;
|
||||
int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &option)
|
||||
{
|
||||
auto it = UD_INTENTION_MAP.find(option.intention);
|
||||
@ -52,12 +54,6 @@ int32_t PreProcessUtils::RuntimeDataImputation(UnifiedData &data, CustomOption &
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
std::string PreProcessUtils::GetLocalDeviceId()
|
||||
{
|
||||
auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice();
|
||||
return DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid);
|
||||
}
|
||||
|
||||
std::string PreProcessUtils::IdGenerator()
|
||||
{
|
||||
std::random_device randomDevice;
|
||||
@ -113,5 +109,37 @@ bool PreProcessUtils::GetNativeProcessNameByToken(int tokenId, std::string &proc
|
||||
processName = nativeInfo.processName;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string PreProcessUtils::GetLocalDeviceId()
|
||||
{
|
||||
auto info = DistributedData::DeviceManagerAdapter::GetInstance().GetLocalDevice();
|
||||
std::string encryptedUuid = DistributedData::DeviceManagerAdapter::GetInstance().CalcClientUuid(" ", info.uuid);
|
||||
return encryptedUuid;
|
||||
}
|
||||
|
||||
void PreProcessUtils::SetRemoteData(UnifiedData &data)
|
||||
{
|
||||
if (data.IsEmpty()) {
|
||||
ZLOGD("invalid data.");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<Runtime> runtime = data.GetRuntime();
|
||||
if (runtime->deviceId == PreProcessUtils::GetLocalDeviceId()) {
|
||||
ZLOGD("not remote data.");
|
||||
return;
|
||||
}
|
||||
ZLOGD("is remote data.");
|
||||
auto records = data.GetRecords();
|
||||
for (auto record : records) {
|
||||
auto type = record->GetType();
|
||||
if (type == UDType::FILE || type == UDType::IMAGE || type == UDType::VIDEO || type == UDType::AUDIO
|
||||
|| type == UDType::FOLDER) {
|
||||
auto file = static_cast<File *>(record.get());
|
||||
UDDetails details = file->GetDetails();
|
||||
details.insert({"isRemote", "true"});
|
||||
file->SetDetails(details);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
@ -33,7 +33,8 @@ public:
|
||||
static int32_t GetHapUidByToken(uint32_t tokenId);
|
||||
static bool GetHapBundleNameByToken(int tokenId, std::string &bundleName);
|
||||
static bool GetNativeProcessNameByToken(int tokenId, std::string &processName);
|
||||
static std::string GetLocalDeviceId(); // uuid
|
||||
static std::string GetLocalDeviceId();
|
||||
static void SetRemoteData(UnifiedData &data);
|
||||
};
|
||||
} // namespace UDMF
|
||||
} // namespace OHOS
|
||||
|
@ -22,10 +22,13 @@
|
||||
#include "lifecycle/lifecycle_manager.h"
|
||||
#include "log_print.h"
|
||||
#include "preprocess_utils.h"
|
||||
#include "reporter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UDMF {
|
||||
using FeatureSystem = DistributedData::FeatureSystem;
|
||||
using UDMFBehaviourMsg = OHOS::DistributedDataDfx::UDMFBehaviourMsg;
|
||||
using Reporter = OHOS::DistributedDataDfx::Reporter;
|
||||
__attribute__((used)) UdmfServiceImpl::Factory UdmfServiceImpl::factory_;
|
||||
UdmfServiceImpl::Factory::Factory()
|
||||
{
|
||||
@ -46,13 +49,49 @@ UdmfServiceImpl::Factory::~Factory()
|
||||
int32_t UdmfServiceImpl::SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key)
|
||||
{
|
||||
ZLOGD("start");
|
||||
return DataManager::GetInstance().SaveData(option, unifiedData, key);
|
||||
int32_t res = E_OK;
|
||||
UDMFBehaviourMsg msg;
|
||||
auto find = UD_INTENTION_MAP.find(option.intention);
|
||||
msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second;
|
||||
msg.operation = "insert";
|
||||
std::string bundleName;
|
||||
if (!PreProcessUtils::GetHapBundleNameByToken(option.tokenId, bundleName)) {
|
||||
msg.appId = "unknown";
|
||||
res = E_ERROR;
|
||||
} else {
|
||||
msg.appId = bundleName;
|
||||
res = DataManager::GetInstance().SaveData(option, unifiedData, key);
|
||||
}
|
||||
msg.result = ERROR_MAP.find(res)->second;
|
||||
std::vector<UDType> types = unifiedData.GetUDTypes();
|
||||
msg.dataType = unifiedData.GetTypes();
|
||||
msg.dataSize = unifiedData.GetSize();
|
||||
Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t UdmfServiceImpl::GetData(const QueryOption &query, UnifiedData &unifiedData)
|
||||
{
|
||||
ZLOGD("start");
|
||||
return DataManager::GetInstance().RetrieveData(query, unifiedData);
|
||||
int32_t res = E_OK;
|
||||
UDMFBehaviourMsg msg;
|
||||
auto find = UD_INTENTION_MAP.find(query.intention);
|
||||
msg.channel = find == UD_INTENTION_MAP.end() ? "invalid" : find->second;
|
||||
msg.operation = "insert";
|
||||
std::string bundleName;
|
||||
if (!PreProcessUtils::GetHapBundleNameByToken(query.tokenId, bundleName)) {
|
||||
msg.appId = "unknown";
|
||||
res = E_ERROR;
|
||||
} else {
|
||||
msg.appId = bundleName;
|
||||
res = DataManager::GetInstance().RetrieveData(query, unifiedData);
|
||||
}
|
||||
msg.result = ERROR_MAP.find(res)->second;
|
||||
std::vector<UDType> types = unifiedData.GetUDTypes();
|
||||
msg.dataType = unifiedData.GetTypes();
|
||||
msg.dataSize = unifiedData.GetSize();
|
||||
Reporter::GetInstance()->BehaviourReporter()->UDMFReport(msg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t UdmfServiceImpl::GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet)
|
||||
|
Loading…
Reference in New Issue
Block a user