fix: disc and auth stats update

Signed-off-by: qinhao <qinhao43@huawei.com>
This commit is contained in:
qinhao 2024-01-12 16:11:27 +08:00
parent f0dbe54296
commit 1718e23feb
20 changed files with 238 additions and 131 deletions

View File

@ -556,9 +556,8 @@ static void DfxRecordLnnConnectStart(const AuthConnInfo *connInfo)
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
if (connInfo != NULL) {
extra.lnnType = connInfo->type;
extra.authLinkType = connInfo->type;
}
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, extra);
}
static int32_t PostCommData(uint32_t connectionId, bool toServer, const AuthDataHead *head, const uint8_t *data)

View File

@ -109,21 +109,21 @@ static void OnSessionKeyReturned(int64_t authSeq, const uint8_t *sessionKey, uin
(void)AuthSessionSaveSessionKey(authSeq, sessionKey, sessionKeyLen);
}
static void DfxRecordLnnAuthEnd(int64_t authSeq, int32_t reason)
static void DfxRecordLnnEndHichainEnd(int64_t authSeq, int32_t reason)
{
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
extra.authId = (int32_t)authSeq;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH, extra);
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_HICHAIN_END, extra);
}
static void OnFinish(int64_t authSeq, int operationCode, const char *returnData)
{
(void)operationCode;
(void)returnData;
DfxRecordLnnAuthEnd(authSeq, SOFTBUS_OK);
DfxRecordLnnEndHichainEnd(authSeq, SOFTBUS_OK);
AUTH_LOGI(AUTH_HICHAIN, "hichain OnFinish: authSeq=%{public}" PRId64, authSeq);
(void)AuthSessionHandleAuthFinish(authSeq);
}
@ -132,7 +132,7 @@ static void OnError(int64_t authSeq, int operationCode, int errCode, const char
{
(void)operationCode;
(void)errorReturn;
DfxRecordLnnAuthEnd(authSeq, errCode);
DfxRecordLnnEndHichainEnd(authSeq, errCode);
AUTH_LOGE(AUTH_HICHAIN, "hichain OnError: authSeq=%{public}" PRId64 ", errCode=%{public}d", authSeq, errCode);
(void)AuthSessionHandleAuthError(authSeq, SOFTBUS_AUTH_HICHAIN_AUTH_ERROR);
}
@ -271,7 +271,6 @@ static void DfxRecordLnnStartHichainEnd(int64_t authSeq, int32_t reason)
extra.authId = (int32_t)authSeq;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_HICHAIN, extra);
}
int32_t RegTrustDataChangeListener(const TrustDataChangeListener *listener)

View File

@ -717,7 +717,7 @@ static void DfxRecordLnnAuthStart(const AuthConnInfo *connInfo)
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
if (connInfo != NULL) {
extra.lnnType = connInfo->type;
extra.authLinkType = connInfo->type;
}
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH, extra);
}
@ -1044,7 +1044,7 @@ static void DfxRecordLnnConnectEnd(uint64_t connId, const AuthConnInfo *connInfo
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
if (connInfo != NULL) {
extra.lnnType = connInfo->type;
extra.authLinkType = connInfo->type;
}
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_CONNECTION, extra);
}

View File

@ -306,6 +306,21 @@ static SoftBusLinkType ConvertAuthLinkTypeToHisysEvtLinkType(AuthLinkType type)
}
}
static void DfxRecordLnnAuthEnd(AuthFsm *authFsm, uint64_t costTime, int32_t reason)
{
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
extra.errcode = reason;
extra.authCostTime = (int32_t)costTime;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
if (authFsm != NULL) {
extra.authLinkType = authFsm->info.connInfo.type;
extra.authId = (int32_t)authFsm->authSeq;
}
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH, extra);
}
static void ReportAuthResultEvt(AuthFsm *authFsm, int32_t result)
{
AUTH_LOGE(AUTH_FSM, "report auth result evt enter");
@ -315,6 +330,7 @@ static void ReportAuthResultEvt(AuthFsm *authFsm, int32_t result)
}
authFsm->statisticData.endAuthTime = LnnUpTimeMs();
uint64_t costTime = authFsm->statisticData.endAuthTime - authFsm->statisticData.startAuthTime;
DfxRecordLnnAuthEnd(authFsm, costTime, result);
AuthFailStage stage;
switch (result) {
case SOFTBUS_OK:

View File

@ -1566,7 +1566,6 @@ static void DfxRecordLnnProcessDeviceIdStart(void)
{
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_DEVICE_ID_PROCESS, extra);
}
int32_t PostDeviceIdMessage(int64_t authSeq, const AuthSessionInfo *info)
@ -1621,7 +1620,6 @@ static void DfxRecordLnnProcessDeviceInfoStart(int64_t authSeq)
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
extra.authId = (int32_t)authSeq;
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_AUTH_DEVICE_INFO_PROCESS, extra);
}
int32_t PostDeviceInfoMessage(int64_t authSeq, const AuthSessionInfo *info)

View File

@ -847,7 +847,6 @@ static void OnlineStateEnter(FsmStateMachine *fsm)
{
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
LNN_EVENT(EVENT_SCENE_JOIN_LNN, EVENT_STAGE_JOIN_LNN_END, extra);
LnnConnectionFsm *connFsm = NULL;
if (!CheckStateMsgCommonArgs(fsm)) {
@ -954,7 +953,6 @@ static void LeavingStateEnter(FsmStateMachine *fsm)
{
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
LNN_EVENT(EVENT_SCENE_LEAVE_LNN, EVENT_STAGE_LEAVE_LNN, extra);
LnnConnectionFsm *connFsm = NULL;
int32_t rc;
LnnConntionInfo *connInfo = NULL;

View File

@ -1706,7 +1706,7 @@ static void DfxRecordLnnAddOnlineNodeEnd(NodeInfo *info, int32_t onlineNum, int3
extra.peerUdid = udidData;
}
char bleMacAddr[MAC_LEN] = { 0 };
if (strncpy_s(bleMacAddr, MAC_LEN, info->deviceInfo.deviceUdid, MAC_LEN - 1) == EOK) {
if (strncpy_s(bleMacAddr, MAC_LEN, info->connectInfo.bleMacAddr, MAC_LEN - 1) == EOK) {
extra.peerBleMac = bleMacAddr;
}
char deviceType[DEVICE_TYPE_SIZE_LEN + 1] = { 0 };

View File

@ -36,12 +36,13 @@ extern "C" {
LNN_ASSIGNER(Errcode, Result, result)
LNN_ASSIGNER(Errcode, Errcode, errcode)
LNN_ASSIGNER(Errcode, AuthId, authId)
LNN_ASSIGNER(Int32, DiscServerType, discServerType)
LNN_ASSIGNER(Int32, GearCycle, gearCycle)
LNN_ASSIGNER(Int32, GearDuration, gearDuration)
LNN_ASSIGNER(Int32, ConnectionId, connectionId)
LNN_ASSIGNER(Int32, AuthType, authType)
LNN_ASSIGNER(Int32, AuthId, authId)
LNN_ASSIGNER(Int32, AuthLinkType, authLinkType)
LNN_ASSIGNER(Int32, AuthCostTime, authCostTime)
LNN_ASSIGNER(Int32, LnnType, lnnType)
LNN_ASSIGNER(Int32, OnlineNum, onlineNum)
LNN_ASSIGNER(Int32, PeerDeviceAbility, peerDeviceAbility)
@ -57,16 +58,17 @@ LNN_ASSIGNER(String, PeerDeviceType, peerDeviceType)
LNN_ASSIGNER(String, CallerPkg, callerPkg)
LNN_ASSIGNER(String, CalleePkg, calleePkg)
#define LNN_ASSIGNER_SIZE 22 // Size of g_connAssigners
#define LNN_ASSIGNER_SIZE 23 // Size of g_connAssigners
static const HiSysEventParamAssigner g_lnnAssigners[] = {
{ "STAGE_RES", HISYSEVENT_INT32, LnnAssignerResult },
{ "ERROR_CODE", HISYSEVENT_INT32, LnnAssignerErrcode },
{ "AUTH_ID", HISYSEVENT_INT32, LnnAssignerAuthId },
{ "DISC_SERVER_TYPE", HISYSEVENT_INT32, LnnAssignerDiscServerType },
{ "GEAR_CYCLE", HISYSEVENT_INT32, LnnAssignerGearCycle },
{ "GEAR_DURATION", HISYSEVENT_INT32, LnnAssignerGearDuration },
{ "CONN_ID", HISYSEVENT_INT32, LnnAssignerConnectionId },
{ "AUTH_TYPE", HISYSEVENT_INT32, LnnAssignerAuthType },
{ "AUTH_ID", HISYSEVENT_INT32, LnnAssignerAuthId },
{ "AUTH_LINK_TYPE", HISYSEVENT_INT32, LnnAssignerAuthLinkType },
{ "AUTH_COST_TIME", HISYSEVENT_INT32, LnnAssignerAuthCostTime },
{ "LNN_TYPE", HISYSEVENT_INT32, LnnAssignerLnnType },
{ "ONLINE_NUM", HISYSEVENT_INT32, LnnAssignerOnlineNum },
{ "PEER_DEV_ABILITY", HISYSEVENT_INT32, LnnAssignerPeerDeviceAbility},

View File

@ -35,18 +35,22 @@
#define BIZ_SCENE_NAME "BIZ_SCENE"
#define BIZ_STAGE_NAME "BIZ_STAGE"
#define STAGE_RES_NAME "STAGE_RES"
#define DISC_TYPE_NAME "DISC_TYPE"
#define ERROR_CODE_NAME "ERROR_CODE"
#define FIRST_DISCOVERY_TIME_NAME "FIRST_DISCOVERY_TIME"
#define ONLINE_NUM_NAME "ONLINE_NUM"
#define AUTH_COST_TIME_NAME "AUTH_COST_TIME"
#define AUTH_LINK_TYPE_NAME "AUTH_LINK_TYPE"
#define LINK_TYPE_NAME "LINK_TYPE"
#define SESSION_NAME "SESSION_NAME"
#define SOCKET_KEY_NAME "SOCKET_NAME"
#define TIME_CONSUMING_NAME "COST_TIME"
#define BT_FLOW_NAME "BT_FLOW"
#define CALLER_PID_NAME "CALLER_PID"
#define ERROR_CODE_NAME "ERROR_CODE"
#define LINK_TYPE_NAME "LINK_TYPE"
#define MIN_BW_NAME "MIN_BW"
#define METHOD_ID_NAME "METHOD_ID"
#define PERMISSION_NAME "PERMISSION_NAME"
#define SESSION_NAME "SESSION_NAME"
#define AUTH_LINK_TYPE_NAME "AUTH_TYPE"
#define SOCKET_KEY_NAME "SOCKET_NAME"
#define MODULE_NAME_DISC "disc"
#define MODULE_NAME_TRANS "trans"
#define MODULE_NAME_CONN "conn"
#define MODULE_NAME_AUTH "auth"
@ -70,6 +74,7 @@
typedef void (*HandleMessageFunc)(SoftBusMessage* msg);
typedef enum {
SOFTBUS_DISCOVERY_STATS_TYPE,
SOFTBUS_CONNECTION_STATS_TYPE,
SOFTBUS_BUSCENTER_STATS_TYPE,
SOFTBUS_TRANSPORT_STATS_TYPE,
@ -83,6 +88,11 @@ typedef struct {
int32_t dataSize;
} HiSysEventQueryParam;
typedef struct {
int32_t delayTimeFirstDiscovery[MEDIUM_BUTT + 1];
int32_t delayNumFirstDiscovery[MEDIUM_BUTT + 1];
} DiscStatsInfo;
typedef struct {
int32_t connFailTotal;
int32_t connSuccessTotal;
@ -95,6 +105,8 @@ typedef struct {
int32_t authSuccessTotal;
int32_t authLinkTypeTotal[AUTH_LINK_TYPE_MAX];
int32_t authLinkTypeSuccessTotal[AUTH_LINK_TYPE_MAX];
int64_t delayTimeAuth[AUTH_LINK_TYPE_MAX];
int32_t delayNumAuth[AUTH_LINK_TYPE_MAX];
int32_t onlineDevMaxNum;
int32_t joinLnnNum;
int32_t leaveLnnNum;
@ -133,6 +145,7 @@ typedef struct {
static bool g_isDumperInit = false;
static bool g_isDiscQueryEnd = false;
static bool g_isConnQueryEnd = false;
static bool g_isLnnQueryEnd = false;
static bool g_isTransQueryEnd = false;
@ -140,6 +153,7 @@ static bool g_isAlarmQueryEnd = false;
static SoftBusMutex g_statsQueryLock = {0};
static SoftBusMutex g_alarmQueryLock = {0};
static SoftBusMutex g_discOnQueryLock = {0};
static SoftBusMutex g_connOnQueryLock = {0};
static SoftBusMutex g_lnnOnQueryLock = {0};
static SoftBusMutex g_transOnQueryLock = {0};
@ -147,8 +161,9 @@ static SoftBusMutex g_alarmOnQueryLock = {0};
static SoftBusMutex g_transMapLock = {0};
static bool g_isTransMapInit = false;
static DiscStatsInfo g_discStatsInfo = {{0}, {0}};
static ConnStatsInfo g_connStatsInfo = {0, 0, {0}, {0}};
static LnnStatsInfo g_lnnStatsInfo = {0, 0, {0}, {0}, 0, 0, 0};
static LnnStatsInfo g_lnnStatsInfo = {0, 0, {0}, {0}, {0}, {0}, 0, 0, 0};
static TransStatsInfo g_transStatsInfo = {0};
static SoftBusAlarmEvtResult g_alarmEvtResult = {0};
@ -216,6 +231,40 @@ static void GetLocalTime(char* time, uint64_t timestamp)
(void)strftime(time, SOFTBUS_ALARM_TIME_LEN, "%Y-%m-%d %H:%M:%S", tmInfo);
}
static void OnQueryDisc(HiSysEventRecordC srcRecord[], size_t size)
{
COMM_LOGI(COMM_DFX, "OnQueryDisc start");
if (SoftBusMutexLock(&g_discOnQueryLock) != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "disc query lock fail");
return;
}
for (size_t i = 0; i < size; i++) {
int32_t scene = GetInt32ValueByRecord(&srcRecord[i], BIZ_SCENE_NAME);
int32_t stage = GetInt32ValueByRecord(&srcRecord[i], BIZ_STAGE_NAME);
int32_t stageRes = GetInt32ValueByRecord(&srcRecord[i], STAGE_RES_NAME);
int32_t discFirstTime = GetInt32ValueByRecord(&srcRecord[i], FIRST_DISCOVERY_TIME_NAME);
if (scene != EVENT_SCENE_DISC || stage != EVENT_STAGE_DEVICE_FOUND
|| stageRes != EVENT_STAGE_RESULT_OK || discFirstTime == SOFTBUS_ERR) {
continue;
}
int32_t discType = GetInt32ValueByRecord(&srcRecord[i], DISC_TYPE_NAME);
if (discType < AUTO + 1 || discType >= MEDIUM_BUTT + 1) {
discType = SOFTBUS_ZERO;
}
g_discStatsInfo.delayTimeFirstDiscovery[discType] += discFirstTime;
g_discStatsInfo.delayNumFirstDiscovery[discType]++;
}
(void)SoftBusMutexUnlock(&g_discOnQueryLock);
}
static void OnCompleteDisc(int32_t reason, int32_t total)
{
COMM_LOGI(COMM_DFX, "OnCompleteDisc start, reason = %{public}d, total = %{public}d", reason, total);
g_isDiscQueryEnd = true;
}
static void ConnStatsLinkType(int32_t linkTypePara, bool success)
{
int32_t linkType = linkTypePara;
@ -260,33 +309,38 @@ static void OnQueryConn(HiSysEventRecordC srcRecord[], size_t size)
static void OnCompleteConn(int32_t reason, int32_t total)
{
COMM_LOGI(COMM_DFX, "OnCompleteConn start, reason=%{public}d, total=%{public}d", reason, total);
COMM_LOGI(COMM_DFX, "OnCompleteConn start, reason = %{public}d, total = %{public}d", reason, total);
g_isConnQueryEnd = true;
}
static void LnnStatsAuthLinkType(int32_t authLinkTypePara, bool success)
static void LnnStatsAuthLinkType(int32_t authLinkTypePara, int32_t authDelayTime, bool success)
{
int32_t authLinkType = authLinkTypePara;
if (authLinkType < AUTH_LINK_TYPE_WIFI || authLinkType >= AUTH_LINK_TYPE_MAX) {
authLinkType = SOFTBUS_ZERO;
}
g_lnnStatsInfo.authLinkTypeTotal[authLinkType]++;
if (success) {
g_lnnStatsInfo.authLinkTypeSuccessTotal[authLinkType]++;
if (!success) {
return;
}
g_lnnStatsInfo.authLinkTypeSuccessTotal[authLinkType]++;
if (authDelayTime != SOFTBUS_ERR) {
g_lnnStatsInfo.delayTimeAuth[authLinkType] += authDelayTime;
g_lnnStatsInfo.delayNumAuth[authLinkType]++;
}
}
static void LnnStats(int32_t scene, int32_t stage, int32_t stageRes, int32_t authLinkType)
static void LnnStats(int32_t scene, int32_t stage, int32_t stageRes, int32_t authLinkType, int32_t authDelayTime)
{
if (scene == EVENT_SCENE_JOIN_LNN && stage == EVENT_STAGE_AUTH && stageRes == EVENT_STAGE_RESULT_OK) {
g_lnnStatsInfo.authSuccessTotal++;
LnnStatsAuthLinkType(authLinkType, true);
LnnStatsAuthLinkType(authLinkType, authDelayTime, true);
return;
}
if (scene == EVENT_SCENE_JOIN_LNN && stage == EVENT_STAGE_AUTH && stageRes == EVENT_STAGE_RESULT_FAILED) {
g_lnnStatsInfo.authFailTotal++;
LnnStatsAuthLinkType(authLinkType, false);
LnnStatsAuthLinkType(authLinkType, authDelayTime, false);
return;
}
@ -318,10 +372,12 @@ static void OnQueryLnn(HiSysEventRecordC srcRecord[], size_t size)
}
int32_t authLinkType = GetInt32ValueByRecord(&srcRecord[i], AUTH_LINK_TYPE_NAME);
LnnStats(scene, stage, stageRes, authLinkType);
int32_t onlineMaxNum = g_lnnStatsInfo.onlineDevMaxNum;
int32_t authDelayTime = GetInt32ValueByRecord(&srcRecord[i], AUTH_COST_TIME_NAME);
LnnStats(scene, stage, stageRes, authLinkType, authDelayTime);
int32_t onlineNum = GetInt32ValueByRecord(&srcRecord[i], ONLINE_NUM_NAME);
if (onlineNum != SOFTBUS_ERR) {
int32_t onlineMaxNum = g_lnnStatsInfo.onlineDevMaxNum;
g_lnnStatsInfo.onlineDevMaxNum = (onlineMaxNum > onlineNum) ? onlineMaxNum : onlineNum;
}
}
@ -330,7 +386,7 @@ static void OnQueryLnn(HiSysEventRecordC srcRecord[], size_t size)
static void OnCompleteLnn(int32_t reason, int32_t total)
{
COMM_LOGI(COMM_DFX, "OnCompleteLnn start, reason=%{public}d, total=%{public}d", reason, total);
COMM_LOGI(COMM_DFX, "OnCompleteLnn start, reason = %{public}d, total = %{public}d", reason, total);
g_isLnnQueryEnd = true;
}
@ -374,7 +430,7 @@ static void TransStatsSuccessDetail(bool success, const char *socketName, int32_
}
if (LnnMapSet(&g_transStatsInfo.sessionNameLinkTypeMap, keyStr, (const void *)&newResult,
sizeof(TransStatsSuccessRateDetail)) != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "insert fail. keyStr=%{public}s", keyStr);
COMM_LOGE(COMM_DFX, "insert fail. keyStr = %{public}s", keyStr);
}
TransMapUnlock();
return;
@ -481,7 +537,7 @@ static void OnQueryTrans(HiSysEventRecordC srcRecord[], size_t size)
static void OnCompleteTrans(int32_t reason, int32_t total)
{
COMM_LOGI(COMM_DFX, "OnCompleteTrans start, reason=%{public}d, total=%{public}d", reason, total);
COMM_LOGI(COMM_DFX, "OnCompleteTrans start, reason = %{public}d, total = %{public}d", reason, total);
g_isTransQueryEnd = true;
}
@ -543,7 +599,7 @@ static void OnQueryAlarm(HiSysEventRecordC srcRecord[], size_t size)
static void OnCompleteAlarm(int32_t reason, int32_t total)
{
COMM_LOGI(COMM_DFX, "OnCompleteAlarm start, reason=%{public}d, total=%{public}d", reason, total);
COMM_LOGI(COMM_DFX, "OnCompleteAlarm start, reason = %{public}d, total = %{public}d", reason, total);
g_isAlarmQueryEnd = true;
}
@ -555,10 +611,10 @@ static void SoftBusEventQueryInfo(int time, HiSysEventQueryParam* queryParam)
queryArg.maxEvents = queryParam->dataSize;
int32_t ret = OH_HiSysEvent_Query(&queryArg, queryParam->queryRules, queryParam->eventSize, &queryParam->callback);
COMM_LOGI(COMM_DFX, "SoftBusHisEvtQuery result, reason=%{public}d", ret);
COMM_LOGI(COMM_DFX, "SoftBusHisEvtQuery result, reason = %{public}d", ret);
}
void GenerateTransSuccessRateString(MapIterator *it, char *res, uint64_t maxLen)
static void GenerateTransSuccessRateString(MapIterator *it, char *res, uint64_t maxLen)
{
char sessionName[SESSION_NAME_SIZE_MAX] = {0};
const char *key = (const char *)it->node->key;
@ -577,19 +633,17 @@ void GenerateTransSuccessRateString(MapIterator *it, char *res, uint64_t maxLen)
if (quantity->total > 0) {
rate = 1.0 * quantity->successTotal / quantity->total * RATE_HUNDRED;
}
int32_t ret = sprintf_s(res, maxLen, "%s,%d,%d,%d,%2.2f,%d,%lld", sessionName, linkType, quantity->total,
quantity->successTotal, rate, quantity->delayNum, quantity->delay);
if (ret <= 0) {
COMM_LOGE(COMM_DFX, "sprintf_s fail");
if (sprintf_s(res, maxLen, "%s,%d,%d,%d,%2.2f,%"PRId64",%d", sessionName, linkType, quantity->total,
quantity->successTotal, rate, quantity->delay, quantity->delayNum) <= 0) {
COMM_LOGE(COMM_DFX, "GenerateTransSuccessRateString sprintf_s fail");
return;
}
}
void FillTransSuccessRateDetail(cJSON *transObj)
static void FillTransSuccessRateDetail(cJSON *transObj)
{
if (transObj == NULL) {
COMM_LOGE(COMM_DFX, "MODULE_NAME_TRANS json is add to root fail. MODULE_NAME_TRANS=%{public}s",
MODULE_NAME_TRANS);
COMM_LOGE(COMM_DFX, "trans json is add to root fail");
return;
}
if (TransMapLock() != SOFTBUS_OK) {
@ -614,10 +668,27 @@ void FillTransSuccessRateDetail(cJSON *transObj)
TransMapUnlock();
}
void FillConnSuccessRateDetail(cJSON *connObj)
static void FillDiscSuccessRateDetail(cJSON *connObj)
{
if (connObj == NULL) {
COMM_LOGE(COMM_DFX, "MODULE_NAME_CONN json is add to root fail. MODULE_NAME_CONN=%{public}s", MODULE_NAME_CONN);
COMM_LOGE(COMM_DFX, "disc json is add to root fail");
return;
}
for (int i = SOFTBUS_ZERO; i < MEDIUM_BUTT + 1; i++) {
char detail[MAX_LENGTH_OF_SUCCESS_RATE] = {0};
if (sprintf_s(detail, sizeof(detail), "%d,,,,%"PRId64",%d", i, g_discStatsInfo.delayTimeFirstDiscovery[i],
g_discStatsInfo.delayNumFirstDiscovery[i]) <= 0) {
COMM_LOGE(COMM_DFX, "FillDiscSuccessRateDetail sprintf_s fail");
return;
}
cJSON_AddItemToArray(connObj, cJSON_CreateString(detail));
}
}
static void FillConnSuccessRateDetail(cJSON *connObj)
{
if (connObj == NULL) {
COMM_LOGE(COMM_DFX, "conn json is add to root fail");
return;
}
for (int i = SOFTBUS_ZERO; i < CONNECT_TYPE_MAX; i++) {
@ -626,20 +697,19 @@ void FillConnSuccessRateDetail(cJSON *connObj)
rate = 1.0 * g_connStatsInfo.linkTypeSuccessTotal[i] / g_connStatsInfo.linkTypeTotal[i] * RATE_HUNDRED;
}
char detail[MAX_LENGTH_OF_SUCCESS_RATE] = {0};
int32_t ret = sprintf_s(detail, sizeof(detail), "%d,%d,%d,%2.2f", i, g_connStatsInfo.linkTypeTotal[i],
g_connStatsInfo.linkTypeSuccessTotal[i], rate);
if (ret <= 0) {
COMM_LOGE(COMM_DFX, "sprintf_s fail");
if (sprintf_s(detail, sizeof(detail), "%d,%d,%d,%2.2f", i, g_connStatsInfo.linkTypeTotal[i],
g_connStatsInfo.linkTypeSuccessTotal[i], rate) <= 0) {
COMM_LOGE(COMM_DFX, "FillConnSuccessRateDetail sprintf_s fail");
return;
}
cJSON_AddItemToArray(connObj, cJSON_CreateString(detail));
}
}
void FillAuthSuccessRateDetail(cJSON *authObj)
static void FillAuthSuccessRateDetail(cJSON *authObj)
{
if (authObj == NULL) {
COMM_LOGE(COMM_DFX, "MODULE_NAME_AUTH json is add to root fail. MODULE_NAME_AUTH=%{public}s", MODULE_NAME_AUTH);
COMM_LOGE(COMM_DFX, "auth json is add to root fail");
return;
}
for (int i = SOFTBUS_ZERO; i < AUTH_LINK_TYPE_MAX; i++) {
@ -649,17 +719,17 @@ void FillAuthSuccessRateDetail(cJSON *authObj)
1.0 * g_lnnStatsInfo.authLinkTypeSuccessTotal[i] / g_lnnStatsInfo.authLinkTypeTotal[i] * RATE_HUNDRED;
}
char detail[MAX_LENGTH_OF_SUCCESS_RATE] = {0};
int32_t ret = sprintf_s(detail, sizeof(detail), "%d,%d,%d,%2.2f", i, g_lnnStatsInfo.authLinkTypeTotal[i],
g_lnnStatsInfo.authLinkTypeSuccessTotal[i], rate);
if (ret <= 0) {
COMM_LOGE(COMM_DFX, "sprintf_s fail");
if (sprintf_s(detail, sizeof(detail), "%d,%d,%d,%2.2f,%"PRId64",%d", i, g_lnnStatsInfo.authLinkTypeTotal[i],
g_lnnStatsInfo.authLinkTypeSuccessTotal[i], rate, g_lnnStatsInfo.delayTimeAuth[i],
g_lnnStatsInfo.delayNumAuth[i]) <= 0) {
COMM_LOGE(COMM_DFX, "FillAuthSuccessRateDetailsprintf_s fail");
return;
}
cJSON_AddItemToArray(authObj, cJSON_CreateString(detail));
}
}
void FillSuccessRateDetail(SoftBusStatsResult *result)
static void FillSuccessRateDetail(SoftBusStatsResult *result)
{
cJSON *root_obj = cJSON_CreateObject();
if (root_obj == NULL) {
@ -668,6 +738,8 @@ void FillSuccessRateDetail(SoftBusStatsResult *result)
}
cJSON *transObj = cJSON_AddArrayToObject(root_obj, MODULE_NAME_TRANS);
FillTransSuccessRateDetail(transObj);
cJSON *discObj = cJSON_AddArrayToObject(root_obj, MODULE_NAME_DISC);
FillDiscSuccessRateDetail(discObj);
cJSON *connObj = cJSON_AddArrayToObject(root_obj, MODULE_NAME_CONN);
FillConnSuccessRateDetail(connObj);
cJSON *authObj = cJSON_AddArrayToObject(root_obj, MODULE_NAME_AUTH);
@ -722,6 +794,7 @@ static void SoftBusProcessStatsQueryData(SoftBusStatsResult* result)
return;
}
g_isDiscQueryEnd = false;
g_isConnQueryEnd = false;
g_isLnnQueryEnd = false;
g_isTransQueryEnd = false;
@ -757,7 +830,7 @@ int32_t SoftBusQueryStatsInfo(int time, SoftBusStatsResult* result)
{
COMM_LOGI(COMM_DFX, "SoftBusQueryStatsInfo start");
if (time <= SOFTBUS_ZERO || time > SEVEN_DAY_MINUTE) {
COMM_LOGE(COMM_DFX, "SoftBusQueryStatsInfo fail, time=%{public}d", time);
COMM_LOGE(COMM_DFX, "SoftBusQueryStatsInfo fail, time = %{public}d", time);
return SOFTBUS_ERR;
}
if (SoftBusMutexLock(&g_statsQueryLock) != SOFTBUS_OK) {
@ -767,7 +840,7 @@ int32_t SoftBusQueryStatsInfo(int time, SoftBusStatsResult* result)
for (int i = 0; i < STATS_UNUSE_BUTT; i++) {
SoftBusEventQueryInfo(time, &g_queryStatsParam[i]);
}
while (!g_isConnQueryEnd || !g_isLnnQueryEnd || !g_isTransQueryEnd) {
while (!g_isDiscQueryEnd || !g_isConnQueryEnd || !g_isLnnQueryEnd || !g_isTransQueryEnd) {
SoftBusSleepMs(WAIT_QUERY_TIME);
}
@ -780,11 +853,11 @@ int32_t SoftBusQueryAlarmInfo(int time, int type, SoftBusAlarmEvtResult* result)
{
COMM_LOGI(COMM_DFX, "SoftBusQueryAlarmInfo start");
if (time <= SOFTBUS_ZERO || time > SEVEN_DAY_MINUTE) {
COMM_LOGE(COMM_DFX, "QueryAlarmInfo fail, time=%{public}d", time);
COMM_LOGE(COMM_DFX, "QueryAlarmInfo fail, time = %{public}d", time);
return SOFTBUS_ERR;
}
if (type < SOFTBUS_MANAGEMENT_ALARM_TYPE || type >= ALARM_UNUSE_BUTT) {
COMM_LOGE(COMM_DFX, "QueryAlarmInfo fail, type=%{public}d", type);
COMM_LOGE(COMM_DFX, "QueryAlarmInfo fail, type = %{public}d", type);
return SOFTBUS_ERR;
}
if (SoftBusMutexLock(&g_alarmQueryLock) != SOFTBUS_OK) {
@ -823,6 +896,12 @@ static int32_t InitDumperUtilMutexLock(void)
return SOFTBUS_ERR;
}
if (SoftBusMutexInit(&g_discOnQueryLock, &mutexAttr) != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "init disc onQuery lock fail");
(void)SoftBusMutexDestroy(&g_discOnQueryLock);
return SOFTBUS_ERR;
}
if (SoftBusMutexInit(&g_connOnQueryLock, &mutexAttr) != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "init conn onQuery lock fail");
(void)SoftBusMutexDestroy(&g_connOnQueryLock);
@ -865,6 +944,12 @@ static void UpdateSysEventQueryParam(HiSysEventQueryParam* param, char* eventNam
static void InitSoftBusQueryEventParam(void)
{
HiSysEventQueryParam* discParam = &g_queryStatsParam[SOFTBUS_DISCOVERY_STATS_TYPE];
UpdateSysEventQueryParam(discParam, DISC_EVENT_NAME);
discParam->callback.OnQuery = OnQueryDisc;
discParam->callback.OnComplete = OnCompleteDisc;
discParam->dataSize = QUERY_EVENT_FULL_QUERY_PARAM;
HiSysEventQueryParam* connParam = &g_queryStatsParam[SOFTBUS_CONNECTION_STATS_TYPE];
UpdateSysEventQueryParam(connParam, CONN_EVENT_NAME);
connParam->callback.OnQuery = OnQueryConn;
@ -1022,7 +1107,6 @@ void SoftBusHidumperUtilDeInit(void)
return;
}
SoftBusFree(g_alarmEvtResult.records);
if (TransMapLock() != SOFTBUS_OK) {
COMM_LOGE(COMM_DFX, "lock TransMap fail");
}
@ -1030,11 +1114,14 @@ void SoftBusHidumperUtilDeInit(void)
TransMapUnlock();
SoftBusMutexDestroy(&g_transMapLock);
g_isTransMapInit = false;
SoftBusMutexDestroy(&g_statsQueryLock);
SoftBusMutexDestroy(&g_alarmQueryLock);
SoftBusMutexDestroy(&g_discOnQueryLock);
SoftBusMutexDestroy(&g_connOnQueryLock);
SoftBusMutexDestroy(&g_lnnOnQueryLock);
SoftBusMutexDestroy(&g_transOnQueryLock);
SoftBusMutexDestroy(&g_alarmOnQueryLock);
SoftBusFree(g_alarmEvtResult.records);
g_isDumperInit = false;
}

View File

@ -31,8 +31,6 @@ typedef enum {
EVENT_SCENE_SHARE_BLE = 4,
EVENT_SCENE_APPROACH_BLE = 5,
EVENT_SCENE_COAP = 6,
EVENT_SCENE_BROADCAST = 7,
EVENT_SCENE_SCAN = 8,
} DiscEventScene;
typedef enum {
@ -47,12 +45,16 @@ typedef enum {
EVENT_STAGE_DISC_SERVICE = 2,
EVENT_STAGE_ADD_INFO = 3,
EVENT_STAGE_CALL_INTERFACE = 4,
EVENT_STAGE_DEVICE_FOUND = 5,
} DiscEventDiscStage;
typedef enum {
EVENT_STAGE_BLE_PROCESS = 1,
EVENT_STAGE_BLE_HANDLER = 2,
EVENT_STAGE_STATE_TURN = 3,
EVENT_STAGE_BROADCAST = 4,
EVENT_STAGE_SCAN = 5,
EVENT_STAGE_SCAN_RECV = 6,
} DiscEventBleStage;
typedef enum {
@ -74,16 +76,6 @@ typedef enum {
EVENT_STAGE_DISCOVERY_STOP = 7,
} DiscEventCoapStage;
typedef enum {
EVENT_STAGE_BROADCAST = 1,
} DiscEventBroadcastStage;
typedef enum {
EVENT_STAGE_SCAN_START = 1,
EVENT_STAGE_SCAN_RECV = 2,
EVENT_STAGE_SCAN_END = 3,
} DiscEventScanStage;
typedef enum {
SERVER_PUBLISH = 1,
SERVER_STOP_PUBLISH = 2,

View File

@ -47,11 +47,12 @@ typedef enum {
EVENT_STAGE_AUTH_CONNECTION = 3,
EVENT_STAGE_AUTH_DEVICE_ID_POST = 4,
EVENT_STAGE_AUTH_DEVICE_ID_PROCESS = 5,
EVENT_STAGE_AUTH_HICHAIN = 6,
EVENT_STAGE_AUTH_EXCHANGE_CIPHER = 7,
EVENT_STAGE_AUTH_DEVICE_INFO_POST = 8,
EVENT_STAGE_AUTH_DEVICE_INFO_PROCESS = 9,
EVENT_STAGE_JOIN_LNN_END = 10,
EVENT_STAGE_AUTH_HICHAIN_START = 6,
EVENT_STAGE_AUTH_HICHAIN_END = 7,
EVENT_STAGE_AUTH_EXCHANGE_CIPHER = 8,
EVENT_STAGE_AUTH_DEVICE_INFO_POST = 9,
EVENT_STAGE_AUTH_DEVICE_INFO_PROCESS = 10,
EVENT_STAGE_JOIN_LNN_END = 11,
} LnnEventJoinLnnStage;
typedef enum {
@ -68,12 +69,13 @@ typedef enum {
typedef struct {
int32_t result; // STAGE_RES
int32_t errcode; // ERROR_CODE
int32_t authId; // AUTH_ID
int32_t discServerType; // DISC_SERVER_TYPE
int32_t gearCycle; // GEAR_CYCLE
int32_t gearDuration; // GEAR_DURATION
int32_t connectionId; // CONN_ID
int32_t authType; // AUTH_TYPE
int32_t authId; // AUTH_ID
int32_t authLinkType; // AUTH_LINK_TYPE
int32_t authCostTime; // AUTH_COST_TIME
int32_t lnnType; // LNN_TYPE
int32_t onlineNum; // ONLINE_NUM
int32_t peerDeviceAbility; // PEER_DEV_ABILITY

View File

@ -567,7 +567,6 @@ static void BleOnStateChanged(int32_t listenerId, int32_t state)
DiscEventExtra extra = { 0 };
DiscEventExtraInit(&extra);
extra.bleTurnState = state;
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_STATE_TURN, extra);
(void)listenerId;
SoftBusMessage *msg = NULL;
switch (state) {
@ -843,7 +842,7 @@ static void DfxRecordAdevertiserEnd(int32_t adv, int32_t reason)
extra.broadcastType = adv;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, extra);
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_BROADCAST, extra);
}
static int32_t StartAdvertiser(int32_t adv)
@ -965,7 +964,6 @@ static void DfxRecordScanEnd(int32_t reason)
extra.scanType = BLE + 1;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_START, extra);
}
static void StartScaner(void)
@ -1537,7 +1535,7 @@ static void DfxRecordAddRecvMsgEnd(const uint32_t *capBitMap, int32_t reason)
if (capBitMap != NULL) {
extra.capabilityBit = (int32_t)capBitMap[0];
}
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_RECV, extra);
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_SCAN_RECV, extra);
}
static int32_t AddRecvMessage(const char *key, const uint32_t *capBitMap, bool needBrMac)
@ -1639,7 +1637,6 @@ static void DfxRecordBleMsgHandlerStart(SoftBusMessage *msg)
if (msg != NULL) {
extra.interFuncType = msg->what + 1;
}
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_BLE_HANDLER, extra);
}
static void DiscBleMsgHandler(SoftBusMessage *msg)

View File

@ -150,7 +150,6 @@ static void DfxRecordRegisterEnd(const unsigned char *capabilityData, uint32_t c
extra.capabilityBit = (int32_t)capability;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
DISC_EVENT(EVENT_SCENE_COAP, EVENT_STAGE_REGISTER, extra);
}
static void DfxRecordSetFilterEnd(uint32_t capability, int32_t reason)
@ -176,7 +175,6 @@ static void DfxRecordStartDiscoveryEnd(DiscCoapOption *discCoapOption, int32_t r
extra.broadcastFreq = discCoapOption->freq;
extra.capabilityBit = (int32_t)discCoapOption->capability;
}
DISC_EVENT(EVENT_SCENE_COAP, EVENT_STAGE_DISCOVERY_START, extra);
}
static void DfxRecordStopDiscoveryEnd(int32_t reason)
@ -186,7 +184,6 @@ static void DfxRecordStopDiscoveryEnd(int32_t reason)
extra.discType = COAP + 1;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
DISC_EVENT(EVENT_SCENE_COAP, EVENT_STAGE_DISCOVERY_STOP, extra);
}
static int32_t Publish(const PublishOption *option, bool isActive)
@ -486,7 +483,6 @@ static void CoapUpdateLocalIp(LinkStatus status)
DiscEventExtraInit(&extra);
extra.discType = COAP + 1;
extra.ipLinkStatus = status + 1;
DISC_EVENT(EVENT_SCENE_COAP, EVENT_STAGE_UPDATE_IP, extra);
DiscCoapUpdateLocalIp(status);
}
@ -496,7 +492,6 @@ static void CoapUpdateLocalDeviceInfo(InfoTypeChanged type)
DiscEventExtraInit(&extra);
extra.discType = COAP + 1;
extra.coapChangeType = type + 1;
DISC_EVENT(EVENT_SCENE_COAP, EVENT_STAGE_UPDATE_DEVICE, extra);
if (type == TYPE_LOCAL_DEVICE_NAME) {
DiscCoapUpdateDevName();

View File

@ -95,12 +95,12 @@ typedef struct {
static void UpdateDiscEventAndReport(DiscEventExtra *extra, const DeviceInfo *device)
{
if (device == NULL) {
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_END, *extra);
DISC_EVENT(EVENT_SCENE_DISC, EVENT_STAGE_DEVICE_FOUND, *extra);
DISC_LOGI(DISC_CONTROL, "device info is null");
return;
}
if (device->addrNum <= CONNECTION_ADDR_WLAN || device->addrNum > CONNECTION_ADDR_MAX) {
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_END, *extra);
DISC_EVENT(EVENT_SCENE_DISC, EVENT_STAGE_DEVICE_FOUND, *extra);
DISC_LOGI(DISC_CONTROL, "unknown device info");
return;
}
@ -124,12 +124,11 @@ static void UpdateDiscEventAndReport(DiscEventExtra *extra, const DeviceInfo *de
}
}
extra->peerNetworkId = device->devId;
char deviceType[DEVICE_TYPE_SIZE_MAX + 1] = { 0 };
if (snprintf_s(deviceType, DEVICE_TYPE_SIZE_MAX + 1, DEVICE_TYPE_SIZE_MAX, "%03X", device->devType) >= 0) {
extra->peerDeviceType = deviceType;
}
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_END, *extra);
DISC_EVENT(EVENT_SCENE_DISC, EVENT_STAGE_DEVICE_FOUND, *extra);
}
static void DfxRecordStartDiscoveryDevice(DiscInfo *infoNode)

View File

@ -126,12 +126,13 @@ BUSCENTER_BEHAVIOR:
BIZ_STAGE: {type: INT32, desc: business stage }
STAGE_RES: {type: INT32, desc: stage result }
ERROR_CODE: { type: INT32, desc: error code }
AUTH_ID: { type: INT32, desc: auth id }
DISC_SERVER_TYPE: {type: INT32, desc: disc server type }
GEAR_CYCLE: {type: INT32, desc: gear cycle }
GEAR_DURATION: {type: INT32, desc: gear duration }
CONN_ID: { type: INT32, desc: connection id }
AUTH_TYPE: { type: INT32, desc: auth type }
AUTH_ID: { type: INT32, desc: auth id }
AUTH_LINK_TYPE: { type: INT32, desc: auth link type }
AUTH_COST_TIME: { type: INT32, desc: auth cost time }
LNN_TYPE: { type: INT32, desc: lnn type }
ONLINE_NUM: { type: INT32, desc: current online device num }
PEER_DEV_ABILITY: { type: INT32, desc: peer device ability }

View File

@ -139,10 +139,14 @@ static int32_t SubscribeInfoCheck(const SubscribeInfo *info)
static void DfxRecordSdkJoinLnnEnd(const char *packageName, int32_t reason)
{
if (reason == SOFTBUS_OK) {
return;
}
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
extra.result = EVENT_STAGE_RESULT_FAILED;
char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
if (packageName != NULL && IsValidString(packageName, PKG_NAME_SIZE_MAX - 1) && strncpy_s(pkgName,
@ -154,10 +158,14 @@ static void DfxRecordSdkJoinLnnEnd(const char *packageName, int32_t reason)
static void DfxRecordSdkLeaveLnnEnd(const char *packageName, int32_t reason)
{
if (reason == SOFTBUS_OK) {
return;
}
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
extra.result = EVENT_STAGE_RESULT_FAILED;
char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
if (packageName != NULL && IsValidString(packageName, PKG_NAME_SIZE_MAX - 1) && strncpy_s(pkgName,
@ -185,11 +193,15 @@ static void DfxRecordSdkShiftGearStart(const char *packageName, const GearMode *
static void DfxRecordLnnDiscServerEnd(int32_t serverType, const char *packageName, int32_t reason)
{
if (reason == SOFTBUS_OK) {
return;
}
LnnEventExtra extra = { 0 };
LnnEventExtraInit(&extra);
extra.discServerType = serverType;
extra.errcode = reason;
extra.result = (reason == SOFTBUS_OK) ? EVENT_STAGE_RESULT_OK : EVENT_STAGE_RESULT_FAILED;
extra.result = EVENT_STAGE_RESULT_FAILED;
char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
if (packageName != NULL && IsValidString(packageName, PKG_NAME_SIZE_MAX - 1) && strncpy_s(pkgName,

View File

@ -110,7 +110,6 @@ static void DfxRecordDiscServerEnd(int32_t serverType, int32_t reason, const cha
PKG_NAME_SIZE_MAX, packageName, PKG_NAME_SIZE_MAX - 1) == EOK) {
extra.callerPkg = pkgName;
}
DISC_EVENT(EVENT_SCENE_DISC, EVENT_STAGE_DISC_SDK, extra);
}
int PublishService(const char *packageName, const PublishInfo *info, const IPublishCallback *cb)

View File

@ -39,6 +39,10 @@ MATCHER_P2(LnnValidParamArrayMatcher, inExtra, validSize, "lnn valid param array
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
EXPECT_EQ(params[index].v.i32, extra.authId);
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
EXPECT_EQ(params[index].v.i32, extra.discServerType);
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
@ -55,11 +59,11 @@ MATCHER_P2(LnnValidParamArrayMatcher, inExtra, validSize, "lnn valid param array
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
EXPECT_EQ(params[index].v.i32, extra.authType);
EXPECT_EQ(params[index].v.i32, extra.authLinkType);
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
EXPECT_EQ(params[index].v.i32, extra.authId);
EXPECT_EQ(params[index].v.i32, extra.authCostTime);
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
@ -147,6 +151,10 @@ MATCHER_P2(LnnInvalidParamArrayMatcher, inExtra, validSize, "lnn invalid param a
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
EXPECT_EQ(params[index].v.i32, ((extra.errcode < 0) ? (-extra.errcode) : extra.errcode));
++index;
EXPECT_STREQ(params[index].name, g_lnnAssigners[index].name);
EXPECT_EQ(params[index].t, g_lnnAssigners[index].type);
EXPECT_EQ(params[index].v.i32, ((extra.authId < 0) ? (-extra.authId) : extra.authId));
EXPECT_EQ(++index, validSize);
return true;
}

View File

@ -47,7 +47,7 @@ HWTEST_F(DiscEventTest, DiscEventTest001, TestSize.Level0)
HiSysEvent_Write(_, _, StrEq(SOFTBUS_EVENT_DOMAIN), StrEq(DISC_EVENT_NAME), Eq(SOFTBUS_EVENT_TYPE_BEHAVIOR), _,
ParamArraySizeMatcher(VALID_EXTRA_SIZE)))
.Times(1);
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, extra);
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_BROADCAST, extra);
}
/**
@ -93,7 +93,7 @@ HWTEST_F(DiscEventTest, DiscEventTest002, TestSize.Level0)
HiSysEvent_Write(_, _, StrEq(SOFTBUS_EVENT_DOMAIN), StrEq(DISC_EVENT_NAME), Eq(SOFTBUS_EVENT_TYPE_BEHAVIOR),
DiscValidParamArrayMatcher(validExtra, VALID_EXTRA_SIZE), ParamArraySizeMatcher(VALID_EXTRA_SIZE)))
.Times(1);
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_START, validExtra);
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_SCAN, validExtra);
}
/**
@ -139,7 +139,7 @@ HWTEST_F(DiscEventTest, DiscEventTest003, TestSize.Level0)
HiSysEvent_Write(_, _, StrEq(SOFTBUS_EVENT_DOMAIN), StrEq(DISC_EVENT_NAME), Eq(SOFTBUS_EVENT_TYPE_BEHAVIOR),
DiscInvalidParamArrayMatcher(invalidExtra, VALID_EXTRA_SIZE), ParamArraySizeMatcher(VALID_EXTRA_SIZE)))
.Times(1);
DISC_EVENT(EVENT_SCENE_SCAN, EVENT_STAGE_SCAN_END, invalidExtra);
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_SCAN, invalidExtra);
}
/**
@ -158,6 +158,6 @@ HWTEST_F(DiscEventTest, DiscEventTest004, TestSize.Level0)
HiSysEvent_Write(_, _, StrEq(SOFTBUS_EVENT_DOMAIN), StrEq(DISC_EVENT_NAME), Eq(SOFTBUS_EVENT_TYPE_BEHAVIOR),
DiscInvalidParamArrayMatcher(emptyExtra, VALID_EXTRA_SIZE), ParamArraySizeMatcher(VALID_EXTRA_SIZE)))
.Times(1);
DISC_EVENT(EVENT_SCENE_BROADCAST, EVENT_STAGE_BROADCAST, emptyExtra);
DISC_EVENT(EVENT_SCENE_BLE, EVENT_STAGE_BROADCAST, emptyExtra);
}
} // namespace OHOS

View File

@ -37,10 +37,11 @@ HWTEST_F(LnnEventTest, LnnEventTest001, TestSize.Level0)
LnnEventExtra extra = {
.result = 1,
.errcode = 2233,
.authId = 112233,
.onlineNum = -1, // invalid
.peerPort = "9000",
};
constexpr int32_t VALID_EXTRA_SIZE = 3;
constexpr int32_t VALID_EXTRA_SIZE = 4;
HiSysEventMock mock;
EXPECT_CALL(mock,
@ -61,15 +62,16 @@ HWTEST_F(LnnEventTest, LnnEventTest002, TestSize.Level0)
LnnEventExtra validExtra = {
.result = 1,
.errcode = 2,
.discServerType = 3,
.gearCycle = 4,
.gearDuration = 5,
.connectionId = 6,
.authType = 7,
.authId = 8,
.lnnType = 9,
.onlineNum = 10,
.peerDeviceAbility = 11,
.authId = 3,
.discServerType = 4,
.gearCycle = 5,
.gearDuration = 6,
.connectionId = 7,
.authLinkType = 8,
.authCostTime = 9,
.lnnType = 10,
.onlineNum = 11,
.peerDeviceAbility = 12,
.peerDeviceInfo = "testPeerDeviceInfo",
.peerIp = "10.11.12.1",
.peerBrMac = "dd:15:bc:b9:f2:04",
@ -103,15 +105,16 @@ HWTEST_F(LnnEventTest, LnnEventTest003, TestSize.Level0)
LnnEventExtra invalidExtra = {
.result = -1, // vaild
.errcode = -2, // valid
.discServerType = -3,
.gearCycle = -4,
.gearDuration = -5,
.connectionId = -6,
.authType = -7,
.authId = -8,
.lnnType = -9,
.onlineNum = -10,
.peerDeviceAbility = -11,
.authId = -3, // vaild
.discServerType = -4,
.gearCycle = -5,
.gearDuration = -6,
.connectionId = -7,
.authLinkType = -8,
.authCostTime = -9,
.lnnType = -10,
.onlineNum = -11,
.peerDeviceAbility = -12,
.peerDeviceInfo = "",
.peerIp = "",
.peerBrMac = "",
@ -124,7 +127,7 @@ HWTEST_F(LnnEventTest, LnnEventTest003, TestSize.Level0)
.callerPkg = "\0",
.calleePkg = nullptr,
};
constexpr int32_t VALID_EXTRA_SIZE = 2; // result, errcode is valid
constexpr int32_t VALID_EXTRA_SIZE = 3; // result, errcode, authId is valid
HiSysEventMock mock;
EXPECT_CALL(mock,
@ -143,7 +146,7 @@ HWTEST_F(LnnEventTest, LnnEventTest003, TestSize.Level0)
HWTEST_F(LnnEventTest, LnnEventTest004, TestSize.Level0)
{
LnnEventExtra emptyExtra = { 0 };
constexpr int32_t VALID_EXTRA_SIZE = 2; // result, errcode is valid
constexpr int32_t VALID_EXTRA_SIZE = 3; // result, errcode, authId is valid
HiSysEventMock mock;
EXPECT_CALL(mock,