添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Visit Stack Exchange

Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.

Sign up to join this community

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to build an application that can measure the latency/processing time of graphics frameworks on Linux. My idea is to implement simple programs that react to an input event (e.g. mouse click) by changing the screen's color (e.g. from black to white) with different graphics and UI frameworks (e.g. SDL, OpenGL, Qt, ...). To measure each program's latency, I want to implement a separate program that measures the time from an input event arriving at the machine (I'm using evdev for this) to a pixel being updated in some kind of framebuffer (as close to the application as possible). The second program should also be independent of vblank events, as I'm interested in the time the rendering is done, not the time users might be able to see something.

My problem is getting the framebuffer content with the second program. I already managed to get framebuffer content with fbdev or libdrm (based on this tutorial ), but both require the programs to be run in a terminal without an active XServer (which I would prefer due to external validity). I have also already tried to use MIT-XShm to retrieve the X framebuffer's content, but it seems too slow for my problem, even when reading only one pixel (around 4 milliseconds with harsh outliers).

This is how I currently use XShm, in case it might help.

// get one pixel at coordinates x/y with XShm
XShmGetImage(display, rootWindow, image, x, y, 0x00ffffff);
// store red value into variable
unsigned int color = image->data[2];
if(color != lastcolor)
    log(time_micros(), color);

Is there a quick and reliable way to retrieve framebuffer content (either from X or from DRM) with an XServer running? Or is XShm the best we can do at the moment?

problem is: if you're doing e.g. Qt with an OpenGL backend, reading a pixel might have significantly more latency than just painting it, as that painting might already be happening on the GPU; also, we can safely expect that latency to be, on expectation, lower than the update rate of your screen, so this might be a bit of a meaningless measurement.. Could you elaborate what the purpose of that measurement would be. – Marcus Müller Nov 10, 2021 at 0:23 The measuring program is part of a research project. We want to measure all parts of the end-to-end latency (click to photon) individually. We already did input devices and displays - graphics frameworks are the last piece of the puzzle. End result should be a model for end-to-end latency, as well as a comparison of different frameworks in different situation. The latency model is the reason I don't care about vblank in this case - this time does not belong to the framework and can be handled individually (and yes, rendering is much faster than vblank). – Andreas Schmid Nov 10, 2021 at 8:26 interesting research! You probably know way more about GUI drawing architectures than I do, but: I bet it's easier to gain accurate measurements when you add a hook to a compositing window manager (e.g. mutter for Gnome, KWin in KDE) than to try to pry this out of X's hands again as the same client. XComp(osite) is what helps you here: drawing is usually (these days) done in off-screen "window" buffers, and that then is sent to the graphics card as texture for a surface. Things get really complicated when things happen partially on the GPU, though. – Marcus Müller Nov 10, 2021 at 9:34