monitor: Fix median packet size
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 6 Aug 2021 20:33:01 +0000 (13:33 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:36 +0000 (19:08 +0530)
Calculating the median packet based on the current median + size / 2
does not account for last packet could smaller e.g. opp transfer could
end with just 1 byte which would cut the median in a half, so this
switch to more traditional means of calculating by doing total bytes
sent / num of packets so each an every packet has the same weight.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/analyze.c

index 839c2f7..5e0957a 100755 (executable)
@@ -61,6 +61,7 @@ struct hci_conn {
        unsigned long rx_num;
        unsigned long tx_num;
        unsigned long tx_num_comp;
+       size_t tx_bytes;
        struct timeval last_tx;
        struct timeval last_tx_comp;
        struct timeval tx_lat_min;
@@ -99,6 +100,8 @@ static void conn_destroy(void *data)
                break;
        }
 
+       conn->tx_pkt_med = conn->tx_bytes / conn->tx_num;
+
        printf("  Found %s connection with handle %u\n", str, conn->handle);
        printf("    BD_ADDR %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
                        conn->bdaddr[5], conn->bdaddr[4], conn->bdaddr[3],
@@ -485,16 +488,12 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out,
        if (out) {
                conn->tx_num++;
                conn->last_tx = *tv;
+               conn->tx_bytes += size;
 
                if (!conn->tx_pkt_min || size < conn->tx_pkt_min)
                        conn->tx_pkt_min = size;
                if (!conn->tx_pkt_max || size > conn->tx_pkt_max)
                        conn->tx_pkt_max = size;
-               if (conn->tx_pkt_med) {
-                       conn->tx_pkt_med += (size + 1);
-                       conn->tx_pkt_med /= 2;
-               } else
-                       conn->tx_pkt_med = size;
        } else {
                conn->rx_num++;
        }