1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * miscservices under the License is miscservices on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "securec.h"
16 #include "softbus_error_code.h"
17 #include "softbus_log.h"
18 #include "softbus_adapter_thread.h"
19 #include "softbus_adapter_timer.h"
20 #include "softbus_common.h"
21 #include "softbus_hisysevt_common.h"
22 #include "softbus_hisysevt_transreporter.h"
23 #include "softbus_utils.h"
24 #include "softbus_adapter_mem.h"
25 #include "softbus_server_ipc_interface_code.h"
26
27 #define STATISTIC_EVT_TRANSPORT_KPI "TRANSPORT_KPI"
28 #define STATISTIC_EVT_CALLED_API_INFO "CALLED_API_INFO"
29 #define STATISTIC_EVT_CALLED_API_CNT "CALLED_API_CNT"
30 #define STATISTIC_EVT_TRANS_OPEN_SESSION_CNT "TRANS_OPEN_SESSION_CNT"
31 #define STATISTIC_EVT_TRANS_OPEN_SESSION_TIME_COST "TRANS_OPEN_SESSION_TIME_COST"
32
33 #define FAULT_EVT_TRANS_FAULT "TRANS_FAULT"
34 #define BEHAVIOR_EVT_TRANS_INFO "TRANS_INFO"
35
36 #define TRANS_PARAM_LINK_TYPE "LINK_TYPE"
37
38 #define TRANS_PARAM_APP_NAME "APP_NAME"
39 #define TRANS_PARAM_API_NAME "API_NAME"
40
41 #define TRANS_PARAM_TOTAL_CNT "TOTAL_COUNT"
42 #define TRANS_PARAM_FAIL_TOTAL_CNT "FAIL_TOTAL_COUNT"
43 #define TRANS_PARAM_SUCCESS_CNT "SUCCESS_CNT"
44 #define TRANS_PARAM_FAIL_CNT "FAIL_CNT"
45 #define TRANS_PARAM_SUCCESS_RATE "SUCCESS_RATE"
46
47 #define TRANS_PARAM_TOTAL_TIME "TOTAL_TIME"
48 #define TRANS_PARAM_FAIL_TOTAL_TIME "FAIL_TOTAL_TIME"
49 #define TRANS_PARAM_MAX_TIME_COST "MAX_TIME_COST"
50 #define TRANS_PARAM_MIN_TIME_COST "MIN_TIME_COST"
51 #define TRANS_PARAM_AVE_TIME_COST "AVE_TIME_COST"
52 #define TRANS_PARAM_TIMES_UNDER_500MS "TIMES_UNDER_500MS"
53 #define TRANS_PARAM_TIMES_BETWEEN_500MS_1S "TIMES_BETWEEN_500MS_1S"
54 #define TRANS_PARAM_TIMES_BETWEEN_1S_2S "TIMES_BETWEEN_1S_2S"
55 #define TRANS_PARAM_TIMES_ABOVE_2S "TIMES_ABOVE_2S"
56 #define TRANS_OPEN_TIMES_ABOVE_1S "COUNT1"
57 #define TRANS_OPEN_TIMES_ABOVE_2S "COUNT2"
58 #define TRANS_OPEN_TIMES_ABOVE_4S "COUNT3"
59 #define TRANS_OPEN_TIMES_ABOVE_7S "COUNT4"
60 #define TRANS_OPEN_TIMES_ABOVE_11S "COUNT5"
61
62 #define TRANS_PARAM_PACKAGE_VERSION "PACKAGE_VERSION"
63 #define TRANS_PARAM_SOFTBUS_VERSION "SOFT_BUS_VERSION"
64 #define TRANS_PARAM_CALLER_PACKAGE "CALLER_PACKAGE_NAME"
65
66 #define TRANS_PARAM_ERRCODE "ERROR_CODE"
67 #define TRANS_PARAM_INFOMSG "INFO_MSG"
68
69 #define TIME_COST_500MS (500)
70 #define TIME_COST_1S (1000)
71 #define TIME_COST_2S (2000)
72 #define TIME_COST_4S (4000)
73 #define TIME_COST_7S (7000)
74 #define TIME_COST_11S (11000)
75 #define API_TYPE_DEFAULT (1)
76 #define API_CALLED_DEFAULT (1)
77
78 static char g_softbusVersion[SOFTBUS_HISYSEVT_PARAM_LEN] = "softbusVersion1";
79 static char g_pkgVersion[SOFTBUS_HISYSEVT_PARAM_LEN] = "packageVersion1";
80 typedef struct {
81 uint32_t code;
82 char *apiName;
83 }ApiNameIdMap;
84 static ApiNameIdMap g_apiNameIdMapTbl[] = {
85 {SERVER_START_DISCOVERY, "StartDiscovery"},
86 {SERVER_STOP_DISCOVERY, "StopDiscovery"},
87 {SERVER_PUBLISH_SERVICE, "PublishService"},
88 {SERVER_UNPUBLISH_SERVICE, "UnPublishService"},
89 {MANAGE_REGISTER_SERVICE, "SoftbusRegisterService"},
90 {SERVER_CREATE_SESSION_SERVER, "CreateSessionServer"},
91 {SERVER_REMOVE_SESSION_SERVER, "RemoveSessionServer"},
92 {SERVER_OPEN_SESSION, "OpenSession"},
93 {SERVER_OPEN_AUTH_SESSION, "OpenAuthSession"},
94 {SERVER_NOTIFY_AUTH_SUCCESS, "NotifyAuthSuccess"},
95 {SERVER_CLOSE_CHANNEL, "CloseChannel"},
96 {SERVER_SESSION_SENDMSG, "SendMessage"},
97 {SERVER_JOIN_LNN, "JoinLNN"},
98 {SERVER_JOIN_METANODE, "JoinMetaNode"},
99 {SERVER_LEAVE_LNN, "LeaveLNN"},
100 {SERVER_LEAVE_METANODE, "LeaveMetaNode"},
101 {SERVER_GET_ALL_ONLINE_NODE_INFO, "GetAllOnlineNodeInfo"},
102 {SERVER_GET_LOCAL_DEVICE_INFO, "GetLocalDeviceInfo"},
103 {SERVER_GET_NODE_KEY_INFO, "GetNodeKeyInfo"},
104 {SERVER_SET_NODE_DATA_CHANGE_FLAG, "SetNodeDataChangeFlag"},
105 {SERVER_START_TIME_SYNC, "StartTimeSync"},
106 {SERVER_STOP_TIME_SYNC, "StopTimeSync"},
107 {SERVER_QOS_REPORT, "QosReport"},
108 {SERVER_STREAM_STATS, "StreamStats"},
109 {SERVER_GRANT_PERMISSION, "GrantPermission"},
110 {SERVER_REMOVE_PERMISSION, "RemovePermission"},
111 {SERVER_PUBLISH_LNN, "PublishLNN"},
112 {SERVER_STOP_PUBLISH_LNN, "StopPublishLNN"},
113 {SERVER_REFRESH_LNN, "RefreshLNN"},
114 {SERVER_STOP_REFRESH_LNN, "StopRefreshLNN"},
115 {SERVER_ACTIVE_META_NODE, "ActiveMetaNode"},
116 {SERVER_DEACTIVE_META_NODE, "DeactiveMetaNode"},
117 {SERVER_GET_ALL_META_NODE_INFO, "GetAllMetaNodeInfo"},
118 {SERVER_SHIFT_LNN_GEAR, "ShiftLNNGear"},
119 {SERVER_RIPPLE_STATS, "RippleStats"},
120 };
121
122 typedef struct {
123 SoftBusMutex lock;
124 uint32_t failCnt;
125 uint32_t successCnt;
126 float successRate;
127 }OpenSessionCntStruct;
128
129 typedef struct {
130 SoftBusMutex lock;
131 uint32_t maxTimeCost;
132 uint32_t minTimeCost;
133 uint32_t aveTimeCost;
134 uint32_t timesIn500ms;
135 uint32_t timesIn500and1s;
136 uint32_t timesIn1and2s;
137 uint32_t timesOn2s;
138 }OpenSessionTimeStruct;
139
140 typedef struct {
141 SoftBusMutex lock;
142 int32_t linkType;
143 int64_t totalTime;
144 int32_t totalCnt;
145 int32_t successTotalCnt;
146 int64_t failTotalTime;
147 int32_t failTotalCnt;
148 char packageVersion[SOFTBUS_HISYSEVT_PARAM_LEN];
149 char softbusVersion[SOFTBUS_HISYSEVT_PARAM_LEN];
150 int32_t count1;
151 int32_t count2;
152 int32_t count3;
153 int32_t count4;
154 int32_t count5;
155 char callerPackageName[SOFTBUS_HISYSEVT_PARAM_LEN];
156 }OpenSessionKpiStruct;
157
158 typedef struct {
159 SoftBusMutex lock;
160 int32_t cnt; //app count
161 ListNode apiInfolist;
162 }ApiInfoList;
163
164 typedef struct {
165 ListNode node;
166 char appName[SOFTBUS_HISYSEVT_PARAM_LEN];
167 char softbusVersion[SOFTBUS_HISYSEVT_PARAM_LEN];
168 char packageVersion[SOFTBUS_HISYSEVT_PARAM_LEN];
169 int32_t cnt; //Api count
170 ListNode apiCntList;
171 }CalledApiInfoStruct;
172
173 typedef struct {
174 ListNode node;
175 char apiName[SOFTBUS_HISYSEVT_PARAM_LEN];
176 int32_t calledtotalCnt;
177 }CalledApiCntStruct;
178
179 static OpenSessionCntStruct g_openSessionCnt;
180 static OpenSessionTimeStruct g_openSessionTime;
181 static OpenSessionKpiStruct g_openSessionKpi;
182 static ApiInfoList *g_calledApiInfoList = NULL;
183 static ApiInfoList *g_calledApiCntlist = NULL;
184
185 #define TIME_THOUSANDS_FACTOR (1000)
186
GetSoftbusRecordTimeMillis(void)187 int64_t GetSoftbusRecordTimeMillis(void)
188 {
189 SoftBusSysTime t;
190 t.sec = 0;
191 t.usec = 0;
192 SoftBusGetTime(&t);
193 int64_t when = t.sec * TIME_THOUSANDS_FACTOR + (t.usec / TIME_THOUSANDS_FACTOR);
194 return when;
195 }
196
CreateApiInfoList(void)197 static ApiInfoList *CreateApiInfoList(void)
198 {
199 ApiInfoList *list = (ApiInfoList *)SoftBusMalloc(sizeof(ApiInfoList));
200 if (list == NULL) {
201 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "malloc failed");
202 return NULL;
203 }
204 (void)memset_s(list, sizeof(ApiInfoList), 0, sizeof(ApiInfoList));
205 SoftBusMutexAttr mutexAttr;
206 mutexAttr.type = SOFTBUS_MUTEX_RECURSIVE;
207 if (SoftBusMutexInit(&list->lock, &mutexAttr) != SOFTBUS_OK) {
208 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "init lock failed");
209 SoftBusFree(list);
210 return NULL;
211 }
212 ListInit(&list->apiInfolist);
213 return list;
214 }
215
DetroyApiInfoList(ApiInfoList * list)216 static void DetroyApiInfoList(ApiInfoList *list)
217 {
218 ListDelInit(&list->apiInfolist);
219 SoftBusMutexDestroy(&list->lock);
220 SoftBusFree(list);
221 return;
222 }
223
ReleaseCalledApiInfoList(void)224 static void ReleaseCalledApiInfoList(void)
225 {
226 if (g_calledApiInfoList == NULL) {
227 MLOGE("list NULL");
228 return;
229 }
230 if (SoftBusMutexLock(&g_calledApiInfoList->lock) != SOFTBUS_OK) {
231 MLOGE("ReleaseCalledApiInfoList lock failed");
232 return;
233 }
234 CalledApiInfoStruct *item = NULL;
235 CalledApiInfoStruct *nextItem = NULL;
236 LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_calledApiInfoList->apiInfolist, CalledApiInfoStruct, node) {
237 ListDelete(&item->node);
238 SoftBusFree(item);
239 g_calledApiInfoList->cnt--;
240 }
241 ListInit(&g_calledApiInfoList->apiInfolist);
242 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
243 return;
244 }
245
ReleaseCalledApiCntList(void)246 static void ReleaseCalledApiCntList(void)
247 {
248 if (g_calledApiCntlist == NULL) {
249 MLOGE("list NULL");
250 return;
251 }
252 if (SoftBusMutexLock(&g_calledApiCntlist->lock) != SOFTBUS_OK) {
253 MLOGE("ReleaseCalledApiCntList lock failed");
254 return;
255 }
256 CalledApiCntStruct *item = NULL;
257 CalledApiCntStruct *nextItem = NULL;
258 LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_calledApiCntlist->apiInfolist, CalledApiCntStruct, node) {
259 ListDelete(&item->node);
260 SoftBusFree(item);
261 g_calledApiCntlist->cnt--;
262 }
263 ListInit(&g_calledApiCntlist->apiInfolist);
264 (void)SoftBusMutexUnlock(&g_calledApiCntlist->lock);
265 return;
266 }
267
GetNewApiCnt(char * apiName)268 static CalledApiCntStruct *GetNewApiCnt(char *apiName)
269 {
270 CalledApiCntStruct *apiCnt = (CalledApiCntStruct *)SoftBusMalloc(sizeof(CalledApiCntStruct));
271 if (apiCnt == NULL) {
272 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "GetNewApiCnt malloc failed");
273 return NULL;
274 }
275 if (strcpy_s(apiCnt->apiName, SOFTBUS_HISYSEVT_PARAM_LEN, apiName) != EOK) {
276 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "GetNewApiCnt strcpy failed");
277 SoftBusFree(apiCnt);
278 return NULL;
279 }
280 ListInit(&apiCnt->node);
281 apiCnt->calledtotalCnt = API_CALLED_DEFAULT;
282 return apiCnt;
283 }
284
GetNewApiInfo(const char * appName,char * apiName)285 static CalledApiInfoStruct *GetNewApiInfo(const char *appName, char *apiName)
286 {
287 CalledApiInfoStruct *apiInfo = (CalledApiInfoStruct *)SoftBusMalloc(sizeof(CalledApiInfoStruct));
288 if (apiInfo == NULL) {
289 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "GetNewApiInfo malloc failed");
290 return NULL;
291 }
292 if (strcpy_s(apiInfo->appName, SOFTBUS_HISYSEVT_PARAM_LEN, appName) != EOK ||
293 strcpy_s(apiInfo->softbusVersion, SOFTBUS_HISYSEVT_PARAM_LEN, g_softbusVersion) != EOK ||
294 strcpy_s(apiInfo->packageVersion, SOFTBUS_HISYSEVT_PARAM_LEN, g_pkgVersion) != EOK) {
295 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_ERROR, "GetNewApiInfo strcpy failed");
296 SoftBusFree(apiInfo);
297 return NULL;
298 }
299 ListInit(&apiInfo->node);
300 ListInit(&apiInfo->apiCntList);
301 CalledApiCntStruct *apiCnt = GetNewApiCnt(apiName);
302 ListAdd(&apiInfo->apiCntList, &apiCnt->node);
303 apiInfo->cnt = API_TYPE_DEFAULT;
304 return apiInfo;
305 }
306
GetApiNameByCode(uint32_t code)307 static char *GetApiNameByCode(uint32_t code)
308 {
309 for (uint32_t i = 0; i < sizeof(g_apiNameIdMapTbl) / sizeof(ApiNameIdMap); i++) {
310 if (g_apiNameIdMapTbl[i].code == code) {
311 return g_apiNameIdMapTbl[i].apiName;
312 }
313 }
314 return NULL;
315 }
316
SoftbusRecordCalledApiInfo(const char * appName,uint32_t code)317 void SoftbusRecordCalledApiInfo(const char *appName, uint32_t code)
318 {
319 if (SoftBusMutexLock(&g_calledApiInfoList->lock) != SOFTBUS_OK) {
320 MLOGE("SoftbusRecordCalledApiInfo lock fail");
321 return;
322 }
323 char *apiName = GetApiNameByCode(code);
324 if (apiName == NULL) {
325 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
326 return;
327 }
328
329 CalledApiInfoStruct *apiInfoNode = NULL;
330 CalledApiCntStruct *apiCntNode = NULL;
331 bool isAppDiff = true;
332 bool isApiDiff = true;
333 LIST_FOR_EACH_ENTRY(apiInfoNode, &g_calledApiInfoList->apiInfolist, CalledApiInfoStruct, node) {
334 if (strcmp(apiInfoNode->appName, appName) == 0) {
335 isAppDiff = false;
336 LIST_FOR_EACH_ENTRY(apiCntNode, &apiInfoNode->apiCntList, CalledApiCntStruct, node) {
337 if (strcmp(apiCntNode->apiName, apiName) == 0) {
338 isApiDiff = false;
339 apiCntNode->calledtotalCnt++;
340 break;
341 }
342 }
343 }
344 }
345 if (isAppDiff) {
346 apiInfoNode = GetNewApiInfo(appName, apiName);
347 if (apiInfoNode == NULL) {
348 MLOGE("GetNewApiInfo fail");
349 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
350 return;
351 }
352 ListAdd(&g_calledApiInfoList->apiInfolist, &apiInfoNode->node);
353 g_calledApiInfoList->cnt++;
354 }
355 if ((isAppDiff == false) && (isApiDiff == true)) {
356 apiInfoNode = NULL;
357 LIST_FOR_EACH_ENTRY(apiInfoNode, &g_calledApiInfoList->apiInfolist, CalledApiInfoStruct, node) {
358 if (strcmp(apiInfoNode->appName, appName) == 0) {
359 apiCntNode = GetNewApiCnt(apiName);
360 if (apiCntNode == NULL) {
361 MLOGE("GetNewApiCnt fail");
362 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
363 return;
364 }
365 ListAdd(&apiInfoNode->apiCntList, &apiCntNode->node);
366 apiInfoNode->cnt++;
367 }
368 }
369 }
370 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
371 }
372
SoftbusRecordCalledApiCnt(uint32_t code)373 void SoftbusRecordCalledApiCnt(uint32_t code)
374 {
375 if (SoftBusMutexLock(&g_calledApiCntlist->lock) != SOFTBUS_OK) {
376 MLOGE("SoftbusRecordCalledApiCnt lock fail");
377 return;
378 }
379 char *apiName = GetApiNameByCode(code);
380 if (apiName == NULL) {
381 (void)SoftBusMutexUnlock(&g_calledApiCntlist->lock);
382 return;
383 }
384
385 CalledApiCntStruct *apiCntNode = NULL;
386 bool isDiff = true;
387 LIST_FOR_EACH_ENTRY(apiCntNode, &g_calledApiCntlist->apiInfolist, CalledApiCntStruct, node) {
388 if (strcmp(apiCntNode->apiName, apiName) == 0) {
389 isDiff = false;
390 apiCntNode->calledtotalCnt++;
391 break;
392 }
393 }
394 if (isDiff == true) {
395 apiCntNode = GetNewApiCnt(apiName);
396 if (apiCntNode == NULL) {
397 MLOGE("GetNewApiCnt fail");
398 (void)SoftBusMutexUnlock(&g_calledApiCntlist->lock);
399 return;
400 }
401 ListAdd(&g_calledApiCntlist->apiInfolist, &apiCntNode->node);
402 g_calledApiCntlist->cnt++;
403 }
404 (void)SoftBusMutexUnlock(&g_calledApiCntlist->lock);
405 }
406
SoftbusRecordOpenSessionKpi(const char * pkgName,int32_t linkType,SoftBusOpenSessionStatus isSucc,int64_t time)407 void SoftbusRecordOpenSessionKpi(const char *pkgName, int32_t linkType, SoftBusOpenSessionStatus isSucc, int64_t time)
408 {
409 if (SoftBusMutexLock(&g_openSessionKpi.lock) != SOFTBUS_OK) {
410 return;
411 }
412 g_openSessionKpi.linkType = linkType;
413
414 g_openSessionKpi.failTotalCnt += (isSucc != SOFTBUS_EVT_OPEN_SESSION_SUCC);
415 g_openSessionKpi.successTotalCnt += (isSucc == SOFTBUS_EVT_OPEN_SESSION_SUCC);
416 g_openSessionKpi.totalCnt = g_openSessionKpi.failTotalCnt + g_openSessionKpi.successTotalCnt;
417
418 (void)strcpy_s(g_openSessionKpi.softbusVersion, SOFTBUS_HISYSEVT_PARAM_LEN, g_softbusVersion);
419 (void)strcpy_s(g_openSessionKpi.packageVersion, SOFTBUS_HISYSEVT_PARAM_LEN, g_pkgVersion);
420 (void)strcpy_s(g_openSessionKpi.callerPackageName, SOFTBUS_HISYSEVT_PARAM_LEN, pkgName);
421 g_openSessionKpi.totalTime = time;
422 if (isSucc != SOFTBUS_EVT_OPEN_SESSION_SUCC) {
423 g_openSessionKpi.failTotalTime = time;
424 }
425
426 if (time > TIME_COST_1S) {
427 g_openSessionKpi.count1++;
428 } else if (time > TIME_COST_2S) {
429 g_openSessionKpi.count2++;
430 } else if (time > TIME_COST_4S) {
431 g_openSessionKpi.count3++;
432 } else if (time > TIME_COST_7S) {
433 g_openSessionKpi.count4++;
434 } else if (time > TIME_COST_11S) {
435 g_openSessionKpi.count5++;
436 }
437 (void)SoftBusMutexUnlock(&g_openSessionKpi.lock);
438 }
439
SoftbusRecordOpenSession(SoftBusOpenSessionStatus isSucc,uint32_t time)440 void SoftbusRecordOpenSession(SoftBusOpenSessionStatus isSucc, uint32_t time)
441 {
442 if (SoftBusMutexLock(&g_openSessionCnt.lock) != SOFTBUS_OK) {
443 return;
444 }
445
446 g_openSessionCnt.failCnt += (isSucc != SOFTBUS_EVT_OPEN_SESSION_SUCC);
447 g_openSessionCnt.successCnt += (isSucc == SOFTBUS_EVT_OPEN_SESSION_SUCC);
448 uint32_t totalCnt = g_openSessionCnt.failCnt + g_openSessionCnt.successCnt;
449 g_openSessionCnt.successRate = (float)(g_openSessionCnt.successCnt)/(float)(totalCnt);
450
451 (void)SoftBusMutexUnlock(&g_openSessionCnt.lock);
452
453 if (isSucc != SOFTBUS_EVT_OPEN_SESSION_SUCC) {
454 return;
455 }
456
457 if (SoftBusMutexLock(&g_openSessionTime.lock) != SOFTBUS_OK) {
458 return;
459 }
460
461 if (time > g_openSessionTime.maxTimeCost) {
462 g_openSessionTime.maxTimeCost = time;
463 } else if (time < g_openSessionTime.minTimeCost) {
464 g_openSessionTime.minTimeCost = time;
465 }
466
467 uint64_t totalTimeCost = (g_openSessionTime.aveTimeCost) * (g_openSessionCnt.successCnt - 1) + time;
468 g_openSessionTime.aveTimeCost = (uint32_t)(totalTimeCost / g_openSessionCnt.successCnt);
469
470 if (time < TIME_COST_500MS) {
471 g_openSessionTime.timesIn500ms++;
472 } else if (time < TIME_COST_1S) {
473 g_openSessionTime.timesIn500and1s++;
474 } else if (time < TIME_COST_2S) {
475 g_openSessionTime.timesIn1and2s++;
476 } else {
477 g_openSessionTime.timesOn2s++;
478 }
479
480 (void)SoftBusMutexUnlock(&g_openSessionTime.lock);
481 }
482
ClearOpenSessionKpi(void)483 static inline void ClearOpenSessionKpi(void)
484 {
485 memset_s(&g_openSessionKpi.linkType, sizeof(OpenSessionKpiStruct) - sizeof(SoftBusMutex),
486 0, sizeof(OpenSessionKpiStruct) - sizeof(SoftBusMutex));
487 }
488
ClearOpenSessionCnt(void)489 static inline void ClearOpenSessionCnt(void)
490 {
491 memset_s(&g_openSessionCnt.failCnt, sizeof(OpenSessionCntStruct) - sizeof(SoftBusMutex),
492 0, sizeof(OpenSessionCntStruct) - sizeof(SoftBusMutex));
493 }
494
ClearOpenSessionTime(void)495 static inline void ClearOpenSessionTime(void)
496 {
497 memset_s(&g_openSessionTime.maxTimeCost, sizeof(OpenSessionTimeStruct) - sizeof(SoftBusMutex),
498 0, sizeof(OpenSessionTimeStruct) - sizeof(SoftBusMutex));
499 }
500
InitOpenSessionEvtMutexLock(void)501 static inline int32_t InitOpenSessionEvtMutexLock(void)
502 {
503 SoftBusMutexAttr mutexAttr = {SOFTBUS_MUTEX_RECURSIVE};
504 if (SoftBusMutexInit(&g_openSessionCnt.lock, &mutexAttr) != SOFTBUS_OK) {
505 return SOFTBUS_ERR;
506 }
507
508 if (SoftBusMutexInit(&g_openSessionTime.lock, &mutexAttr) != SOFTBUS_OK) {
509 return SOFTBUS_ERR;
510 }
511
512 if (SoftBusMutexInit(&g_openSessionKpi.lock, &mutexAttr) != SOFTBUS_OK) {
513 return SOFTBUS_ERR;
514 }
515
516 return SOFTBUS_OK;
517 }
518
CreateCalledApiInfoMsg(SoftBusEvtReportMsg * msg,CalledApiCntStruct * apiCntItem,char * appName,char * softbusVersion,char * packageVersion)519 static void CreateCalledApiInfoMsg(SoftBusEvtReportMsg* msg, CalledApiCntStruct *apiCntItem,
520 char *appName, char *softbusVersion, char *packageVersion)
521 {
522 // event
523 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, STATISTIC_EVT_CALLED_API_INFO);
524 msg->evtType = SOFTBUS_EVT_TYPE_STATISTIC;
525 msg->paramNum = SOFTBUS_EVT_PARAM_FIVE;
526 // param 0
527 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
528 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_APP_NAME);
529 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
530 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, appName);
531 // param 1
532 param = &msg->paramArray[SOFTBUS_EVT_PARAM_ONE];
533 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_SOFTBUS_VERSION);
534 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
535 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, softbusVersion);
536 // param 2
537 param = &msg->paramArray[SOFTBUS_EVT_PARAM_TWO];
538 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_PACKAGE_VERSION);
539 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
540 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, packageVersion);
541 // param 3
542 param = &msg->paramArray[SOFTBUS_EVT_PARAM_THREE];
543 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_API_NAME);
544 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
545 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, apiCntItem->apiName);
546 // param 4
547 param = &msg->paramArray[SOFTBUS_EVT_PARAM_FOUR];
548 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TOTAL_CNT);
549 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
550 param->paramValue.i32v = apiCntItem->calledtotalCnt;
551 }
552
CreateCalledApiCntMsg(SoftBusEvtReportMsg * msg,CalledApiCntStruct * apiCntItem)553 static void CreateCalledApiCntMsg(SoftBusEvtReportMsg* msg, CalledApiCntStruct *apiCntItem)
554 {
555 // event
556 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, STATISTIC_EVT_CALLED_API_CNT);
557 msg->evtType = SOFTBUS_EVT_TYPE_STATISTIC;
558 msg->paramNum = SOFTBUS_EVT_PARAM_TWO;
559 // param 0
560 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
561 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_API_NAME);
562 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
563 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, apiCntItem->apiName);
564 // param 1
565 param = &msg->paramArray[SOFTBUS_EVT_PARAM_ONE];
566 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TOTAL_CNT);
567 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
568 param->paramValue.i32v = apiCntItem->calledtotalCnt;
569 }
570
CreateOpenSessionKpiMsg(SoftBusEvtReportMsg * msg)571 static void CreateOpenSessionKpiMsg(SoftBusEvtReportMsg* msg)
572 {
573 if (SoftBusMutexLock(&g_openSessionKpi.lock) != SOFTBUS_OK) {
574 return;
575 }
576 // event
577 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, STATISTIC_EVT_TRANSPORT_KPI);
578 msg->evtType = SOFTBUS_EVT_TYPE_STATISTIC;
579 msg->paramNum = SOFTBUS_EVT_PARAM_THIRTEEN;
580 // param 0
581 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
582 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_LINK_TYPE);
583 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
584 param->paramValue.i32v = g_openSessionKpi.linkType;
585 // param 1
586 param = &msg->paramArray[SOFTBUS_EVT_PARAM_ONE];
587 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TOTAL_TIME);
588 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT64;
589 param->paramValue.i64v = g_openSessionKpi.totalTime;
590 // param 2
591 param = &msg->paramArray[SOFTBUS_EVT_PARAM_TWO];
592 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TOTAL_CNT);
593 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
594 param->paramValue.i32v = g_openSessionKpi.totalCnt;
595 // param 3
596 param = &msg->paramArray[SOFTBUS_EVT_PARAM_THREE];
597 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_FAIL_TOTAL_TIME);
598 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT64;
599 param->paramValue.i64v = g_openSessionKpi.failTotalTime;
600 // param 4
601 param = &msg->paramArray[SOFTBUS_EVT_PARAM_FOUR];
602 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_FAIL_TOTAL_CNT);
603 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
604 param->paramValue.i32v = g_openSessionKpi.failTotalCnt;
605 // param 5
606 param = &msg->paramArray[SOFTBUS_EVT_PARAM_FIVE];
607 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_PACKAGE_VERSION);
608 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
609 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, g_openSessionKpi.packageVersion);
610 // param 6
611 param = &msg->paramArray[SOFTBUS_EVT_PARAM_SIX];
612 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_SOFTBUS_VERSION);
613 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
614 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, g_openSessionKpi.softbusVersion);
615 // param 7
616 param = &msg->paramArray[SOFTBUS_EVT_PARAM_SEVEN];
617 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_OPEN_TIMES_ABOVE_1S);
618 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
619 param->paramValue.i32v = g_openSessionKpi.count1;
620 // param 8
621 param = &msg->paramArray[SOFTBUS_EVT_PARAM_EIGHT];
622 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_OPEN_TIMES_ABOVE_2S);
623 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
624 param->paramValue.i32v = g_openSessionKpi.count2;
625 // param 9
626 param = &msg->paramArray[SOFTBUS_EVT_PARAM_NINE];
627 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_OPEN_TIMES_ABOVE_4S);
628 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
629 param->paramValue.i32v = g_openSessionKpi.count3;
630 // param 10
631 param = &msg->paramArray[SOFTBUS_EVT_PARAM_TEN];
632 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_OPEN_TIMES_ABOVE_7S);
633 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
634 param->paramValue.i32v = g_openSessionKpi.count4;
635 // param 11
636 param = &msg->paramArray[SOFTBUS_EVT_PARAM_ELEVEN];
637 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_OPEN_TIMES_ABOVE_11S);
638 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
639 param->paramValue.i32v = g_openSessionKpi.count5;
640 // param 12
641 param = &msg->paramArray[SOFTBUS_EVT_PARAM_TWELVE];
642 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_CALLER_PACKAGE);
643 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
644 (void)strcpy_s(param->paramValue.str, SOFTBUS_HISYSEVT_PARAM_LEN, g_openSessionKpi.callerPackageName);
645 ClearOpenSessionKpi();
646 (void)SoftBusMutexUnlock(&g_openSessionKpi.lock);
647 }
648
CreateOpenSessionCntMsg(SoftBusEvtReportMsg * msg)649 static void CreateOpenSessionCntMsg(SoftBusEvtReportMsg* msg)
650 {
651 if (SoftBusMutexLock(&g_openSessionCnt.lock) != SOFTBUS_OK) {
652 return;
653 }
654
655 // event
656 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, STATISTIC_EVT_TRANS_OPEN_SESSION_CNT);
657 msg->evtType = SOFTBUS_EVT_TYPE_STATISTIC;
658 msg->paramNum = SOFTBUS_EVT_PARAM_THREE;
659
660 // param 0
661 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
662 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_SUCCESS_CNT);
663 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
664 param->paramValue.u32v = g_openSessionCnt.successCnt;
665
666 // param 1
667 param = &msg->paramArray[SOFTBUS_EVT_PARAM_ONE];
668 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_FAIL_CNT);
669 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
670 param->paramValue.u32v = (g_openSessionCnt.failCnt);
671
672 // param 2
673 param = &msg->paramArray[SOFTBUS_EVT_PARAM_TWO];
674 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_SUCCESS_RATE);
675 param->paramType = SOFTBUS_EVT_PARAMTYPE_FLOAT;
676 param->paramValue.f = g_openSessionCnt.successRate;
677
678 ClearOpenSessionCnt();
679
680 (void)SoftBusMutexUnlock(&g_openSessionCnt.lock);
681 }
682
SoftbusReportCalledAPIEvt(void)683 static int32_t SoftbusReportCalledAPIEvt(void)
684 {
685 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_FIVE);
686 if (msg == NULL) {
687 return SOFTBUS_ERR;
688 }
689 if (SoftBusMutexLock(&g_calledApiInfoList->lock) != SOFTBUS_OK) {
690 return SOFTBUS_LOCK_ERR;
691 }
692 char appName[SOFTBUS_HISYSEVT_PARAM_LEN];
693 char softbusVersion[SOFTBUS_HISYSEVT_PARAM_LEN];
694 char packageVersion[SOFTBUS_HISYSEVT_PARAM_LEN];
695 CalledApiInfoStruct *apiInfoItem = NULL;
696 CalledApiCntStruct *apiCntItem = NULL;
697 LIST_FOR_EACH_ENTRY(apiInfoItem, &g_calledApiInfoList->apiInfolist, CalledApiInfoStruct, node) {
698 (void)strcpy_s(appName, SOFTBUS_HISYSEVT_NAME_LEN, apiInfoItem->appName);
699 (void)strcpy_s(softbusVersion, SOFTBUS_HISYSEVT_NAME_LEN, apiInfoItem->softbusVersion);
700 (void)strcpy_s(packageVersion, SOFTBUS_HISYSEVT_NAME_LEN, apiInfoItem->packageVersion);
701 LIST_FOR_EACH_ENTRY(apiCntItem, &apiInfoItem->apiCntList, CalledApiCntStruct, node) {
702 CreateCalledApiInfoMsg(msg, apiCntItem, appName, softbusVersion, packageVersion);
703 if (SoftbusWriteHisEvt(msg) != SOFTBUS_OK) {
704 SoftbusFreeEvtReporMsg(msg);
705 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
706 ReleaseCalledApiInfoList();
707 return SOFTBUS_ERR;
708 }
709 }
710 }
711 SoftbusFreeEvtReporMsg(msg);
712 (void)SoftBusMutexUnlock(&g_calledApiInfoList->lock);
713 ReleaseCalledApiInfoList();
714 return SOFTBUS_OK;
715 }
716
SoftbusReportCalledAPICntEvt(void)717 static int32_t SoftbusReportCalledAPICntEvt(void)
718 {
719 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_TWO);
720 if (msg == NULL) {
721 return SOFTBUS_ERR;
722 }
723 if (SoftBusMutexLock(&g_calledApiCntlist->lock) != SOFTBUS_OK) {
724 return SOFTBUS_LOCK_ERR;
725 }
726 CalledApiCntStruct *apiCntItem = NULL;
727 LIST_FOR_EACH_ENTRY(apiCntItem, &g_calledApiCntlist->apiInfolist, CalledApiCntStruct, node) {
728 CreateCalledApiCntMsg(msg, apiCntItem);
729 if (SoftbusWriteHisEvt(msg) != SOFTBUS_OK) {
730 SoftbusFreeEvtReporMsg(msg);
731 (void)SoftBusMutexUnlock(&g_calledApiCntlist->lock);
732 ReleaseCalledApiCntList();
733 return SOFTBUS_ERR;
734 }
735 }
736 SoftbusFreeEvtReporMsg(msg);
737 (void)SoftBusMutexUnlock(&g_calledApiCntlist->lock);
738 ReleaseCalledApiCntList();
739 return SOFTBUS_OK;
740 }
741
SoftbusReportOpenSessionKpiEvt(void)742 static int32_t SoftbusReportOpenSessionKpiEvt(void)
743 {
744 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_THIRTEEN);
745 if (msg == NULL) {
746 return SOFTBUS_ERR;
747 }
748 CreateOpenSessionKpiMsg(msg);
749 int ret = SoftbusWriteHisEvt(msg);
750 SoftbusFreeEvtReporMsg(msg);
751 return ret;
752 }
753
SoftbusReportOpenSessionCntEvt(void)754 static int32_t SoftbusReportOpenSessionCntEvt(void)
755 {
756 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_THREE);
757 if (msg == NULL) {
758 return SOFTBUS_ERR;
759 }
760 CreateOpenSessionCntMsg(msg);
761 int ret = SoftbusWriteHisEvt(msg);
762 SoftbusFreeEvtReporMsg(msg);
763
764 return ret;
765 }
766
CreateOpenSessionTimeMsg(SoftBusEvtReportMsg * msg)767 static void CreateOpenSessionTimeMsg(SoftBusEvtReportMsg* msg)
768 {
769 if (SoftBusMutexLock(&g_openSessionTime.lock) != SOFTBUS_OK) {
770 return;
771 }
772
773 // event
774 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, STATISTIC_EVT_TRANS_OPEN_SESSION_TIME_COST);
775 msg->evtType = SOFTBUS_EVT_TYPE_STATISTIC;
776 msg->paramNum = SOFTBUS_EVT_PARAM_SEVEN;
777
778 // param 0
779 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
780 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_MAX_TIME_COST);
781 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
782 param->paramValue.u32v = g_openSessionTime.maxTimeCost;
783
784 // param 1
785 param = &msg->paramArray[SOFTBUS_EVT_PARAM_ONE];
786 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_MIN_TIME_COST);
787 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
788 param->paramValue.u32v = g_openSessionTime.minTimeCost;
789
790 // param 2
791 param = &msg->paramArray[SOFTBUS_EVT_PARAM_TWO];
792 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_AVE_TIME_COST);
793 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
794 param->paramValue.u32v = g_openSessionTime.aveTimeCost;
795
796 // param 3
797 param = &msg->paramArray[SOFTBUS_EVT_PARAM_THREE];
798 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TIMES_UNDER_500MS);
799 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
800 param->paramValue.u32v = g_openSessionTime.timesIn500ms;
801
802 // param 4
803 param = &msg->paramArray[SOFTBUS_EVT_PARAM_FOUR];
804 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TIMES_BETWEEN_500MS_1S);
805 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
806 param->paramValue.u32v = g_openSessionTime.timesIn500and1s;
807
808 // param 5
809 param = &msg->paramArray[SOFTBUS_EVT_PARAM_FIVE];
810 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TIMES_BETWEEN_1S_2S);
811 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
812 param->paramValue.u32v = g_openSessionTime.timesIn1and2s;
813
814 // param 6
815 param = &msg->paramArray[SOFTBUS_EVT_PARAM_SIX];
816 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_TIMES_ABOVE_2S);
817 param->paramType = SOFTBUS_EVT_PARAMTYPE_UINT32;
818 param->paramValue.u32v = g_openSessionTime.timesOn2s;
819
820 ClearOpenSessionTime();
821
822 (void)SoftBusMutexUnlock(&g_openSessionTime.lock);
823 }
824
SoftbusReportOpenSessionTimeEvt(void)825 static int32_t SoftbusReportOpenSessionTimeEvt(void)
826 {
827 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_SEVEN);
828 if (msg == NULL) {
829 return SOFTBUS_ERR;
830 }
831 CreateOpenSessionTimeMsg(msg);
832 int ret = SoftbusWriteHisEvt(msg);
833 SoftbusFreeEvtReporMsg(msg);
834
835 return ret;
836 }
837
CreateTransErrMsg(SoftBusEvtReportMsg * msg,int32_t errcode)838 static inline void CreateTransErrMsg(SoftBusEvtReportMsg* msg, int32_t errcode)
839 {
840 // event
841 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, FAULT_EVT_TRANS_FAULT);
842 msg->evtType = SOFTBUS_EVT_TYPE_FAULT;
843 msg->paramNum = SOFTBUS_EVT_PARAM_ONE;
844
845 // param 0
846 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
847 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_ERRCODE);
848 param->paramType = SOFTBUS_EVT_PARAMTYPE_INT32;
849 param->paramValue.i32v = errcode;
850 }
851
CreateTransInfoMsg(SoftBusEvtReportMsg * msg,const char * infoMsg)852 static inline void CreateTransInfoMsg(SoftBusEvtReportMsg* msg, const char *infoMsg)
853 {
854 // event
855 (void)strcpy_s(msg->evtName, SOFTBUS_HISYSEVT_NAME_LEN, BEHAVIOR_EVT_TRANS_INFO);
856 msg->evtType = SOFTBUS_EVT_TYPE_BEHAVIOR;
857 msg->paramNum = SOFTBUS_EVT_PARAM_ONE;
858
859 // param 0
860 SoftBusEvtParam* param = &msg->paramArray[SOFTBUS_EVT_PARAM_ZERO];
861 (void)strcpy_s(param->paramName, SOFTBUS_HISYSEVT_NAME_LEN, TRANS_PARAM_INFOMSG);
862 param->paramType = SOFTBUS_EVT_PARAMTYPE_STRING;
863 (void)strcpy_s(param->paramValue.str, sizeof(param->paramValue.str), infoMsg);
864 }
865
SoftbusReportTransErrorEvt(int32_t errcode)866 void SoftbusReportTransErrorEvt(int32_t errcode)
867 {
868 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_ONE);
869 if (msg == NULL) {
870 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "Alloc EvtReport Msg Fail!");
871 return;
872 }
873 CreateTransErrMsg(msg, errcode);
874 int ret = SoftbusWriteHisEvt(msg);
875 SoftbusFreeEvtReporMsg(msg);
876
877 if (ret != SOFTBUS_OK) {
878 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "Sys Evt Witre ErrCode %d FAIL!", errcode);
879 }
880 }
881
SoftbusReportTransInfoEvt(const char * infoMsg)882 void SoftbusReportTransInfoEvt(const char *infoMsg)
883 {
884 if (infoMsg == NULL) {
885 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "infoMsg is null");
886 return;
887 }
888 SoftBusEvtReportMsg* msg = SoftbusCreateEvtReportMsg(SOFTBUS_EVT_PARAM_ONE);
889 if (msg == NULL) {
890 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "Alloc EvtReport Msg Fail!");
891 return;
892 }
893 CreateTransInfoMsg(msg, infoMsg);
894 int ret = SoftbusWriteHisEvt(msg);
895 SoftbusFreeEvtReporMsg(msg);
896
897 if (ret != SOFTBUS_OK) {
898 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "Sys Evt Witre ErrMsg %s FAIL!", infoMsg);
899 }
900 }
901
InitTransStatisticSysEvt(void)902 int32_t InitTransStatisticSysEvt(void)
903 {
904 if (InitOpenSessionEvtMutexLock() != SOFTBUS_OK) {
905 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "Trans Statistic Evt Lock Init Fail!");
906 return SOFTBUS_ERR;
907 }
908
909 g_calledApiInfoList = CreateApiInfoList();
910 g_calledApiCntlist = CreateApiInfoList();
911 ClearOpenSessionCnt();
912 ClearOpenSessionKpi();
913 ClearOpenSessionTime();
914
915 SetStatisticEvtReportFunc(SOFTBUS_STATISTIC_EVT_TRANS_OPEN_SESSION_CNT, SoftbusReportOpenSessionCntEvt);
916 SetStatisticEvtReportFunc(SOFTBUS_STATISTIC_EVT_TRANS_OPEN_SESSION_KPI, SoftbusReportOpenSessionKpiEvt);
917 SetStatisticEvtReportFunc(TRANSPORT_API_CALLED_INFO_STATISTIC_EVENT, SoftbusReportCalledAPIEvt);
918 SetStatisticEvtReportFunc(TRANSPORT_API_CALLED_CNT_STATISTIC_EVENT, SoftbusReportCalledAPICntEvt);
919 SetStatisticEvtReportFunc(SOFTBUS_STATISTIC_EVT_TRANS_OPEN_SESSION_TIME_COST, SoftbusReportOpenSessionTimeEvt);
920 return SOFTBUS_OK;
921 }
922
DeinitTransStatisticSysEvt(void)923 void DeinitTransStatisticSysEvt(void)
924 {
925 DetroyApiInfoList(g_calledApiInfoList);
926 DetroyApiInfoList(g_calledApiCntlist);
927 }