mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-23 16:59:54 +00:00
feat: resource statistic
Signed-off-by: yezizhuo <yezizhuo@huawei.com>
This commit is contained in:
parent
74c0cb8f91
commit
b9806ece4b
61
core/common/dfx/statistics/include/bt_statistic.h
Normal file
61
core/common/dfx/statistics/include/bt_statistic.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BT_STATISTIC_H
|
||||
#define BT_STATISTIC_H
|
||||
|
||||
#include "stdint.h"
|
||||
#include "cJSON.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace Communication {
|
||||
namespace Softbus {
|
||||
class BtStatistic {
|
||||
public:
|
||||
BtStatistic();
|
||||
~BtStatistic() = default;
|
||||
|
||||
static BtStatistic& GetInstance();
|
||||
int32_t GetBtStatisticInfo(cJSON *json);
|
||||
|
||||
private:
|
||||
void GetGattClientDeviceInfo(cJSON *json);
|
||||
void GetGattServerDeviceInfo(cJSON *json);
|
||||
void GetBleAdvertiserDeviceInfo(cJSON *json);
|
||||
void GetBleCentralDeviceInfo(cJSON *json);
|
||||
void GetBleGattDeviceInfo(cJSON *json);
|
||||
void GetA2dpSrcDeviceInfo(cJSON *json);
|
||||
void GetA2dpSinkDeviceInfo(cJSON *json);
|
||||
void GetAvrCTDeviceInfo(cJSON *json);
|
||||
void GetAvrTGDeviceInfo(cJSON *json);
|
||||
void GetHfpAGDeviceInfo(cJSON *json);
|
||||
void GetHfpHFDeviceInfo(cJSON *json);
|
||||
void GetMapMseDeviceInfo(cJSON *json);
|
||||
void GetPbapPseDeviceInfo(cJSON *json);
|
||||
void GetHidHostDeviceInfo(cJSON *json);
|
||||
void GetOppDeviceInfo(cJSON *json);
|
||||
void GetPanDeviceInfo(cJSON *json);
|
||||
|
||||
void GetGattDeviceInfo(cJSON *json, uint32_t gattId);
|
||||
|
||||
typedef void (BtStatistic::*GetProfileDeviceInfo)(cJSON *);
|
||||
std::map<uint32_t, GetProfileDeviceInfo> getProfileDeviceInfoMap_;
|
||||
std::vector<int32_t> connectState_;
|
||||
};
|
||||
} // namespace SoftBus
|
||||
} // namespace Communication
|
||||
|
||||
#endif // BT_STATISTIC_H
|
40
core/common/dfx/statistics/include/wifi_statistic.h
Normal file
40
core/common/dfx/statistics/include/wifi_statistic.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WIFI_STATISTIC_H
|
||||
#define WIFI_STATISTIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
namespace Communication {
|
||||
namespace Softbus {
|
||||
class WifiStatistic {
|
||||
public:
|
||||
WifiStatistic() = default;
|
||||
~WifiStatistic() = default;
|
||||
|
||||
static WifiStatistic& GetInstance();
|
||||
int32_t GetWifiStatisticInfo(cJSON *json);
|
||||
|
||||
private:
|
||||
int32_t GetStaInfo(cJSON *json);
|
||||
int32_t GetSoftApInfo(cJSON *json);
|
||||
int32_t GetP2PInfo(cJSON *json);
|
||||
};
|
||||
} // namespace SoftBus
|
||||
} // namespace Communication
|
||||
|
||||
#endif // WIFI_STATISTIC_H
|
241
core/common/dfx/statistics/instant/bt_statistic.cpp
Normal file
241
core/common/dfx/statistics/instant/bt_statistic.cpp
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "bt_statistic.h"
|
||||
|
||||
#include "bluetooth_a2dp_snk.h"
|
||||
#include "bluetooth_a2dp_src.h"
|
||||
#include "bluetooth_avrcp_ct.h"
|
||||
#include "bluetooth_avrcp_tg.h"
|
||||
#include "bluetooth_hfp_ag.h"
|
||||
#include "bluetooth_hfp_hf.h"
|
||||
#include "bluetooth_hid_host.h"
|
||||
#include "bluetooth_host.h"
|
||||
#include "bluetooth_map_mse.h"
|
||||
#include "bluetooth_opp.h"
|
||||
#include "bluetooth_pan.h"
|
||||
#include "bluetooth_pbap_pse.h"
|
||||
#include "bluetooth_gatt_manager.h"
|
||||
#include "comm_log.h"
|
||||
#include "softbus_error_code.h"
|
||||
#include "softbus_json_utils.h"
|
||||
#include "utils/wifi_direct_anonymous.h"
|
||||
|
||||
using namespace OHOS::Bluetooth;
|
||||
|
||||
namespace Communication {
|
||||
namespace Softbus {
|
||||
|
||||
BtStatistic::BtStatistic()
|
||||
{
|
||||
connectState_ = { static_cast<int32_t>(BTConnectState::CONNECTED) };
|
||||
getProfileDeviceInfoMap_ = {
|
||||
{PROFILE_ID_GATT_CLIENT, &BtStatistic::GetGattClientDeviceInfo},
|
||||
{PROFILE_ID_GATT_SERVER, &BtStatistic::GetGattServerDeviceInfo},
|
||||
{PROFILE_ID_A2DP_SRC, &BtStatistic::GetA2dpSrcDeviceInfo},
|
||||
{PROFILE_ID_A2DP_SINK, &BtStatistic::GetA2dpSinkDeviceInfo},
|
||||
{PROFILE_ID_AVRCP_CT, &BtStatistic::GetAvrCTDeviceInfo},
|
||||
{PROFILE_ID_AVRCP_TG, &BtStatistic::GetAvrTGDeviceInfo},
|
||||
{PROFILE_ID_HFP_AG, &BtStatistic::GetHfpAGDeviceInfo},
|
||||
{PROFILE_ID_HFP_HF, &BtStatistic::GetHfpHFDeviceInfo},
|
||||
{PROFILE_ID_MAP_MCE, nullptr},
|
||||
{PROFILE_ID_MAP_MSE, &BtStatistic::GetMapMseDeviceInfo},
|
||||
{PROFILE_ID_PBAP_PCE, nullptr},
|
||||
{PROFILE_ID_PBAP_PSE, &BtStatistic::GetPbapPseDeviceInfo},
|
||||
{PROFILE_ID_SPP, nullptr},
|
||||
{PROFILE_ID_DI, nullptr},
|
||||
{PROFILE_ID_BLE_ADVERTISER, &BtStatistic::GetBleAdvertiserDeviceInfo},
|
||||
{PROFILE_ID_BLE_CENTRAL_MANAGER_SERVER, &BtStatistic::GetBleCentralDeviceInfo},
|
||||
{PROFILE_ID_BLE_GATT_MANAGER, &BtStatistic::GetBleGattDeviceInfo},
|
||||
{PROFILE_ID_HID_HOST, &BtStatistic::GetHidHostDeviceInfo},
|
||||
{PROFILE_ID_OPP, &BtStatistic::GetOppDeviceInfo},
|
||||
{PROFILE_ID_PAN, &BtStatistic::GetPanDeviceInfo},
|
||||
{PROFILE_ID_HOST, nullptr},
|
||||
};
|
||||
}
|
||||
|
||||
BtStatistic& BtStatistic::GetInstance()
|
||||
{
|
||||
static BtStatistic instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
int32_t BtStatistic::GetBtStatisticInfo(cJSON *json)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
cJSON *btDeviceArray = cJSON_CreateArray();
|
||||
std::vector<uint32_t> profileList = BluetoothHost::GetDefaultHost().GetProfileList();
|
||||
for (size_t i = 0; i < profileList.size(); i++) {
|
||||
if (getProfileDeviceInfoMap_.find(profileList[i]) == getProfileDeviceInfoMap_.end()) {
|
||||
continue;
|
||||
}
|
||||
GetProfileDeviceInfo func = getProfileDeviceInfoMap_[profileList[i]];
|
||||
if (func != nullptr) {
|
||||
(this->*func)(btDeviceArray);
|
||||
}
|
||||
}
|
||||
(void)cJSON_AddItemToObject(json, "BtDeviceList", btDeviceArray);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void AddDevicesToArray(
|
||||
cJSON *json, const std::vector<OHOS::Bluetooth::BluetoothRemoteDevice>& devices, uint32_t profileId)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < devices.size(); i++) {
|
||||
cJSON *deviceJson = cJSON_CreateObject();
|
||||
(void)AddStringToJsonObject(deviceJson, "Name", devices[i].GetDeviceName().c_str());
|
||||
(void)AddStringToJsonObject(deviceJson, "Mac",
|
||||
OHOS::SoftBus::WifiDirectAnonymizeMac(devices[i].GetDeviceAddr()).c_str());
|
||||
(void)AddNumberToJsonObject(deviceJson, "Profile", static_cast<int32_t>(profileId));
|
||||
if (profileId == PROFILE_ID_A2DP_SRC) {
|
||||
(void)AddStringToJsonObject(deviceJson, "IsPlaying",
|
||||
std::to_string(A2dpSource::GetProfile()->GetPlayingState(devices[i])).c_str());
|
||||
} else if (profileId == PROFILE_ID_A2DP_SINK) {
|
||||
(void)AddStringToJsonObject(deviceJson, "IsPlaying",
|
||||
std::to_string(A2dpSink::GetProfile()->GetPlayingState(devices[i])).c_str());
|
||||
} else if (profileId == PROFILE_ID_HFP_HF) {
|
||||
(void)AddStringToJsonObject(deviceJson, "ScoState",
|
||||
std::to_string(HandsFreeUnit::GetProfile()->GetScoState(devices[i])).c_str());
|
||||
} else if (profileId == PROFILE_ID_HFP_AG) {
|
||||
(void)AddStringToJsonObject(deviceJson, "ScoState",
|
||||
std::to_string(HandsFreeAudioGateway::GetProfile()->GetScoState(devices[i])).c_str());
|
||||
}
|
||||
(void)cJSON_AddItemToArray(json, deviceJson);
|
||||
}
|
||||
}
|
||||
|
||||
void BtStatistic::GetGattDeviceInfo(cJSON *json, uint32_t gattId)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return;
|
||||
}
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
GattManager gattManager;
|
||||
devices = gattManager.GetConnectedDevices();
|
||||
AddDevicesToArray(json, devices, gattId);
|
||||
}
|
||||
|
||||
void BtStatistic::GetGattClientDeviceInfo(cJSON *json)
|
||||
{
|
||||
GetGattDeviceInfo(json, PROFILE_ID_GATT_CLIENT);
|
||||
}
|
||||
|
||||
void BtStatistic::GetGattServerDeviceInfo(cJSON *json)
|
||||
{
|
||||
GetGattDeviceInfo(json, PROFILE_ID_GATT_SERVER);
|
||||
}
|
||||
|
||||
void BtStatistic::GetBleAdvertiserDeviceInfo(cJSON *json)
|
||||
{
|
||||
GetGattDeviceInfo(json, PROFILE_ID_BLE_ADVERTISER);
|
||||
}
|
||||
|
||||
void BtStatistic::GetBleCentralDeviceInfo(cJSON *json)
|
||||
{
|
||||
GetGattDeviceInfo(json, PROFILE_ID_BLE_CENTRAL_MANAGER_SERVER);
|
||||
}
|
||||
|
||||
void BtStatistic::GetBleGattDeviceInfo(cJSON *json)
|
||||
{
|
||||
GetGattDeviceInfo(json, PROFILE_ID_BLE_GATT_MANAGER);
|
||||
}
|
||||
|
||||
void BtStatistic::GetA2dpSrcDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
A2dpSource::GetProfile()->GetDevicesByStates(connectState_, devices);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_A2DP_SRC);
|
||||
}
|
||||
|
||||
void BtStatistic::GetA2dpSinkDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
devices = A2dpSink::GetProfile()->GetDevicesByStates(connectState_);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_A2DP_SINK);
|
||||
}
|
||||
|
||||
void BtStatistic::GetAvrCTDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
devices = AvrcpController::GetProfile()->GetDevicesByStates(connectState_);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_AVRCP_CT);
|
||||
}
|
||||
|
||||
void BtStatistic::GetAvrTGDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
devices = AvrcpTarget::GetProfile()->GetDevicesByStates(connectState_);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_AVRCP_TG);
|
||||
}
|
||||
|
||||
void BtStatistic::GetHfpAGDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
devices = HandsFreeAudioGateway::GetProfile()->GetDevicesByStates(connectState_);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_HFP_AG);
|
||||
}
|
||||
|
||||
void BtStatistic::GetHfpHFDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
devices = HandsFreeUnit::GetProfile()->GetDevicesByStates(connectState_);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_HFP_HF);
|
||||
}
|
||||
|
||||
void BtStatistic::GetMapMseDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
MapMse::GetProfile()->GetDevicesByStates(connectState_, devices);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_MAP_MSE);
|
||||
}
|
||||
|
||||
void BtStatistic::GetPbapPseDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
PbapPse::GetProfile()->GetDevicesByStates(connectState_, devices);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_PBAP_PSE);
|
||||
}
|
||||
|
||||
void BtStatistic::GetHidHostDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
HidHost::GetProfile()->GetDevicesByStates(connectState_, devices);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_HID_HOST);
|
||||
}
|
||||
|
||||
void BtStatistic::GetOppDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
Opp::GetProfile()->GetDevicesByStates(connectState_, devices);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_OPP);
|
||||
}
|
||||
|
||||
void BtStatistic::GetPanDeviceInfo(cJSON *json)
|
||||
{
|
||||
std::vector<BluetoothRemoteDevice> devices;
|
||||
Pan::GetProfile()->GetDevicesByStates(connectState_, devices);
|
||||
AddDevicesToArray(json, devices, PROFILE_ID_PAN);
|
||||
}
|
||||
|
||||
} // namespace SoftBus
|
||||
} // namespace Communication
|
@ -29,10 +29,13 @@
|
||||
#include "softbus_proxychannel_manager.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "trans_auth_manager.h"
|
||||
#include "trans_channel_common.h"
|
||||
#include "trans_event.h"
|
||||
#include "trans_tcp_direct_sessionconn.h"
|
||||
#include "trans_udp_channel_manager.h"
|
||||
#include "utils/wifi_direct_anonymous.h"
|
||||
#include "wifi_statistic.h"
|
||||
#include "bt_statistic.h"
|
||||
|
||||
using namespace OHOS::SoftBus;
|
||||
|
||||
@ -231,6 +234,41 @@ static bool InstIsMatchSessionConn(const InstantRemoteInfo *rInfo, const Session
|
||||
}
|
||||
}
|
||||
|
||||
static std::string GetUdidByTcpChannelInfo(const TcpChannelInfo *conn)
|
||||
{
|
||||
if (conn->channelType == CHANNEL_TYPE_TCP_DIRECT || conn->channelType == CHANNEL_TYPE_PROXY ||
|
||||
conn->channelType == CHANNEL_TYPE_UDP) {
|
||||
char peerUdid[DEVICE_ID_SIZE_MAX] = { 0 };
|
||||
GetRemoteUdidWithNetworkId(conn->peerDeviceId, peerUdid, sizeof(peerUdid));
|
||||
return std::string(peerUdid);
|
||||
} else if (conn->channelType == CHANNEL_TYPE_AUTH) {
|
||||
return std::string(conn->peerDeviceId);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static bool InstIsMatchTcpChannel(const InstantRemoteInfo *rInfo, const TcpChannelInfo *conn)
|
||||
{
|
||||
if (rInfo == nullptr || conn == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "invalid param");
|
||||
return false;
|
||||
}
|
||||
if (InstantIsParaMatch(rInfo->uuid, GetUdidByTcpChannelInfo(conn))) {
|
||||
return true;
|
||||
}
|
||||
int32_t type = InstGetIpFromLinkTypeOrConnectType(rInfo, conn->linkType, conn->connectType);
|
||||
switch (type) {
|
||||
case HML_IP:
|
||||
return InstantIsParaMatch(rInfo->hmlIp, conn->peerIp);
|
||||
case P2P_IP:
|
||||
return InstantIsParaMatch(rInfo->p2pIp, conn->peerIp);
|
||||
case WLAN_IP:
|
||||
return InstantIsParaMatch(rInfo->wlanIp, conn->peerIp);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void InstSetIpForRemoteInfo(InstantRemoteInfo *remoteInfo, const AppInfo *appInfo)
|
||||
{
|
||||
if (remoteInfo == NULL || appInfo == NULL) {
|
||||
@ -290,6 +328,35 @@ static void UpdateRemoteInfoBySessionConn(InstantRemoteInfo *remoteInfo, const S
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateRemoteInfoByTcpChannelInfo(InstantRemoteInfo *remoteInfo, const TcpChannelInfo *conn)
|
||||
{
|
||||
if (remoteInfo == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param remote info is null");
|
||||
return;
|
||||
}
|
||||
if (conn == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param conn is null");
|
||||
return;
|
||||
}
|
||||
int32_t type = InstGetIpFromLinkTypeOrConnectType(remoteInfo, conn->linkType, conn->connectType);
|
||||
switch (type) {
|
||||
case HML_IP:
|
||||
remoteInfo->hmlIp = std::string(conn->peerIp);
|
||||
break;
|
||||
case P2P_IP:
|
||||
remoteInfo->p2pIp = std::string(conn->peerIp);
|
||||
break;
|
||||
case WLAN_IP:
|
||||
remoteInfo->wlanIp = std::string(conn->peerIp);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (remoteInfo->udid.empty()) {
|
||||
remoteInfo->udid = GetUdidByTcpChannelInfo(conn);
|
||||
}
|
||||
}
|
||||
|
||||
static InstantChannelInfo *InstCreateAndAddChannelInfo(InstantRemoteInfo *remoteInfo)
|
||||
{
|
||||
if (remoteInfo == NULL) {
|
||||
@ -330,6 +397,25 @@ static void InstAddSessionConnToRemoteInfo(InstantRemoteInfo *remoteInfo, Sessio
|
||||
UpdateRemoteInfoBySessionConn(remoteInfo, conn);
|
||||
}
|
||||
|
||||
static void InstAddTcpChannelInfoToRemoteInfo(InstantRemoteInfo *remoteInfo, TcpChannelInfo *conn)
|
||||
{
|
||||
if (remoteInfo == nullptr || conn == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "invalid param");
|
||||
return;
|
||||
}
|
||||
InstantChannelInfo *channelInfo = InstCreateAndAddChannelInfo(remoteInfo);
|
||||
if (channelInfo == nullptr) {
|
||||
return;
|
||||
}
|
||||
channelInfo->serverSide = conn->isServer;
|
||||
channelInfo->laneLinkType = conn->linkType;
|
||||
channelInfo->connectType = conn->connectType;
|
||||
channelInfo->startTime = GetSoftbusRecordTimeMillis() - conn->timeStart;
|
||||
channelInfo->channelType = CHANNEL_TYPE_TCP_DIRECT;
|
||||
channelInfo->socketName = conn->peerSessionName;
|
||||
UpdateRemoteInfoByTcpChannelInfo(remoteInfo, conn);
|
||||
}
|
||||
|
||||
static void InstUpdateRemoteInfoBySessionConn(SoftBusList *remoteChannelInfoList)
|
||||
{
|
||||
SessionConn *item = NULL;
|
||||
@ -356,6 +442,32 @@ static void InstUpdateRemoteInfoBySessionConn(SoftBusList *remoteChannelInfoList
|
||||
ReleaseSessionConnLock();
|
||||
}
|
||||
|
||||
static void InstUpdateRemoteInfoByTcpChannel(SoftBusList *remoteChannelInfoList)
|
||||
{
|
||||
TcpChannelInfo *item = NULL;
|
||||
SoftBusList *tcpChannelInfoList = GetTcpChannelInfoList();
|
||||
if (tcpChannelInfoList == NULL || GetTcpChannelInfoLock() != SOFTBUS_OK) {
|
||||
return;
|
||||
}
|
||||
LIST_FOR_EACH_ENTRY(item, &tcpChannelInfoList->list, TcpChannelInfo, node) {
|
||||
InstantRemoteInfo *rInfo = NULL;
|
||||
bool matched = false;
|
||||
LIST_FOR_EACH_ENTRY(rInfo, &remoteChannelInfoList->list, InstantRemoteInfo, node) {
|
||||
if (InstIsMatchTcpChannel(rInfo, item)) {
|
||||
matched = true;
|
||||
InstAddTcpChannelInfoToRemoteInfo(rInfo, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
rInfo = InstCreateAndAddRemoteInfo(remoteChannelInfoList, matched);
|
||||
if (rInfo == NULL) {
|
||||
continue;
|
||||
}
|
||||
InstAddTcpChannelInfoToRemoteInfo(rInfo, item);
|
||||
}
|
||||
ReleaseTcpChannelInfoLock();
|
||||
}
|
||||
|
||||
static bool InstIsMatchUdpChannel(const InstantRemoteInfo *rInfo, const UdpChannelInfo *info)
|
||||
{
|
||||
if (rInfo == NULL || info == NULL) {
|
||||
@ -781,6 +893,7 @@ static void InstGetRemoteInfo(cJSON *json)
|
||||
}
|
||||
InstAddRemoteInfoByLinkManager(remoteChannelInfoList);
|
||||
InstUpdateRemoteInfoBySessionConn(remoteChannelInfoList);
|
||||
InstUpdateRemoteInfoByTcpChannel(remoteChannelInfoList);
|
||||
InstUpdateRemoteInfoByUdpChannel(remoteChannelInfoList);
|
||||
InstUpdateRemoteInfoByProxyChannel(remoteChannelInfoList);
|
||||
InstUpdateByAuthChannelList(remoteChannelInfoList);
|
||||
@ -800,6 +913,14 @@ static int32_t InstGetAllInfo(int32_t radarId, int32_t errorCode)
|
||||
InstGetRemoteInfo(remoteDevicesJson);
|
||||
}
|
||||
|
||||
cJSON *wifiJson = cJSON_CreateObject();
|
||||
Communication::Softbus::WifiStatistic::GetInstance().GetWifiStatisticInfo(wifiJson);
|
||||
(void)cJSON_AddItemToObject(json, "WifiInfo", wifiJson);
|
||||
|
||||
cJSON *btJson = cJSON_CreateObject();
|
||||
Communication::Softbus::BtStatistic::GetInstance().GetBtStatisticInfo(btJson);
|
||||
(void)cJSON_AddItemToObject(json, "BtInfo", btJson);
|
||||
|
||||
char *info = cJSON_PrintUnformatted(json);
|
||||
cJSON_Delete(json);
|
||||
COMM_CHECK_AND_RETURN_RET_LOGE(info != NULL, SOFTBUS_PARSE_JSON_ERR, COMM_DFX, "cJSON_PrintUnformatted fail");
|
||||
|
167
core/common/dfx/statistics/instant/wifi_statistic.cpp
Normal file
167
core/common/dfx/statistics/instant/wifi_statistic.cpp
Normal file
@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "wifi_statistic.h"
|
||||
|
||||
#include "inner_api/wifi_device.h"
|
||||
#include "inner_api/wifi_hotspot.h"
|
||||
#include "inner_api/wifi_p2p.h"
|
||||
#include "comm_log.h"
|
||||
#include "softbus_error_code.h"
|
||||
#include "softbus_json_utils.h"
|
||||
#include "utils/wifi_direct_anonymous.h"
|
||||
|
||||
using namespace OHOS::Wifi;
|
||||
|
||||
namespace Communication {
|
||||
namespace Softbus {
|
||||
|
||||
WifiStatistic& WifiStatistic::GetInstance()
|
||||
{
|
||||
static WifiStatistic instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
int32_t WifiStatistic::GetWifiStatisticInfo(cJSON *json)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (GetStaInfo(json) != SOFTBUS_OK || GetSoftApInfo(json) != SOFTBUS_OK || GetP2PInfo(json) != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t WifiStatistic::GetStaInfo(cJSON *json)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
std::shared_ptr<WifiDevice> wifiStaPtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
|
||||
if (wifiStaPtr == nullptr) {
|
||||
COMM_LOGW(COMM_DFX, "Get wifi device fail");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
cJSON *staJson = cJSON_CreateObject();
|
||||
WifiLinkedInfo wifiLinkedInfo;
|
||||
if (wifiStaPtr->GetLinkedInfo(wifiLinkedInfo) != 0) {
|
||||
(void)AddNumberToJsonObject(staJson, "IsStaExist", 0);
|
||||
(void)cJSON_AddItemToObject(json, "StaInfo", staJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
(void)AddNumberToJsonObject(staJson, "IsStaExist", 1);
|
||||
(void)AddStringToJsonObject(staJson, "Name", wifiLinkedInfo.ssid.c_str());
|
||||
(void)AddStringToJsonObject(staJson, "Mac",
|
||||
OHOS::SoftBus::WifiDirectAnonymizeMac(wifiLinkedInfo.bssid).c_str());
|
||||
(void)AddNumberToJsonObject(staJson, "Freq", wifiLinkedInfo.frequency);
|
||||
(void)AddNumberToJsonObject(staJson, "chload", wifiLinkedInfo.chload);
|
||||
|
||||
(void)cJSON_AddItemToObject(json, "StaInfo", staJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t WifiStatistic::GetSoftApInfo(cJSON *json)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
std::shared_ptr<WifiHotspot> wifiSoftApPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
|
||||
if (wifiSoftApPtr == nullptr) {
|
||||
COMM_LOGW(COMM_DFX, "Get wifi soft ap fail");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
cJSON *softApJson = cJSON_CreateObject();
|
||||
bool isHotspotActive = false;
|
||||
wifiSoftApPtr->IsHotspotActive(isHotspotActive);
|
||||
if (!isHotspotActive) {
|
||||
(void)AddNumberToJsonObject(softApJson, "IsSoftApExist", 0);
|
||||
(void)cJSON_AddItemToObject(json, "SoftApInfo", softApJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
(void)AddNumberToJsonObject(softApJson, "IsSoftApExist", 1);
|
||||
HotspotConfig config;
|
||||
wifiSoftApPtr->GetHotspotConfig(config);
|
||||
(void)AddNumberToJsonObject(softApJson, "channel", config.GetChannel());
|
||||
std::vector<StationInfo> stationList;
|
||||
if (wifiSoftApPtr->GetStationList(stationList) != 0 || stationList.size() == 0) {
|
||||
(void)AddNumberToJsonObject(softApJson, "StaNum", 0);
|
||||
(void)cJSON_AddItemToObject(json, "SoftApInfo", softApJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
(void)AddNumberToJsonObject(softApJson, "StaNum", stationList.size());
|
||||
cJSON *stationArray = cJSON_CreateArray();
|
||||
for (size_t i = 0; i < stationList.size(); i++) {
|
||||
cJSON *stationJson = cJSON_CreateObject();
|
||||
(void)AddStringToJsonObject(stationJson, "Name", stationList[i].deviceName.c_str());
|
||||
(void)AddStringToJsonObject(stationJson, "Mac",
|
||||
OHOS::SoftBus::WifiDirectAnonymizeMac(stationList[i].bssid).c_str());
|
||||
(void)cJSON_AddItemToArray(stationArray, stationJson);
|
||||
}
|
||||
(void)cJSON_AddItemToObject(softApJson, "StaDevList", stationArray);
|
||||
(void)cJSON_AddItemToObject(json, "SoftApInfo", softApJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t WifiStatistic::GetP2PInfo(cJSON *json)
|
||||
{
|
||||
if (json == nullptr) {
|
||||
COMM_LOGE(COMM_DFX, "param json is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
std::shared_ptr<WifiP2p> wifiP2PPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
|
||||
if (wifiP2PPtr == nullptr) {
|
||||
COMM_LOGW(COMM_DFX, "Get wifi p2p fail");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
cJSON *p2pJson = cJSON_CreateObject();
|
||||
WifiP2pGroupInfo groupInfo;
|
||||
if (wifiP2PPtr->GetCurrentGroup(groupInfo) != 0) {
|
||||
(void)AddNumberToJsonObject(p2pJson, "IsP2PExist", 0);
|
||||
(void)cJSON_AddItemToObject(json, "P2PInfo", p2pJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
(void)AddNumberToJsonObject(p2pJson, "IsP2PExist", 1);
|
||||
(void)AddBoolToJsonObject(p2pJson, "IsP2POwner", groupInfo.IsGroupOwner());
|
||||
(void)AddNumberToJsonObject(p2pJson, "Freq", groupInfo.GetFrequency());
|
||||
if (!groupInfo.IsGroupOwner()) {
|
||||
cJSON *goJson = cJSON_CreateObject();
|
||||
(void)AddStringToJsonObject(goJson, "Name", groupInfo.GetOwner().GetDeviceName().c_str());
|
||||
(void)AddStringToJsonObject(goJson, "Mac",
|
||||
OHOS::SoftBus::WifiDirectAnonymizeMac(groupInfo.GetOwner().GetRandomDeviceAddress()).c_str());
|
||||
(void)cJSON_AddItemToObject(p2pJson, "GOInfo", goJson);
|
||||
(void)cJSON_AddItemToObject(json, "P2PInfo", p2pJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
std::vector<WifiP2pDevice> gcList = groupInfo.GetClientDevices();
|
||||
(void)AddNumberToJsonObject(p2pJson, "GCNum", gcList.size());
|
||||
cJSON *gcArray = cJSON_CreateArray();
|
||||
for (size_t i = 0; i < gcList.size(); i++) {
|
||||
cJSON *gcJson = cJSON_CreateObject();
|
||||
(void)AddStringToJsonObject(gcJson, "Name", gcList[i].GetDeviceName().c_str());
|
||||
(void)AddStringToJsonObject(gcJson, "Mac",
|
||||
OHOS::SoftBus::WifiDirectAnonymizeMac(gcList[i].GetRandomDeviceAddress()).c_str());
|
||||
(void)cJSON_AddItemToArray(gcArray, gcJson);
|
||||
}
|
||||
(void)cJSON_AddItemToObject(p2pJson, "GCInfo", gcArray);
|
||||
(void)cJSON_AddItemToObject(json, "P2PInfo", p2pJson);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
} // namespace SoftBus
|
||||
} // namespace Communication
|
@ -94,8 +94,15 @@ if (defined(ohos_lite)) {
|
||||
external_deps += auth_server_ex_deps
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.hmoshiviewdfx_hiview_xcommradar_plugin)) {
|
||||
include_dirs += [ "$dsoftbus_root_path/../../../vendor/huawei/base/hiviewdfx/hiview_plugins/communication_radar_plugin/interfaces/inner_api/communication_radar" ]
|
||||
sources += [ "$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics.cpp" ]
|
||||
include_dirs += [
|
||||
"$dsoftbus_root_path/../../../vendor/huawei/base/hiviewdfx/hiview_plugins/communication_radar_plugin/interfaces/inner_api/communication_radar",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/include",
|
||||
]
|
||||
sources += [
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/bt_statistic.cpp",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics.cpp",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/wifi_statistic.cpp",
|
||||
]
|
||||
external_deps +=
|
||||
[ "hiview_xcommradar_plugin:communication_radar_client" ]
|
||||
} else {
|
||||
@ -165,8 +172,15 @@ if (defined(ohos_lite)) {
|
||||
external_deps += auth_server_ex_deps
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.hmoshiviewdfx_hiview_xcommradar_plugin)) {
|
||||
include_dirs += [ "$dsoftbus_root_path/../../../vendor/huawei/base/hiviewdfx/hiview_plugins/communication_radar_plugin/interfaces/inner_api/communication_radar" ]
|
||||
sources += [ "$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics.cpp" ]
|
||||
include_dirs += [
|
||||
"$dsoftbus_root_path/../../../vendor/huawei/base/hiviewdfx/hiview_plugins/communication_radar_plugin/interfaces/inner_api/communication_radar",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/include",
|
||||
]
|
||||
sources += [
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/bt_statistic.cpp",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics.cpp",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/wifi_statistic.cpp",
|
||||
]
|
||||
external_deps +=
|
||||
[ "hiview_xcommradar_plugin:communication_radar_client" ]
|
||||
} else {
|
||||
@ -304,8 +318,15 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.hmoshiviewdfx_hiview_xcommradar_plugin)) {
|
||||
include_dirs += [ "$dsoftbus_root_path/../../../vendor/huawei/base/hiviewdfx/hiview_plugins/communication_radar_plugin/interfaces/inner_api/communication_radar" ]
|
||||
sources += [ "$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics.cpp" ]
|
||||
include_dirs += [
|
||||
"$dsoftbus_root_path/../../../vendor/huawei/base/hiviewdfx/hiview_plugins/communication_radar_plugin/interfaces/inner_api/communication_radar",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/include",
|
||||
]
|
||||
sources += [
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/bt_statistic.cpp",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics.cpp",
|
||||
"$dsoftbus_root_path/core/common/dfx/statistics/instant/wifi_statistic.cpp",
|
||||
]
|
||||
external_deps += [ "hiview_xcommradar_plugin:communication_radar_client" ]
|
||||
} else {
|
||||
sources += [ "$dsoftbus_root_path/core/common/dfx/statistics/instant/instant_statistics_virtual.cpp" ]
|
||||
|
@ -60,6 +60,13 @@ typedef struct {
|
||||
int32_t businessType;
|
||||
int32_t connectType;
|
||||
char myIp[IP_LEN];
|
||||
bool isServer;
|
||||
int32_t channelType;
|
||||
char peerSessionName[SESSION_NAME_SIZE_MAX];
|
||||
char peerDeviceId[DEVICE_ID_SIZE_MAX];
|
||||
char peerIp[IP_LEN];
|
||||
int64_t timeStart;
|
||||
int32_t linkType;
|
||||
} TcpChannelInfo;
|
||||
|
||||
uint64_t TransTdcGetNewSeqId(void);
|
||||
@ -68,10 +75,16 @@ int32_t CreatSessionConnList(void);
|
||||
|
||||
SoftBusList *GetSessionConnList(void);
|
||||
|
||||
SoftBusList *GetTcpChannelInfoList(void);
|
||||
|
||||
int32_t GetSessionConnLock(void);
|
||||
|
||||
int32_t GetTcpChannelInfoLock(void);
|
||||
|
||||
void ReleaseSessionConnLock(void);
|
||||
|
||||
void ReleaseTcpChannelInfoLock(void);
|
||||
|
||||
SessionConn *GetSessionConnByRequestId(uint32_t requestId);
|
||||
|
||||
SessionConn *GetSessionConnByReq(int64_t req);
|
||||
|
@ -68,6 +68,11 @@ SoftBusList *GetSessionConnList(void)
|
||||
return g_sessionConnList;
|
||||
}
|
||||
|
||||
SoftBusList *GetTcpChannelInfoList(void)
|
||||
{
|
||||
return g_tcpChannelInfoList;
|
||||
}
|
||||
|
||||
int32_t GetSessionConnLock(void)
|
||||
{
|
||||
if (g_sessionConnList == NULL) {
|
||||
@ -79,6 +84,14 @@ int32_t GetSessionConnLock(void)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t GetTcpChannelInfoLock(void)
|
||||
{
|
||||
if (g_tcpChannelInfoList == NULL) {
|
||||
return SOFTBUS_NO_INIT;
|
||||
}
|
||||
return SoftBusMutexLock(&g_tcpChannelInfoList->lock);
|
||||
}
|
||||
|
||||
void ReleaseSessionConnLock(void)
|
||||
{
|
||||
if (g_sessionConnList == NULL) {
|
||||
@ -87,6 +100,14 @@ void ReleaseSessionConnLock(void)
|
||||
(void)SoftBusMutexUnlock(&g_sessionConnList->lock);
|
||||
}
|
||||
|
||||
void ReleaseTcpChannelInfoLock(void)
|
||||
{
|
||||
if (g_tcpChannelInfoList == NULL) {
|
||||
return;
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&g_tcpChannelInfoList->lock);
|
||||
}
|
||||
|
||||
SessionConn *GetSessionConnByRequestId(uint32_t requestId)
|
||||
{
|
||||
if (g_sessionConnList == NULL) {
|
||||
@ -336,6 +357,9 @@ int32_t CreateTcpChannelInfoList(void)
|
||||
|
||||
TcpChannelInfo *CreateTcpChannelInfo(const ChannelInfo *channel)
|
||||
{
|
||||
if (channel == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
TcpChannelInfo *tcpChannelInfo = (TcpChannelInfo *)SoftBusCalloc(sizeof(TcpChannelInfo));
|
||||
if (tcpChannelInfo == NULL) {
|
||||
return NULL;
|
||||
@ -348,6 +372,25 @@ TcpChannelInfo *CreateTcpChannelInfo(const ChannelInfo *channel)
|
||||
SoftBusFree(tcpChannelInfo);
|
||||
return NULL;
|
||||
}
|
||||
tcpChannelInfo->isServer = channel->isServer;
|
||||
tcpChannelInfo->channelType = channel->channelType;
|
||||
if (strcpy_s(tcpChannelInfo->peerSessionName, SESSION_NAME_SIZE_MAX, channel->peerSessionName) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "failed to strcpy peerSessionName, channelId=%{public}d", channel->channelId);
|
||||
SoftBusFree(tcpChannelInfo);
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(tcpChannelInfo->peerDeviceId, DEVICE_ID_SIZE_MAX, channel->peerDeviceId) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "failed to strcpy peerDeviceId, channelId=%{public}d", channel->channelId);
|
||||
SoftBusFree(tcpChannelInfo);
|
||||
return NULL;
|
||||
}
|
||||
if (strcpy_s(tcpChannelInfo->peerIp, IP_LEN, channel->peerIp) != EOK) {
|
||||
TRANS_LOGE(TRANS_CTRL, "failed to strcpy peerDeviceId, channelId=%{public}d", channel->channelId);
|
||||
SoftBusFree(tcpChannelInfo);
|
||||
return NULL;
|
||||
}
|
||||
tcpChannelInfo->timeStart = channel->timeStart;
|
||||
tcpChannelInfo->linkType = channel->linkType;
|
||||
return tcpChannelInfo;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user