• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * 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 #include "legacy/softbus_hidumper_stats.h"
16 
17 #include <stdio.h>
18 #include <string.h>
19 
20 #include "comm_log.h"
21 #include "softbus_error_code.h"
22 #include "softbus_adapter_mem.h"
23 #include "softbus_def.h"
24 #include "legacy/softbus_hidumper.h"
25 #include "legacy/softbus_hidumper_util.h"
26 
27 #define SOFTBUS_FIFTEEN_MINUTES_STATS_ORDER "15min"
28 #define SOFTBUS_TWENTY_FOUR_HOURS_STATS_ORDER "24h"
29 
30 #define SOFTBUS_STATS_MODULE_NAME "stats"
31 #define SOFTBUS_STATS_MODULE_HELP "List all the dump item of stats"
32 
33 #define FIFTEEN_MINUTES 15
34 #define TWENTY_FOUR_HOURS (24 * 60)
35 
SoftBusStatsDumpHander(int fd,int32_t argc,const char ** argv)36 static int32_t SoftBusStatsDumpHander(int fd, int32_t argc, const char **argv)
37 {
38     if (fd < 0 || argc != 1 || argv == NULL) {
39         return SOFTBUS_INVALID_PARAM;
40     }
41 
42     SoftBusStatsResult *result = MallocSoftBusStatsResult(sizeof(SoftBusStatsResult));
43     if (result == NULL) {
44         SOFTBUS_DPRINTF(fd, "SoftBusStatsDumpHander result malloc fail!\n");
45         return SOFTBUS_MALLOC_ERR;
46     }
47     int32_t ret = SOFTBUS_OK;
48     if (strcmp(argv[0], SOFTBUS_FIFTEEN_MINUTES_STATS_ORDER) == SOFTBUS_OK) {
49         ret = SoftBusQueryStatsInfo(FIFTEEN_MINUTES, result);
50         if (ret != SOFTBUS_OK) {
51             SOFTBUS_DPRINTF(fd, "SoftBusStatsDumpHander query fail!\n");
52             FreeSoftBusStatsResult(result);
53             return ret;
54         }
55         SOFTBUS_DPRINTF(fd, "SoftBus 15min Statistics:\n");
56         SOFTBUS_DPRINTF(fd, "BT traffic = NA\n");
57         SOFTBUS_DPRINTF(fd, "Connection success rate = %f\n", result->successRate);
58         SOFTBUS_DPRINTF(fd, "Maximun concurrent number = %d\n", result->maxParaSessionNum);
59         SOFTBUS_DPRINTF(fd, "Service delay threshold = %dms\n", result->sessionSuccessDuration);
60         SOFTBUS_DPRINTF(fd, "Maximun online number = %d\n", result->deviceOnlineNum);
61         SOFTBUS_DPRINTF(fd, "Online/Offine times = %d/%d\n", result->deviceOnlineTimes, result->deviceOfflineTimes);
62         SOFTBUS_DPRINTF(fd, "Channel score exceeded times = %d\n", result->laneScoreOverTimes);
63     } else if (strcmp(argv[0], SOFTBUS_TWENTY_FOUR_HOURS_STATS_ORDER) == SOFTBUS_OK) {
64         ret = SoftBusQueryStatsInfo(TWENTY_FOUR_HOURS, result);
65         if (ret != SOFTBUS_OK) {
66             FreeSoftBusStatsResult(result);
67             SOFTBUS_DPRINTF(fd, "SoftBusStatsDumpHander query fail!\n");
68             return ret;
69         }
70         SOFTBUS_DPRINTF(fd, "SoftBus 24h Statistics:\n");
71         SOFTBUS_DPRINTF(fd, "BT traffic = NA\n");
72         SOFTBUS_DPRINTF(fd, "Connection success rate = %f\n", result->successRate);
73         SOFTBUS_DPRINTF(fd, "Act rate =  NA\n");
74         SOFTBUS_DPRINTF(fd, "Maximun online number = %d\n", result->deviceOnlineNum);
75         SOFTBUS_DPRINTF(fd, "Online times = %d\n", result->deviceOnlineTimes);
76         SOFTBUS_DPRINTF(fd, "Offine times = %d\n", result->deviceOfflineTimes);
77         SOFTBUS_DPRINTF(fd, "Keepalive detection times = NA\n");
78     } else {
79         SOFTBUS_DPRINTF(fd, "SoftBusStatsDumpHander invalid param!\n");
80         FreeSoftBusStatsResult(result);
81         return SOFTBUS_STRCMP_ERR;
82     }
83 
84     FreeSoftBusStatsResult(result);
85     return ret;
86 }
87 
SoftBusStatsHiDumperInit(void)88 int32_t SoftBusStatsHiDumperInit(void)
89 {
90     int32_t ret = SoftBusRegHiDumperHandler(SOFTBUS_STATS_MODULE_NAME, SOFTBUS_STATS_MODULE_HELP,
91         &SoftBusStatsDumpHander);
92     if (ret != SOFTBUS_OK) {
93         COMM_LOGE(COMM_DFX, "SoftBusRegStatsDumpCb registe fail");
94     }
95     return ret;
96 }