From f9f4b00aad69ff36e81c63089b1b16660eaca900 Mon Sep 17 00:00:00 2001 From: Sam Varshavchik Date: Sat, 4 Jan 2020 10:43:59 -0500 Subject: Implement xcb_total_read() and xcb_total_written(). Returns raw byte counts that have been read or written to the xcb_connection_t. I found it very useful when developing a high level widget toolkit, to track down inefficient/sub-optimum code that generates a lot of X protocol traffic. Signed-off-by: Sam Varshavchik --- src/xcb_conn.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/xcb_conn.c') diff --git a/src/xcb_conn.c b/src/xcb_conn.c index 7d09637..8dab658 100644 --- a/src/xcb_conn.c +++ b/src/xcb_conn.c @@ -287,6 +287,7 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count) return 0; } + c->out.total_written += n; for(; *count; --*count, ++*vector) { int cur = (*vector)->iov_len; @@ -528,3 +529,30 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec 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; +} -- cgit v1.2.3