On a system with 30 extensions listed by xdpyinfo, truss -c
reports this saves quite a few system calls by batching the
QueryExtension requests instead of a round-trip for each one:

                       Xlib     xcb
writev                  40       11
poll                    80       22
recv                   117       29
total (*)              464      296

(*) total includes all system calls, including many not shown since
their count did not change significantly.   There was one additional
set of open/mmap/close/etc. for loading the added libX11-xcb library.

Signed-off-by: Alan Coopersmith <alan.coopersm...@oracle.com>
---

This was also written with the intent of serving as an example of
incremental migration from Xlib to xcb, so please suggest if there's
anything that should be improved for people who may model their own
code on it.

 configure.ac |    2 +-
 xdpyinfo.c   |   41 +++++++++++++++++++++++++++++------------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index 48ae434..47a1246 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,7 @@ XORG_DEFAULT_OPTIONS
 AM_CONFIG_HEADER(config.h)
 
 # Checks for pkg-config packages
-PKG_CHECK_MODULES(XDPYINFO, xext x11 xtst)
+PKG_CHECK_MODULES(XDPYINFO, xext x11 xtst x11-xcb xcb)
 
 # This is used below to allow <X11/Xlib.h> to be found
 PKG_CHECK_MODULES(DPY_X11, x11)
diff --git a/xdpyinfo.c b/xdpyinfo.c
index db4a438..bd0b0f6 100644
--- a/xdpyinfo.c
+++ b/xdpyinfo.c
@@ -82,6 +82,7 @@ in this Software without prior written authorization from The 
Open Group.
 
 #endif
 
+#include <X11/Xlib-xcb.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #ifdef MULTIBUFFER
@@ -170,22 +171,38 @@ print_extension_info(Display *dpy)
     printf ("number of extensions:    %d\n", n);
 
     if (extlist) {
-       register int i;
-       int opcode, event, error;
+       int i;
 
        qsort(extlist, n, sizeof(char *), StrCmp);
-       for (i = 0; i < n; i++) {
-           if (!queryExtensions) {
+
+       if (!queryExtensions) {
+           for (i = 0; i < n; i++) {
                printf ("    %s\n", extlist[i]);
-               continue;
            }
-           XQueryExtension(dpy, extlist[i], &opcode, &event, &error);
-           printf ("    %s  (opcode: %d", extlist[i], opcode);
-           if (event)
-               printf (", base event: %d", event);
-           if (error)
-               printf (", base error: %d", error);
-           printf(")\n");
+       } else {
+           xcb_connection_t *xcb_conn = XGetXCBConnection (dpy);
+           xcb_query_extension_cookie_t qe_cookies[n];
+
+           for (i = 0; i < n; i++) {
+               qe_cookies[i] = xcb_query_extension (xcb_conn,
+                                                    strlen(extlist[i]),
+                                                    extlist[i]);
+           }
+           xcb_flush (xcb_conn);
+
+           for (i = 0; i < n; i++) {
+               xcb_query_extension_reply_t *rep
+                   = xcb_query_extension_reply(xcb_conn, qe_cookies[i], NULL);
+
+               printf ("    %s  (opcode: %d", extlist[i], rep->major_opcode);
+               if (rep->first_event)
+                   printf (", base event: %d", rep->first_event);
+               if (rep->first_error)
+                   printf (", base error: %d", rep->first_error);
+               printf(")\n");
+
+               free(rep);
+           }
        }
        /* do not free, Xlib can depend on contents being unaltered */
        /* XFreeExtensionList (extlist); */
-- 
1.5.6.5

_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to