monitor: Use gnuplot to plot graph of Latency-Packets
Luiz Augusto von Dentz
maintainerPATCH v4 1/3 monitor: Use gnuplot to plot graph of Latency-Packets
From: Luiz Augusto von Dentz <[email protected]>
This make use of gnuplot when using -a/--analyze to plot a graph of Latency-Packets:
Found BR-ACL connection with handle 256
Address: XX:XX:XX:XX:XX:XX (Sony Home Entertainment&Sound Products Inc) 60 RX packets
22548 TX packets
22547 TX completed packets
3 msec min latency
73 msec max latency
11 msec median latency
6 octets TX min packet size
850 octets TX max packet size
847 octets TX median packet size
10000 +------------------------------------------------------------------+
|+ + |
|+ |+ Packets +-----+ |
|+ || |
1000 |-+ +||++ |
|+ |||||+ + |
|+ ||||||+| |
|+ ||||||||+ |
|+ |||||||||+++ |
100 |-+ |||||||||||++++ |
|+ ||||||||||||||| + |
|+ ||||||||||||||| ++ |
|+ + |||||||||||||||+|| |
10 |-+| ||||||||||||||||||+++ |
|+ | ||||||||||||||||||||| |
|+ | ||||||||||||||||||||| + |
|+ | ++|||||||||||||||||||||++|++++ + |
| | |||||||||||||||||||||||||||||| | |
1 |-+|+|||||||||||||||||||||||||||||| + + | + + + |
+------------------------------------------------------------------+
0 10 20 30 40 50 60 70 80
Latency (ms)
---
monitor/analyze.c | 98 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 87 insertions(+), 11 deletions(-)monitor/analyze.c +87 -11
@@ -17,6 +17,7 @@#include <stdio.h> #include <string.h> #include <sys/time.h> +#include <unistd.h> #include "lib/bluetooth.h"
@@ -28,6 +29,9 @@#include "monitor/packet.h" #include "monitor/analyze.h" +#define TIMEVAL_MSEC (_tv) \ + (long long)((_tv)->tv_sec * 1000 + (_tv)->tv_usec / 1000) +struct hci_dev {uint16_t index;uint8_t type;
@@ -69,12 +73,18 @@ struct hci_conn {struct timeval tx_lat_min;struct timeval tx_lat_max;struct timeval tx_lat_med; +struct queue *plot;uint16_t tx_pkt_min;uint16_t tx_pkt_max;uint16_t tx_pkt_med;struct queue *chan_list; }; +struct plot { +long long x_msec; +size_t y_count; +}; +struct l2cap_chan {uint16_t cid;uint16_t psm;
@@ -135,6 +145,47 @@ static struct l2cap_chan *chan_lookup(struct hci_conn *conn, uint16_t cid,return chan; } +static void tmp_write (void *data,void *user_data) +{ +struct plot *plot = data; +FILE *tmp = user_data; + +fprintf (tmp,"%lld %zu\n" , plot->x_msec, plot->y_count); +} + +static void plot_draw (struct queue *queue) +{ +const char *filename ="analyze.tmp" ; +FILE *gplot =popen ("gnuplot" ,"w" ); +FILE *tmp; + +if (!gplot) +return ; + +if (queue_isempty (queue)) + goto done; + + tmp =fopen (filename,"w" ); +if (!tmp) + goto done; + +queue_foreach (queue, tmp_write, tmp); + +fprintf (gplot,"set terminal dumb enhanced ansi\n" ); +fprintf (gplot,"set xlabel 'Latency (ms)'\n" ); +fprintf (gplot,"set tics nomirror\n" ); +fprintf (gplot,"set log y\n" ); +fprintf (gplot,"set yrange [0.5:*]\n" ); +fprintf (gplot,"plot './%s' using 1:2 t 'Packets' w impulses\n" , + filename); +fflush (gplot); + +fclose (tmp); +done: +pclose (gplot); +unlink (filename); +} +static void conn_destroy (void *data) {struct hci_conn *conn = data;
@@ -172,21 +223,17 @@ static void conn_destroy(void *data)print_field ("%lu RX packets" , conn->rx_num);print_field ("%lu TX packets" , conn->tx_num);print_field ("%lu TX completed packets" , conn->tx_num_comp); -print_field ("%lld msec min latency" , - (long long ) - (conn->tx_lat_min.tv_sec *1000 + - conn->tx_lat_min.tv_usec /1000 )); -print_field ("%lld msec max latency" , - (long long ) - (conn->tx_lat_max.tv_sec *1000 + - conn->tx_lat_max.tv_usec /1000 )); +print_field ("%lld msec min latency" ,TIMEVAL_MSEC (&conn->tx_lat_min)); +print_field ("%lld msec max latency" ,TIMEVAL_MSEC (&conn->tx_lat_max));print_field ("%lld msec median latency" , - (long long ) - (conn->tx_lat_med.tv_sec *1000 + - conn->tx_lat_med.tv_usec /1000 )); +TIMEVAL_MSEC (&conn->tx_lat_med));print_field ("%u octets TX min packet size" , conn->tx_pkt_min);print_field ("%u octets TX max packet size" , conn->tx_pkt_max);print_field ("%u octets TX median packet size" , conn->tx_pkt_med); + +plot_draw (conn->plot); + +queue_destroy (conn->plot, free);queue_destroy (conn->chan_list, chan_destroy);queue_destroy (conn->tx_queue, free);
@@ -203,6 +250,7 @@ static struct hci_conn *conn_alloc(struct hci_dev *dev, uint16_t handle, conn->handle = handle; conn->type = type; conn->tx_queue =queue_new (); + conn->plot =queue_new (); conn->chan_list =queue_new ();
@@ -447,6 +495,32 @@ static void evt_cmd_complete(struct hci_dev *dev, struct timeval *tv, } } +static bool match_plot_latency (const void *data,const void *user_data) +{ +const struct plot *plot = data; +const struct timeval *latency = user_data; + +return TIMEVAL_MSEC (latency) == plot->x_msec; +} + +static void plot_add (struct queue *queue,struct timeval *latency, +uint16_t count) +{ +struct plot *plot; + + plot =queue_find (queue, match_plot_latency, latency); +if (plot) { + plot->y_count += count; +return ; + } + + plot = new0(struct plot, 1); + plot->x_msec =TIMEVAL_MSEC (latency); + plot->y_count = count; + +queue_push_tail (queue, plot); +} +static void evt_num_completed_packets (struct hci_dev *dev,struct timeval *tv,const void *data,uint16_t size) {
@@ -504,6 +578,8 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, }else conn->tx_lat_med = res; +plot_add (conn->plot, &res, count); +free (last_tx); } }
Signature · 1 line
2.41.0
Luiz Augusto von Dentz
maintainerPATCH v4 2/3 monitor: Update documentation
From: Luiz Augusto von Dentz <[email protected]>
This updates the documentation to mention gnuplot usage.
--- monitor/btmon.rst | 4 +++- monitor/main.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-)
monitor/btmon.rst +3 -1
@@ -33,7 +33,9 @@ OPTIONS -w FILE, --write FILE Save traces in btsnoop format to *FILE*. -a FILE, --analyze FILE Analyze traces in btsnoop format from *FILE*. It displays the devices found in the *FILE* with - its packets by type. + its packets by type. If gnuplot is installed on + the system it also attempts to plot packet latency + graph. -s SOCKET, --server SOCKET Start monitor server socket. -p PRIORITY, --priority PRIORITY Show only priority or lower for user log.
monitor/main.c +3 -0
@@ -51,6 +51,9 @@ static void usage(void)"\t-r, --read <file> Read traces in btsnoop format\n" "\t-w, --write <file> Save traces in btsnoop format\n" "\t-a, --analyze <file> Analyze traces in btsnoop format\n" +"\t If gnuplot is installed on the\n" +"\t system it will also attempt to plot\n" +"\t packet latency graph.\n" "\t-s, --server <socket> Start monitor server socket\n" "\t-p, --priority <level> Show only priority or lower\n" "\t-i, --index <num> Show only specified controller\n"
Signature · 1 line
2.41.0
Luiz Augusto von Dentz
maintainerPATCH v4 3/3 monitor: Consolidate code around latency calculation
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This move latency calculations to a helper function called packet_latency_add so it can get reused by the likes of l2cap.c and analyze.c
--- monitor/analyze.c | 44 ++++++----------------------------- monitor/l2cap.c | 36 ++++------------------------- monitor/packet.c | 59 +++++++++++++++++++++++++---------------------- monitor/packet.h | 12 +++++++--- 4 files changed, 51 insertions(+), 100 deletions(-)
monitor/analyze.c +7 -37
@@ -70,9 +70,7 @@ struct hci_conn {unsigned long tx_num_comp;size_t tx_bytes;struct queue *tx_queue; -struct timeval tx_lat_min; -struct timeval tx_lat_max; -struct timeval tx_lat_med; +struct packet_latency tx_l;struct queue *plot;uint16_t tx_pkt_min;uint16_t tx_pkt_max;
@@ -223,13 +221,11 @@ static void conn_destroy(void *data)print_field ("%lu RX packets" , conn->rx_num);print_field ("%lu TX packets" , conn->tx_num);print_field ("%lu TX completed packets" , conn->tx_num_comp); -print_field ("%lld msec min latency" ,TIMEVAL_MSEC (&conn->tx_lat_min)); -print_field ("%lld msec max latency" ,TIMEVAL_MSEC (&conn->tx_lat_max)); -print_field ("%lld msec median latency" , -TIMEVAL_MSEC (&conn->tx_lat_med)); -print_field ("%u octets TX min packet size" , conn->tx_pkt_min); -print_field ("%u octets TX max packet size" , conn->tx_pkt_max); -print_field ("%u octets TX median packet size" , conn->tx_pkt_med); +print_field ("%lld-%lld msec (~%lld msec) TX Latency" , +TV_MSEC (conn->tx_l.min),TV_MSEC (conn->tx_l.max), +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);plot_draw (conn->plot);
@@ -550,33 +546,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv,if (last_tx) {timersub (tv, last_tx, &res); -if ((!timerisset (&conn->tx_lat_min) || - timercmp(&res, &conn->tx_lat_min, <)) && - res.tv_sec >=0 && res.tv_usec >=0 ) - conn->tx_lat_min = res; - -if (!timerisset (&conn->tx_lat_max) || - timercmp(&res, &conn->tx_lat_max, >)) - conn->tx_lat_max = res; - -if (timerisset (&conn->tx_lat_med)) { -struct timeval tmp; - -timeradd (&conn->tx_lat_med, &res, &tmp); - - tmp.tv_sec /=2 ; - tmp.tv_usec /=2 ; -if (tmp.tv_sec %2 ) { - tmp.tv_usec +=500000 ; -if (tmp.tv_usec >=1000000 ) { - tmp.tv_sec++; - tmp.tv_usec -=1000000 ; - } - } - - conn->tx_lat_med = tmp; - }else - conn->tx_lat_med = res; +packet_latency_add (&conn->tx_l, &res);plot_add (conn->plot, &res, count);
monitor/l2cap.c +4 -32
@@ -100,9 +100,7 @@ struct chan_data {uint8_t ext_ctrl;uint8_t seq_num;uint16_t sdu; -struct timeval tx_min; -struct timeval tx_max; -struct timeval tx_med; +struct packet_latency tx_l; };static struct chan_data chan_list[MAX_CHAN ];
@@ -2798,8 +2796,6 @@ void l2cap_packet(uint16_t index, bool in, uint16_t handle, uint8_t flags, } } -#define TV_MSEC (_tv) (long long)((_tv)->tv_sec * 1000 + (_tv)->tv_usec / 1000) -void l2cap_dequeue_frame (struct timeval *delta,struct packet_conn_data *conn) {struct l2cap_frame *frame;
@@ -2813,39 +2809,15 @@ void l2cap_dequeue_frame(struct timeval *delta, struct packet_conn_data *conn)if (!chan)return ; - if ((!timerisset(&chan->tx_min) || timercmp(delta, &chan->tx_min, <)) - && delta->tv_sec >=0 && delta->tv_usec >=0 ) - chan->tx_min = *delta; - - if (!timerisset(&chan->tx_max) || timercmp(delta, &chan->tx_max, >)) - chan->tx_max = *delta; - -if (timerisset (&chan->tx_med)) { -struct timeval tmp; - -timeradd (&chan->tx_med, delta, &tmp); - - tmp.tv_sec /=2 ; - tmp.tv_usec /=2 ; -if (tmp.tv_sec %2 ) { - tmp.tv_usec +=500000 ; -if (tmp.tv_usec >=1000000 ) { - tmp.tv_sec++; - tmp.tv_usec -=1000000 ; - } - } - - chan->tx_med = tmp; - }else - chan->tx_med = *delta; +packet_latency_add (&chan->tx_l, delta);print_field ("Channel: %d [PSM %d mode %s (0x%02x)] {chan %d}" , frame->cid, frame->psm,mode2str (frame->mode), frame->mode, frame->chan);print_field ("Channel Latency: %lld msec (%lld-%lld msec ~%lld msec)" , -TV_MSEC (delta),TV_MSEC (&chan->tx_min), -TV_MSEC (&chan->tx_max),TV_MSEC (&chan->tx_med)); +TV_MSEC (*delta),TV_MSEC (chan->tx_l.min), +TV_MSEC (chan->tx_l.max),TV_MSEC (chan->tx_l.med));free (frame); }
monitor/packet.c +31 -28
73 lines not on this page · raw message
monitor/packet.h +9 -3
@@ -23,6 +23,13 @@#define PACKET_FILTER_SHOW_A2DP_STREAM (1 << 6)#define PACKET_FILTER_SHOW_MGMT_SOCKET (1 << 7)#define PACKET_FILTER_SHOW_ISO_DATA (1 << 8) +#define TV_MSEC (_tv) (long long)((_tv).tv_sec * 1000 + (_tv).tv_usec / 1000) + +struct packet_latency { +struct timeval min; +struct timeval max; +struct timeval med; +};struct packet_conn_data {uint16_t index;
@@ -33,14 +40,13 @@ struct packet_conn_data {uint8_t dst_type;struct queue *tx_q;struct queue *chan_q; -struct timeval tx_min; -struct timeval tx_max; -struct timeval tx_med; +struct packet_latency tx_l;void *data;void (*destroy)(void *data); };struct packet_conn_data *packet_get_conn_data (uint16_t handle); +void packet_latency_add (struct packet_latency *latency,struct timeval *delta);bool packet_has_filter (unsigned long filter);void packet_set_filter (unsigned long filter);
Signature · 1 line
2.41.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=770670
---Test result---
Test Summary:
CheckPatch FAIL 1.87 seconds GitLint PASS 1.07 seconds BuildEll PASS 27.21 seconds BluezMake PASS 781.31 seconds MakeCheck PASS 11.40 seconds MakeDistcheck PASS 157.38 seconds CheckValgrind PASS 251.09 seconds CheckSmatch WARNING 339.62 seconds bluezmakeextell PASS 102.83 seconds IncrementalBuild PASS 1976.07 seconds ScanBuild WARNING 1026.41 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v4,1/3] monitor: Use gnuplot to plot graph of Latency-Packets WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #86:
Address: XX:XX:XX:XX:XX:XX (Sony Home Entertainment&Sound Products Inc)
/github/workspace/src/src/13332241.patch total: 0 errors, 1 warnings, 156 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/src/13332241.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[BlueZ,v4,2/3] monitor: Update documentation ERROR:CODE_INDENT: code indent should use tabs where possible #115: FILE: monitor/main.c:55:
+ "\t system it will also attempt to plot\n"$
WARNING:LEADING_SPACE: please, no spaces at the start of a line #115: FILE: monitor/main.c:55:
+ "\t system it will also attempt to plot\n"$
/github/workspace/src/src/13332242.patch total: 1 errors, 1 warnings, 19 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
NOTE: Whitespace errors detected.
You may wish to use scripts/cleanpatch or scripts/cleanfile
/github/workspace/src/src/13332242.patch has style problems, please review.
NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:monitor/l2cap.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1832:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3551:52: warning: array of flexible structuresmonitor/bt.h:3539:40: warning: array of flexible structures
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:monitor/l2cap.c:1638:4: warning: Value stored to 'data' is never read
data += len;
^ ~~~
monitor/l2cap.c:1639:4: warning: Value stored to 'size' is never read
size -= len;
^ ~~~
2 warnings generated.
monitor/packet.c:12373:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull'
memcpy(tx, tv, sizeof(*tv));
^~~~~~~~~~~~~~~~~~~~~~~~~~~1 warning generated.
---
Regards,
Linux Bluetooth