mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Add config options for socket statistics
1. MBED_CONF_NSAPI_SOCKET_STATS_ENABLE to enable the statistics 2. MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT max sockets statistics cachedpull/8592/head
							parent
							
								
									a851df66e3
								
							
						
					
					
						commit
						f6c1a40b29
					
				| 
						 | 
					@ -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
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
 | 
				
			||||||
mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
 | 
					mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
 | 
				
			||||||
#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;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,7 +114,7 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TCPSOCKET_ECHOTEST_NONBLOCK()
 | 
					void TCPSOCKET_ECHOTEST_NONBLOCK()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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);
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ using namespace utest::v1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TCPSOCKET_OPEN_CLOSE_REPEAT()
 | 
					void TCPSOCKET_OPEN_CLOSE_REPEAT()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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;
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,7 +70,7 @@ void TCPSOCKET_OPEN_LIMIT()
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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++) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ namespace {
 | 
				
			||||||
NetworkInterface *net;
 | 
					NetworkInterface *net;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
 | 
				
			||||||
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
 | 
					mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,7 +80,7 @@ void fill_tx_buffer_ascii(char *buff, size_t len)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -121,7 +121,7 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UDPSOCKET_ECHOTEST_NONBLOCK()
 | 
					void UDPSOCKET_ECHOTEST_NONBLOCK()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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++) {
 | 
				
			||||||
| 
						 | 
					@ -183,7 +183,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    free(stack_mem);
 | 
					    free(stack_mem);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
 | 
				
			||||||
    TEST_ASSERT_EQUAL(1, fetch_stats());
 | 
					    TEST_ASSERT_EQUAL(1, fetch_stats());
 | 
				
			||||||
    TEST_ASSERT_EQUAL(NSAPI_UDP, udp_stats[0].proto);
 | 
					    TEST_ASSERT_EQUAL(NSAPI_UDP, udp_stats[0].proto);
 | 
				
			||||||
    TEST_ASSERT(udp_stats[0].sent_bytes != 0);
 | 
					    TEST_ASSERT(udp_stats[0].sent_bytes != 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ using namespace utest::v1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UDPSOCKET_OPEN_CLOSE_REPEAT()
 | 
					void UDPSOCKET_OPEN_CLOSE_REPEAT()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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;
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,7 +70,7 @@ void UDPSOCKET_OPEN_LIMIT()
 | 
				
			||||||
        if (!socket_list_head) {
 | 
					        if (!socket_list_head) {
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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++) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,7 @@
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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] = {0};
 | 
					mbed_stats_socket_t SocketStats::_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT] = {0};
 | 
				
			||||||
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;
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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) && (sent_bytes > 0)) {
 | 
					    if ((position >= 0) && (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)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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) && (recv_bytes > 0)) {
 | 
					    if ((position >= 0) && (recv_bytes > 0)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,6 @@
 | 
				
			||||||
#ifndef SOCKET_STATS_H
 | 
					#ifndef SOCKET_STATS_H
 | 
				
			||||||
#define SOCKET_STATS_H
 | 
					#define SOCKET_STATS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "platform/mbed_stats.h"
 | 
					 | 
				
			||||||
#include "platform/SingletonPtr.h"
 | 
					#include "platform/SingletonPtr.h"
 | 
				
			||||||
#include "platform/PlatformMutex.h"
 | 
					#include "platform/PlatformMutex.h"
 | 
				
			||||||
#include "netsocket/Socket.h"
 | 
					#include "netsocket/Socket.h"
 | 
				
			||||||
| 
						 | 
					@ -99,7 +98,7 @@ public:
 | 
				
			||||||
    /** Update bytes received on socket, which is cumulative count per socket */
 | 
					    /** Update bytes received on socket, which is cumulative count per socket */
 | 
				
			||||||
    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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(MBED_NW_STATS_ENABLED)
 | 
					#ifdef 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;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,14 @@
 | 
				
			||||||
        "dns-cache-size": {
 | 
					        "dns-cache-size": {
 | 
				
			||||||
            "help": "Number of cached host name resolutions",
 | 
					            "help": "Number of cached host name resolutions",
 | 
				
			||||||
            "value": 3
 | 
					            "value": 3
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        "socket-stats-enable": {
 | 
				
			||||||
 | 
					            "help": "Enable network socket statistics",
 | 
				
			||||||
 | 
					            "value": false
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        "socket-stats-max-count": {
 | 
				
			||||||
 | 
					            "help": "Maximum number of socket statistics cached",
 | 
				
			||||||
 | 
					            "value": 10
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "target_overrides": {
 | 
					    "target_overrides": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,7 +36,6 @@ extern "C" {
 | 
				
			||||||
#define MBED_CPU_STATS_ENABLED      1
 | 
					#define MBED_CPU_STATS_ENABLED      1
 | 
				
			||||||
#define MBED_HEAP_STATS_ENABLED     1
 | 
					#define MBED_HEAP_STATS_ENABLED     1
 | 
				
			||||||
#define MBED_THREAD_STATS_ENABLED   1
 | 
					#define MBED_THREAD_STATS_ENABLED   1
 | 
				
			||||||
#define MBED_NW_STATS_ENABLED       1
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Maximum memory regions reported by mbed-os memory statistics */
 | 
					/** Maximum memory regions reported by mbed-os memory statistics */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,7 @@
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "target_overrides": {
 | 
					    "target_overrides": {
 | 
				
			||||||
        "*": {
 | 
					        "*": {
 | 
				
			||||||
 | 
					            "nsapi.socket-stats-enable": true,
 | 
				
			||||||
            "target.network-default-interface-type": "ETHERNET"
 | 
					            "target.network-default-interface-type": "ETHERNET"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,7 @@
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "target_overrides": {
 | 
					    "target_overrides": {
 | 
				
			||||||
        "*": {
 | 
					        "*": {
 | 
				
			||||||
 | 
					            "nsapi.socket-stats-enable": true,
 | 
				
			||||||
            "target.network-default-interface-type": "ETHERNET"
 | 
					            "target.network-default-interface-type": "ETHERNET"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue