[Xcb] Measuring total traffic over a connection

Sam Varshavchik mrsam at courier-mta.com
Wed Dec 4 04:12:26 UTC 2019


I would like to be able to keep an eye out on how many bytes are  
read/written over a connection. I need this for diagnostic reasons.

I threw something together after looking over the source, see below; I think  
this is what I need. I'll appreciate if someone would look it over and let  
me know if I'm on the right track, before I sink a little bit of time making  
a custom build of libxcb and installing it. I think this might be of some  
general usefulness, so I'm happy to share it:


--- src/xcb_conn.c.orig	2018-09-27 08:02:28.000000000 -0400
+++ src/xcb_conn.c	2019-12-03 23:07:27.947188219 -0500
@@ -287,6 +287,7 @@
         return 0;
     }

+    c->out.total_written += n;
     for(; *count; --*count, ++*vector)
     {
         int cur = (*vector)->iov_len;
@@ -528,3 +529,30 @@

     return ret;
 }
+
+uint64_t xcb_total_read(xcb_connection_t *c)
+{
+    uint64_t n;
+
+    if (xcb_connection_has_error(c))
+        return 0;
+
+    pthread_mutex_lock(&c->iolock);
+    n=c->in.total_read;
+    pthread_mutex_unlock(&c->iolock);
+    return n;
+}
+
+uint64_t xcb_total_written(xcb_connection_t *c)
+{
+    uint64_t n;
+
+    if (xcb_connection_has_error(c))
+        return 0;
+
+    pthread_mutex_lock(&c->iolock);
+    n=c->out.total_written;
+    pthread_mutex_unlock(&c->iolock);
+
+    return n;
+}
--- src/xcb_in.c.orig	2018-09-27 08:02:28.000000000 -0400
+++ src/xcb_in.c	2019-12-03 23:07:47.334860323 -0500
@@ -1025,6 +1025,7 @@
             }
         }
 #endif
+        c->in.total_read += n;
         c->in.queue_len += n;
     }
     while(read_packet(c))
--- src/xcbint.h.orig	2018-09-27 08:02:28.000000000 -0400
+++ src/xcbint.h	2019-12-03 23:07:27.954188100 -0500
@@ -103,6 +103,7 @@

     uint64_t request;
     uint64_t request_written;
+    uint64_t total_written;

     pthread_mutex_t reqlenlock;
     enum lazy_reply_tag maximum_request_length_tag;
@@ -135,6 +136,7 @@
     uint64_t request_expected;
     uint64_t request_read;
     uint64_t request_completed;
+    uint64_t total_read;
     struct reply_list *current_reply;
     struct reply_list **current_reply_tail;

--- src/xproto.h.orig	2019-12-03 23:06:00.984658993 -0500
+++ src/xproto.h	2019-12-03 23:07:27.955188083 -0500
@@ -12684,6 +12684,33 @@
 xcb_void_cookie_t
 xcb_no_operation (xcb_connection_t *c);

+/**
+ *
+ * @param c The connection
+ * @return Number of bytes read from the server.
+ *
+ * Returns cumulative number of bytes received from the connection.
+ *
+ * This retrieves the total number of bytes read from this connection,
+ * to be used for diagnostic/monitoring/informative purposes.
+ */
+
+uint64_t
+xcb_total_read(xcb_connection_t *);
+
+/**
+ *
+ * @param c The connection
+ * @return Number of bytes written to the server.
+ *
+ * Returns cumulative number of bytes sent to the connection.
+ *
+ * This retrieves the total number of bytes written to this connection,
+ * to be used for diagnostic/monitoring/informative purposes.
+ */
+
+uint64_t
+xcb_total_written(xcb_connection_t *);

 #ifdef __cplusplus
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20191203/e938314f/attachment.sig>


More information about the Xcb mailing list