mirror of https://github.com/ARMmbed/mbed-os.git
Make sure no memory overhead if statistics are disabled
parent
fa6b3d2783
commit
c272377a81
|
@ -38,7 +38,7 @@ NetworkInterface *net;
|
|||
Timer tc_bucket; // Timer to limit a test cases run time
|
||||
}
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
#endif
|
||||
|
||||
|
@ -119,7 +119,7 @@ int split2half_rmng_tcp_test_time()
|
|||
return (tcp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
|
||||
}
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int fetch_stats()
|
||||
{
|
||||
return SocketStats::mbed_stats_socket_get_each(&tcp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
|
||||
|
|
|
@ -24,7 +24,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len);
|
|||
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
|
||||
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
extern mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
int fetch_stats(void);
|
||||
#endif
|
||||
|
|
|
@ -114,7 +114,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
|
||||
void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int j = 0;
|
||||
int count = fetch_stats();
|
||||
for (; j < count; j++) {
|
||||
|
@ -167,7 +167,7 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
|||
bytes2send -= sent;
|
||||
}
|
||||
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
count = fetch_stats();
|
||||
for (j = 0; j < count; j++) {
|
||||
if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) {
|
||||
|
|
|
@ -26,7 +26,7 @@ using namespace utest::v1;
|
|||
|
||||
void TCPSOCKET_OPEN_CLOSE_REPEAT()
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int count = fetch_stats();
|
||||
for (int j = 0; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
|
||||
|
@ -42,7 +42,7 @@ void TCPSOCKET_OPEN_CLOSE_REPEAT()
|
|||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||
}
|
||||
delete sock;
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
count = fetch_stats();
|
||||
for (int j = 0; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);
|
||||
|
|
|
@ -70,7 +70,7 @@ void TCPSOCKET_OPEN_LIMIT()
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int count = fetch_stats();
|
||||
int open_count = 0;
|
||||
for (int j = 0; j < count; j++) {
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace {
|
|||
NetworkInterface *net;
|
||||
}
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
#endif
|
||||
|
||||
|
@ -80,7 +80,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int fetch_stats()
|
||||
{
|
||||
return SocketStats::mbed_stats_socket_get_each(&udp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);
|
||||
|
|
|
@ -22,7 +22,7 @@ NetworkInterface *get_interface();
|
|||
void drop_bad_packets(UDPSocket &sock, int orig_timeout);
|
||||
void fill_tx_buffer_ascii(char *buff, size_t len);
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
extern mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
int fetch_stats(void);
|
||||
#endif
|
||||
|
|
|
@ -121,7 +121,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
|
||||
void UDPSOCKET_ECHOTEST_NONBLOCK()
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int j = 0;
|
||||
int count = fetch_stats();
|
||||
for (; j < count; j++) {
|
||||
|
@ -189,7 +189,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
|||
printf("Packets sent: %d, packets received %d, loss ratio %.2lf\r\n", packets_sent, packets_recv, loss_ratio);
|
||||
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
count = fetch_stats();
|
||||
for (j = 0; j < count; j++) {
|
||||
if ((NSAPI_UDP == udp_stats[j].proto) && (SOCK_OPEN == udp_stats[j].state)) {
|
||||
|
|
|
@ -26,7 +26,7 @@ using namespace utest::v1;
|
|||
|
||||
void UDPSOCKET_OPEN_CLOSE_REPEAT()
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int count = fetch_stats();
|
||||
for (int j = 0; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||
|
@ -42,7 +42,7 @@ void UDPSOCKET_OPEN_CLOSE_REPEAT()
|
|||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||
}
|
||||
delete sock;
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
count = fetch_stats();
|
||||
for (int j = 0; j < count; j++) {
|
||||
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
|
||||
|
|
|
@ -70,7 +70,7 @@ void UDPSOCKET_OPEN_LIMIT()
|
|||
if (!socket_list_head) {
|
||||
break;
|
||||
}
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int count = fetch_stats();
|
||||
int open_count = 0;
|
||||
for (int j = 0; j < count; j++) {
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
#include "SocketStats.h"
|
||||
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
int SocketStats::get_entry_position(const Socket *const reference_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t SocketStats::mbed_stats_socket_get_each(mbed_stats_socket_t *stats, size_t count)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
SingletonPtr<PlatformMutex> SocketStats::_mutex;
|
||||
mbed_stats_socket_t SocketStats::_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
uint32_t SocketStats::_size = 0;
|
||||
|
@ -44,7 +44,7 @@ size_t SocketStats::mbed_stats_socket_get_each(mbed_stats_socket_t *stats, size_
|
|||
{
|
||||
MBED_ASSERT(stats != NULL);
|
||||
size_t i = 0;
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
memset(stats, 0, count * sizeof(mbed_stats_socket_t));
|
||||
_mutex->lock();
|
||||
for (uint32_t j = 0; j < count; j++) {
|
||||
|
@ -64,7 +64,7 @@ SocketStats::SocketStats()
|
|||
|
||||
void SocketStats::stats_new_socket_entry(const Socket *const reference_id)
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
_mutex->lock();
|
||||
if (get_entry_position(reference_id) >= 0) {
|
||||
// Duplicate entry
|
||||
|
@ -98,7 +98,7 @@ void SocketStats::stats_new_socket_entry(const Socket *const reference_id)
|
|||
|
||||
void SocketStats::stats_update_socket_state(const Socket *const reference_id, socket_state state)
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
_mutex->lock();
|
||||
int position = get_entry_position(reference_id);
|
||||
if (position >= 0) {
|
||||
|
@ -113,7 +113,7 @@ void SocketStats::stats_update_socket_state(const Socket *const reference_id, so
|
|||
|
||||
void SocketStats::stats_update_peer(const Socket *const reference_id, const SocketAddress &peer)
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
_mutex->lock();
|
||||
int position = get_entry_position(reference_id);
|
||||
if ((position >= 0) && (!_stats[position].peer)) {
|
||||
|
@ -125,7 +125,7 @@ void SocketStats::stats_update_peer(const Socket *const reference_id, const Sock
|
|||
|
||||
void SocketStats::stats_update_proto(const Socket *const reference_id, nsapi_protocol_t proto)
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
_mutex->lock();
|
||||
int position = get_entry_position(reference_id);
|
||||
if (position >= 0) {
|
||||
|
@ -137,7 +137,7 @@ void SocketStats::stats_update_proto(const Socket *const reference_id, nsapi_pro
|
|||
|
||||
void SocketStats::stats_update_sent_bytes(const Socket *const reference_id, size_t sent_bytes)
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
_mutex->lock();
|
||||
int position = get_entry_position(reference_id);
|
||||
if ((position >= 0) && ((int32_t)sent_bytes > 0)) {
|
||||
|
@ -149,7 +149,7 @@ void SocketStats::stats_update_sent_bytes(const Socket *const reference_id, size
|
|||
|
||||
void SocketStats::stats_update_recv_bytes(const Socket *const reference_id, size_t recv_bytes)
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
_mutex->lock();
|
||||
int position = get_entry_position(reference_id);
|
||||
if ((position >= 0) && ((int32_t)recv_bytes > 0)) {
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
*/
|
||||
void stats_update_recv_bytes(const Socket *const reference_id, size_t recv_bytes);
|
||||
|
||||
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
private:
|
||||
static mbed_stats_socket_t _stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
static SingletonPtr<PlatformMutex> _mutex;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
},
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"target.network-default-interface-type": "ETHERNET"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
},
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"target.network-default-interface-type": "ETHERNET"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,41 @@
|
|||
{
|
||||
"UBLOX_EVK_ODIN_W2": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI", "HEAPBLOCKDEVICE_AND_ETHERNET"]
|
||||
},
|
||||
"REALTEK_RTL8195AM": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"]
|
||||
},
|
||||
"K64F": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET",
|
||||
"test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER", "ESP8266_WIFI", "ETHERNET"]
|
||||
},
|
||||
"NUCLEO_F429ZI": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET",
|
||||
"test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER"]
|
||||
},
|
||||
"DISCO_L475VG_IOT01A": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["ISM43362_WIFI"]
|
||||
},
|
||||
"DISCO_F413ZH": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["ISM43362_WIFI"]
|
||||
},
|
||||
"MTB_UBLOX_ODIN_W2": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"]
|
||||
},
|
||||
"MTB_ADV_WISE_1530": {
|
||||
"nsapi.socket-stats-enable": true,
|
||||
"default_test_configuration": "NONE",
|
||||
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"]
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue