1 /*
2 * Copyright (c) 2023 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 * distributed under the License is distributed 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
16 #ifndef STATS_EVENT_CONVERTER_H
17 #define STATS_EVENT_CONVERTER_H
18
19 #include "softbus_event_converter.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define STATS_ASSIGNER(type, fieldName, field) \
26 static inline bool StatsAssigner##fieldName( \
27 const char *eventName, HiSysEventParamType paramType, SoftbusEventForm *form, HiSysEventParam *param) \
28 { \
29 if (Assigner##type(form->statsExtra->field, ¶m) && \
30 CopyString(param->name, eventName, MAX_LENGTH_OF_PARAM_NAME)) { \
31 param->t = paramType; \
32 return true; \
33 } \
34 return false; \
35 }
36
37 STATS_ASSIGNER(Errcode, Result, result)
38 STATS_ASSIGNER(Int32, BtFlow, btFlow)
39 STATS_ASSIGNER(Int32, SuccessRate, successRate)
40 STATS_ASSIGNER(Int32, MaxParaSessionNum, maxParaSessionNum)
41 STATS_ASSIGNER(Int32, SessionSuccessDuration, sessionSuccessDuration)
42 STATS_ASSIGNER(Int32, DeviceOnlineNum, deviceOnlineNum)
43 STATS_ASSIGNER(Int32, DeviceOnlineTimes, deviceOnlineTimes)
44 STATS_ASSIGNER(Int32, DeviceOfflineTimes, deviceOfflineTimes)
45 STATS_ASSIGNER(Int32, LaneScoreOverTimes, laneScoreOverTimes)
46 STATS_ASSIGNER(Int32, ActivationRate, activationRate)
47 STATS_ASSIGNER(Int32, DetectionTimes, detectionTimes)
48 STATS_ASSIGNER(LongString, SuccessRateDetail, successRateDetail)
49
50 #define STATS_ASSIGNER_SIZE 12 // Size of g_statsAssigners
51 static HiSysEventParamAssigner g_statsAssigners[] = {
52 { "STAGE_RES", HISYSEVENT_INT32, StatsAssignerResult },
53 { "BT_FLOW", HISYSEVENT_INT32, StatsAssignerBtFlow },
54 { "SUCCESS_RATE", HISYSEVENT_INT32, StatsAssignerSuccessRate },
55 { "MAX_PARA_SESSION_NUM", HISYSEVENT_INT32, StatsAssignerMaxParaSessionNum },
56 { "SESSION_SUCCESS_DURATION", HISYSEVENT_INT32, StatsAssignerSessionSuccessDuration },
57 { "DEVICE_ONLINE_NUM", HISYSEVENT_INT32, StatsAssignerDeviceOnlineNum },
58 { "DEVICE_ONLINE_TIMES", HISYSEVENT_INT32, StatsAssignerDeviceOnlineTimes },
59 { "DEVICE_OFFLINE_TIMES", HISYSEVENT_INT32, StatsAssignerDeviceOfflineTimes },
60 { "LANE_SCORE_OVER_TIMES", HISYSEVENT_INT32, StatsAssignerLaneScoreOverTimes },
61 { "ACTIVATION_RATE", HISYSEVENT_INT32, StatsAssignerActivationRate },
62 { "DETECTION_TIMES", HISYSEVENT_INT32, StatsAssignerDetectionTimes },
63 { "SUCCESS_RATE_DETAIL", HISYSEVENT_STRING, StatsAssignerSuccessRateDetail },
64
65 // Modification Note: remember updating STATS_ASSIGNER_SIZE
66 };
67
ConvertStatsForm2Param(HiSysEventParam params[],size_t size,SoftbusEventForm * form)68 static inline size_t ConvertStatsForm2Param(HiSysEventParam params[], size_t size, SoftbusEventForm *form)
69 {
70 size_t validSize = 0;
71 if (form == NULL || form->statsExtra == NULL) {
72 return validSize;
73 }
74 for (size_t i = 0; i < size; ++i) {
75 HiSysEventParamAssigner assigner = g_statsAssigners[i];
76 if (assigner.Assign(assigner.name, assigner.type, form, ¶ms[validSize])) {
77 ++validSize;
78 }
79 }
80 return validSize;
81 }
82
83 #ifdef __cplusplus
84 }
85 #endif /* __cplusplus */
86 #endif // STATS_EVENT_CONVERTER_H
87