Make sure no memory overhead if statistics are disabled

pull/8592/head
deepikabhavnani 2018-11-20 23:25:53 -06:00
parent fa6b3d2783
commit c272377a81
16 changed files with 35 additions and 27 deletions

View File

@ -38,7 +38,7 @@ NetworkInterface *net;
Timer tc_bucket; // Timer to limit a test cases run time 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]; mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
#endif #endif
@ -119,7 +119,7 @@ int split2half_rmng_tcp_test_time()
return (tcp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2; 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() int fetch_stats()
{ {
return SocketStats::mbed_stats_socket_get_each(&tcp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT); return SocketStats::mbed_stats_socket_get_each(&tcp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);

View File

@ -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_echo_srv(TCPSocket &sock);
nsapi_error_t tcpsocket_connect_to_discard_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]; extern mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
int fetch_stats(void); int fetch_stats(void);
#endif #endif

View File

@ -114,7 +114,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
void TCPSOCKET_ECHOTEST_NONBLOCK() void TCPSOCKET_ECHOTEST_NONBLOCK()
{ {
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int j = 0; int j = 0;
int count = fetch_stats(); int count = fetch_stats();
for (; j < count; j++) { for (; j < count; j++) {
@ -167,7 +167,7 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
bytes2send -= sent; bytes2send -= sent;
} }
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s); 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(); count = fetch_stats();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) { if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) {

View File

@ -26,7 +26,7 @@ using namespace utest::v1;
void TCPSOCKET_OPEN_CLOSE_REPEAT() void TCPSOCKET_OPEN_CLOSE_REPEAT()
{ {
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats(); int count = fetch_stats();
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); 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()); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
} }
delete sock; delete sock;
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats(); count = fetch_stats();
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state);

View File

