[cairo] graph plotting using cairo

Milan Stanojević milanst at gmail.com
Fri Aug 10 09:45:57 PDT 2007


Hi, I've been working on a real-time graph plotting application that
uses Cairo through OCaml bindings.
I basically have a stream of data that comes in at the rate of 100
values a second, maybe a bit more. I collect the data and then plot it
on a cairo surface periodically.
I went through archives and googled a lot and I was able to optimize
code a lot. For example, I save the last surface drawn, shift it a bit
next time and just plot new points. I draw on Gtk DrawArea widget and
I use surface_create_similar to create surfaces. I tried image
surfaces as well, but that was much slower, which makes me suspect
that cairo is probably going through xrender when drawing onto gtk
widget.

The problem arises when the whole graph has to be redrawn, for example
on window resize. Then I have to plot all the points that are visible
(on the order of 10k points) which takes a bit. I've also noticed that
text drawing is taking a lot of time (when drawing plot axis).
That stuff I can even ignore, although I would appreciate if someone
could give me any advice how to make it faster.

What worries is more is CPU load. Anything more frequent than 10
frames a second basically hogs my CPU. The application itself is not
consuming a lot of CPU, but Xorg is. With 10frames a second, it goes
to over 80%. I measured time needed to draw a frame, and it is around
0.25ms when everything can be optimized, and going all the way to
200ms when everything needs to be redrawn. Even when window is static,
with frame draw time of 0.25ms, Xorg is still using 80% of the CPU.
I want to have a few graphs on the screen at the same time, which is
impossible with this kind of CPU load.

Has anyone have any idea why this is the case? Or how to optimize more
or fix the stuff? I was thinking of trying to use glitz backend, maybe
that will help, although I think that some hardware acceleration is in
place even now (as I said, using image surfaces is much, much slower).
The machine I am using is 2.4GHz Pentium 4 with ATI Radeon graphics
card with Fedora Linux.

Thanks a lot,
     Milan


More information about the cairo mailing list