XCreatePixmapCursor stats a lot of files...

BJörn Lindqvist bjourne at gmail.com
Sun Sep 30 19:53:22 PDT 2007


Hello all,

While stracing a program, I found that XCreatePixmapCursor() has some
very surprising behavior. Here is a sample program:

#include <X11/Xlib.h>
int
main (int   argc,
      char *argv[])
{
    Display *display = XOpenDisplay (NULL);
    Window root = XDefaultRootWindow (display);
    int depth = DefaultDepth (display, 0);
    char data[] = {0x00};
    Pixmap pix = XCreateBitmapFromData (display, root, data, 1, 1);
    XColor col;
    XCreatePixmapCursor (display, pix, pix, &col, &col, 4, 4);
}

Stracing this program with strace ./test, shows that
XCreatePixmapCursor() tries to open about 100 files. Here is a part of
the strace log showing some of the files that XCreatePixmapCursor()
accesses:

$ strace ./test 2>&1 | grep "usr/share" | sort
...
open("/usr/share/pixmaps/gnome/index.theme", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/share/pixmaps/gnome/index.theme", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/share/pixmaps/gnome/index.theme", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/share/pixmaps/gnome/index.theme", O_RDONLY) = -1 ENOENT (No
such file or directory)
open("/usr/share/pixmaps/Human/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Human/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Tangerine/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Tangerine/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Tango/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Tango/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Tango/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/pixmaps/Tango/cursors/00000000000000000000000000000000",
O_RDONLY) = -1 ENOENT (No such file or directory)
...

And so on, for many more themes and many more directories and many
more files. Why does it do this? The documentaton doesn't explain this
fairly odd behaviour. Why does it try to open the exact same file 8 or
more times?

Plus, this file-opening-business isn't cheap either. The single
XCreatePixmapCursor() call increases cold startup time with 200 ms on
my system.


-- 
mvh Björn



More information about the xorg mailing list