monitor: Add TX frame number and speed estimation
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 31 Jul 2023 18:26:19 +0000 (11:26 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 13:34:03 +0000 (19:04 +0530)
This adds the frame information while decoding:

> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 256 Address: XX:XX:XX:XX:XX:XX
        Count: 1
        #188: len 850 (755 Kb/s)
        Latency: 9 msec (3-21 msec ~6 msec)
        Channel: 68 [PSM 25 mode Basic (0x00)] {chan 4}
        Channel Latency: 9 msec (7-21 msec ~9 msec)

Or the speed estimation while analyzing:

  Found BR-ACL connection with handle 256
        Address: XX:XX:XX:XX:XX:XX
        60 RX packets
        22548 TX packets
        22547 TX completed packets
        3-73 msec (~11 msec) TX Latency
        6-850 octets (~847 octets) TX packet size
        ~568 Kb/s TX transfer speed

monitor/analyze.c
monitor/packet.c
monitor/packet.h

index 96eed84..6a81854 100755 (executable)
@@ -228,6 +228,8 @@ static void conn_destroy(void *data)
                        TV_MSEC(conn->tx_l.med));
        print_field("%u-%u octets (~%u octets) TX packet size",
                        conn->tx_pkt_min, conn->tx_pkt_max, conn->tx_pkt_med);
+       print_field("~%lld Kb/s TX transfer speed",
+                       conn->tx_bytes * 8 / TV_MSEC(conn->tx_l.total));
 
        plot_draw(conn->plot);
 
index 551827d..9f8e192 100755 (executable)
@@ -10403,6 +10403,8 @@ static void role_change_evt(struct timeval *tv, uint16_t index,
 
 void packet_latency_add(struct packet_latency *latency, struct timeval *delta)
 {
+       timeradd(&latency->total, delta, &latency->total);
+
        if ((!timerisset(&latency->min) || timercmp(delta, &latency->min, <))
                                && delta->tv_sec >= 0 && delta->tv_usec >= 0)
                latency->min = *delta;
@@ -10433,28 +10435,30 @@ void packet_latency_add(struct packet_latency *latency, struct timeval *delta)
 static void packet_dequeue_tx(struct timeval *tv, uint16_t handle)
 {
        struct packet_conn_data *conn;
-       struct timeval *tx;
+       struct packet_frame *frame;
        struct timeval delta;
 
        conn = packet_get_conn_data(handle);
        if (!conn)
                return;
 
-       tx = queue_pop_head(conn->tx_q);
-       if (!tx)
+       frame = queue_pop_head(conn->tx_q);
+       if (!frame)
                return;
 
-       timersub(tv, tx, &delta);
+       timersub(tv, &frame->tv, &delta);
 
        packet_latency_add(&conn->tx_l, &delta);
 
+       print_field("#%zu: len %zu (%lld Kb/s)", frame->num, frame->len,
+                                       frame->len * 8 / TV_MSEC(delta));
        print_field("Latency: %lld msec (%lld-%lld msec ~%lld msec)",
                        TV_MSEC(delta), TV_MSEC(conn->tx_l.min),
                        TV_MSEC(conn->tx_l.max), TV_MSEC(conn->tx_l.med));
 
        l2cap_dequeue_frame(&delta, conn);
 
-       free(tx);
+       free(frame);
 }
 
 static void num_completed_packets_evt(struct timeval *tv, uint16_t index,
@@ -12448,10 +12452,11 @@ void packet_hci_event(struct timeval *tv, struct ucred *cred, uint16_t index,
        event_data->func(tv, index, data, hdr->plen);
 }
 
-static void packet_queue_tx(struct timeval *tv, uint16_t handle)
+static void packet_enqueue_tx(struct timeval *tv, uint16_t handle,
+                               size_t num, uint16_t len)
 {
        struct packet_conn_data *conn;
-       struct timeval *tx;
+       struct packet_frame *frame;
 
        conn = packet_get_conn_data(handle);
        if (!conn)
@@ -12460,9 +12465,12 @@ static void packet_queue_tx(struct timeval *tv, uint16_t handle)
        if (!conn->tx_q)
                conn->tx_q = queue_new();
 
-       tx = new0(struct timeval, 1);
-       memcpy(tx, tv, sizeof(*tv));
-       queue_push_tail(conn->tx_q, tx);
+       frame = new0(struct packet_frame, 1);
+       if (tv)
+               memcpy(&frame->tv, tv, sizeof(*tv));
+       frame->num = num;
+       frame->len = len;
+       queue_push_tail(conn->tx_q, frame);
 }
 
 void packet_hci_acldata(struct timeval *tv, struct ucred *cred, uint16_t index,
@@ -12503,7 +12511,8 @@ void packet_hci_acldata(struct timeval *tv, struct ucred *cred, uint16_t index,
                                                handle_str, extra_str);
 
        if (!in)
-               packet_queue_tx(tv, acl_handle(handle));
+               packet_enqueue_tx(tv, acl_handle(handle),
+                                       index_list[index].frame, dlen);
 
        if (size != dlen) {
                print_text(COLOR_ERROR, "invalid packet size (%d != %d)",
@@ -12550,7 +12559,8 @@ void packet_hci_scodata(struct timeval *tv, struct ucred *cred, uint16_t index,
                                                handle_str, extra_str);
 
        if (!in)
-               packet_queue_tx(tv, acl_handle(handle));
+               packet_enqueue_tx(tv, acl_handle(handle),
+                                       index_list[index].frame, hdr->dlen);
 
        if (size != hdr->dlen) {
                print_text(COLOR_ERROR, "invalid packet size (%d != %d)",
@@ -12600,7 +12610,8 @@ void packet_hci_isodata(struct timeval *tv, struct ucred *cred, uint16_t index,
                                                handle_str, extra_str);
 
        if (!in)
-               packet_queue_tx(tv, acl_handle(handle));
+               packet_enqueue_tx(tv, acl_handle(handle),
+                                       index_list[index].frame, hdr->dlen);
 
        if (size != hdr->dlen) {
                print_text(COLOR_ERROR, "invalid packet size (%d != %d)",
index 0faac62..45c63c9 100755 (executable)
 #define TV_MSEC(_tv) (long long)((_tv).tv_sec * 1000 + (_tv).tv_usec / 1000)
 
 struct packet_latency {
+       struct timeval total;
        struct timeval min;
        struct timeval max;
        struct timeval med;
 };
 
+struct packet_frame {
+       struct timeval tv;
+       size_t num;
+       size_t len;
+};
+
 struct packet_conn_data {
        uint16_t index;
        uint8_t  src[6];