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 <mrsam@courier-mta.com>
This commit is contained in:
parent
59e271e15b
commit
f9f4b00aad
29
src/xcb.h
29
src/xcb.h
|
@ -599,6 +599,35 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *display, xcb
|
||||||
uint32_t xcb_generate_id(xcb_connection_t *c);
|
uint32_t xcb_generate_id(xcb_connection_t *c);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Obtain number of bytes read from the connection.
|
||||||
|
* @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 *c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @brief Obtain number of bytes written to the connection.
|
||||||
|
* @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 *c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -287,6 +287,7 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->out.total_written += n;
|
||||||
for(; *count; --*count, ++*vector)
|
for(; *count; --*count, ++*vector)
|
||||||
{
|
{
|
||||||
int cur = (*vector)->iov_len;
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -1025,6 +1025,7 @@ int _xcb_in_read(xcb_connection_t *c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
c->in.total_read += n;
|
||||||
c->in.queue_len += n;
|
c->in.queue_len += n;
|
||||||
}
|
}
|
||||||
while(read_packet(c))
|
while(read_packet(c))
|
||||||
|
|
|
@ -103,6 +103,7 @@ typedef struct _xcb_out {
|
||||||
|
|
||||||
uint64_t request;
|
uint64_t request;
|
||||||
uint64_t request_written;
|
uint64_t request_written;
|
||||||
|
uint64_t total_written;
|
||||||
|
|
||||||
pthread_mutex_t reqlenlock;
|
pthread_mutex_t reqlenlock;
|
||||||
enum lazy_reply_tag maximum_request_length_tag;
|
enum lazy_reply_tag maximum_request_length_tag;
|
||||||
|
@ -135,6 +136,7 @@ typedef struct _xcb_in {
|
||||||
uint64_t request_expected;
|
uint64_t request_expected;
|
||||||
uint64_t request_read;
|
uint64_t request_read;
|
||||||
uint64_t request_completed;
|
uint64_t request_completed;
|
||||||
|
uint64_t total_read;
|
||||||
struct reply_list *current_reply;
|
struct reply_list *current_reply;
|
||||||
struct reply_list **current_reply_tail;
|
struct reply_list **current_reply_tail;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue