/* * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /* Compile with: * cc -o synccounter synccounter.c `pkg-config --libs xcb xcb-sync xcb-event` */ #include #include #include #include #include #include #include #include /* Convert an xcb_sync_int64_t to a plain int64_t */ static inline int64_t extract_int64(xcb_sync_int64_t *xsint64) { return (((int64_t) xsint64->hi) << 32) | xsint64->lo; } static void handle_xcb_error(xcb_connection_t *xconn, xcb_generic_error_t *error) { const char *error_label = xcb_event_get_error_label(error->error_code); if (error_label) fprintf(stderr, "ERROR! %s\n", error_label); else fprintf(stderr, "ERROR! Unknown error (%d)\n", error->error_code); xcb_disconnect(xconn); exit(1); } int main (int argc, char **argv) { xcb_connection_t *xconn = xcb_connect(NULL, NULL); const xcb_query_extension_reply_t *sync_query; xcb_sync_initialize_cookie_t sync_init_cookie; xcb_sync_list_system_counters_cookie_t list_cookie; xcb_sync_list_system_counters_reply_t *list_reply; xcb_sync_systemcounter_iterator_t iter; xcb_generic_error_t *error; if ((xconn == NULL) || xcb_connection_has_error(xconn)) { const char *display_name = getenv("DISPLAY"); fprintf(stderr, "unable to open display \"%s\"", display_name ? display_name : ""); exit(1); } sync_query = xcb_get_extension_data (xconn, &xcb_sync_id); if (!sync_query->present) { fputs("Error: X server does not support sync extension.\n", stderr); exit(1); } sync_init_cookie = xcb_sync_initialize(xconn, XCB_SYNC_MAJOR_VERSION, XCB_SYNC_MINOR_VERSION); list_cookie = xcb_sync_list_system_counters(xconn); list_reply = xcb_sync_list_system_counters_reply(xconn, list_cookie, &error); if (list_reply == NULL) { handle_xcb_error(xconn, error); } iter = xcb_sync_list_system_counters_counters_iterator(list_reply); for (iter = xcb_sync_list_system_counters_counters_iterator(list_reply) ; iter.rem ; xcb_sync_systemcounter_next(&iter)) { printf("%"PRIx32": %.*s (resolution: %"PRId64")\n", iter.data->counter, iter.data->name_len, xcb_sync_systemcounter_name(iter.data), extract_int64(&iter.data->resolution)); /* Extra info for debugging: */ printf(" Actual name: %.*s\n", iter.data->name_len, ( (char *) &iter.data->name_len) + 2); } printf ("sizeof(xcb_sync_systemcounter_t) = %d\n", sizeof(xcb_sync_systemcounter_t)); xcb_disconnect (xconn); exit(0); }