@ -70,7 +70,7 @@ void TCPSOCKET_OPEN_LIMIT()
break; break;
} }
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats(); int count = fetch_stats();
int open_count = 0; int open_count = 0;
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {

View File

@ -37,7 +37,7 @@ namespace {
NetworkInterface *net; 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]; mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
#endif #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() int fetch_stats()
{ {
return SocketStats::mbed_stats_socket_get_each(&udp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT); return SocketStats::mbed_stats_socket_get_each(&udp_stats[0], MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT);

View File

@ -22,7 +22,7 @@ NetworkInterface *get_interface();
void drop_bad_packets(UDPSocket &sock, int orig_timeout); void drop_bad_packets(UDPSocket &sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len); 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]; extern mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
int fetch_stats(void); int fetch_stats(void);
#endif #endif

View File

@ -121,7 +121,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
void UDPSOCKET_ECHOTEST_NONBLOCK() void UDPSOCKET_ECHOTEST_NONBLOCK()
{ {
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int j = 0; int j = 0;
int count = fetch_stats(); int count = fetch_stats();
for (; j < count; j++) { 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); 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); 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(); count = fetch_stats();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
if ((NSAPI_UDP == udp_stats[j].proto) && (SOCK_OPEN == udp_stats[j].state)) { if ((NSAPI_UDP == udp_stats[j].proto) && (SOCK_OPEN == udp_stats[j].state)) {

View File

@ -26,7 +26,7 @@ using namespace utest::v1;
void UDPSOCKET_OPEN_CLOSE_REPEAT() void UDPSOCKET_OPEN_CLOSE_REPEAT()
{ {
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats(); int count = fetch_stats();
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); 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()); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
} }
delete sock; delete sock;
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats(); count = fetch_stats();
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {
TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);

View File

@ -70,7 +70,7 @@ void UDPSOCKET_OPEN_LIMIT()
if (!socket_list_head) { if (!socket_list_head) {
break; break;
} }
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int count = fetch_stats(); int count = fetch_stats();
int open_count = 0; int open_count = 0;
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {

View File

@ -16,10 +16,12 @@
#include "SocketStats.h" #include "SocketStats.h"
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
int SocketStats::get_entry_position(const Socket *const reference_id) int SocketStats::get_entry_position(const Socket *const reference_id)
{ {
return 0; return 0;
} }
#endif
size_t SocketStats::mbed_stats_socket_get_each(mbed_stats_socket_t *stats, size_t count) size_t SocketStats::mbed_stats_socket_get_each(mbed_stats_socket_t *stats, size_t count)
{ {

View File

@ -24,7 +24,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
SingletonPtr<PlatformMutex> SocketStats::_mutex; SingletonPtr<PlatformMutex> SocketStats::_mutex;
mbed_stats_socket_t SocketStats::_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT]; mbed_stats_socket_t SocketStats::_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
uint32_t SocketStats::_size = 0; 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); MBED_ASSERT(stats != NULL);
size_t i = 0; 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)); memset(stats, 0, count * sizeof(mbed_stats_socket_t));
_mutex->lock(); _mutex->lock();
for (uint32_t j = 0; j < count; j++) { 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) 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(); _mutex->lock();
if (get_entry_position(reference_id) >= 0) { if (get_entry_position(reference_id) >= 0) {
// Duplicate entry // 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) 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(); _mutex->lock();
int position = get_entry_position(reference_id); int position = get_entry_position(reference_id);
if (position >= 0) { 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) 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(); _mutex->lock();
int position = get_entry_position(reference_id); int position = get_entry_position(reference_id);
if ((position >= 0) && (!_stats[position].peer)) { 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) 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(); _mutex->lock();
int position = get_entry_position(reference_id); int position = get_entry_position(reference_id);
if (position >= 0) { 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) 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(); _mutex->lock();
int position = get_entry_position(reference_id); int position = get_entry_position(reference_id);
if ((position >= 0) && ((int32_t)sent_bytes > 0)) { 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) 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(); _mutex->lock();
int position = get_entry_position(reference_id); int position = get_entry_position(reference_id);
if ((position >= 0) && ((int32_t)recv_bytes > 0)) { if ((position >= 0) && ((int32_t)recv_bytes > 0)) {

View File

@ -143,7 +143,7 @@ public:
*/ */
void stats_update_recv_bytes(const Socket *const reference_id, size_t recv_bytes); 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: private:
static mbed_stats_socket_t _stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT]; static mbed_stats_socket_t _stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
static SingletonPtr<PlatformMutex> _mutex; static SingletonPtr<PlatformMutex> _mutex;

View File

@ -11,7 +11,6 @@
}, },
"target_overrides": { "target_overrides": {
"*": { "*": {
"nsapi.socket-stats-enable": true,
"target.network-default-interface-type": "ETHERNET" "target.network-default-interface-type": "ETHERNET"
} }
} }

View File

@ -16,7 +16,6 @@
}, },
"target_overrides": { "target_overrides": {
"*": { "*": {
"nsapi.socket-stats-enable": true,
"target.network-default-interface-type": "ETHERNET" "target.network-default-interface-type": "ETHERNET"
} }
} }

View File

@ -1,33 +1,41 @@
{ {
"UBLOX_EVK_ODIN_W2": { "UBLOX_EVK_ODIN_W2": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE", "default_test_configuration": "NONE",
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI", "HEAPBLOCKDEVICE_AND_ETHERNET"] "test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI", "HEAPBLOCKDEVICE_AND_ETHERNET"]
}, },
"REALTEK_RTL8195AM": { "REALTEK_RTL8195AM": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE", "default_test_configuration": "NONE",
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"] "test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"]
}, },
"K64F": { "K64F": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET", "default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET",
"test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER", "ESP8266_WIFI", "ETHERNET"] "test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER", "ESP8266_WIFI", "ETHERNET"]
}, },
"NUCLEO_F429ZI": { "NUCLEO_F429ZI": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET", "default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET",
"test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER"] "test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER"]
}, },
"DISCO_L475VG_IOT01A": { "DISCO_L475VG_IOT01A": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE", "default_test_configuration": "NONE",
"test_configurations": ["ISM43362_WIFI"] "test_configurations": ["ISM43362_WIFI"]
}, },
"DISCO_F413ZH": { "DISCO_F413ZH": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE", "default_test_configuration": "NONE",
"test_configurations": ["ISM43362_WIFI"] "test_configurations": ["ISM43362_WIFI"]
}, },
"MTB_UBLOX_ODIN_W2": { "MTB_UBLOX_ODIN_W2": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE", "default_test_configuration": "NONE",
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"] "test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"]
}, },
"MTB_ADV_WISE_1530": { "MTB_ADV_WISE_1530": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE", "default_test_configuration": "NONE",
"test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"] "test_configurations": ["HEAPBLOCKDEVICE_AND_WIFI"]
}, },