LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2016, 09:48 AM   #1
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Rep: Reputation: 18
Cool GTK+-3.0 Performance Issue with Cairo usage or Widget Structure


I need another pair of GTK3 skilled eyes to help me find the drawing performance issue in my glinegraph-cairo project. It's a GtkWidget I extracted from 'GApcMon' back in 2007 and I wanted to upgrade it from Gtk2 to Gtk3. The upgrade process was painless and I think I've covered all the bases.

The issue I'm having is in the GtkWidget#draw, GtkWidget#configure-event callback routines. The line chart test program adds 5 data points every 5 seconds, and the chart should start plotting a line for each data point from left to right. The time it takes to draw those lines is where the performance issue surfaces. Should be no more than 300ms when 50+ data points are being drawn. Depending on the version of Gtk3 that number could be 15 seconds, or just immediately fail with a GdkWindow out-of-memory error.

I've tried two different strategies to render the draw function.
  1. The classic inline method of redrawing everything inside the 'draw' callback.
  2. Drawing to a side surface, and letting 'draw' paint the affected region.

I've tried using the GDK Cairo Surfaces, and a Image Cairo Surface. The GDK based surface produces the worst results, with the image surface being the most stable.

I suspect there is some coding step that I've missed involving cairo surfaces, maybe I need to mark them as dirty once their drawn on. Or maybe these is something wrong with my Object Widget Structure. Right now I'm very frustrated with GTK3.

Source for this question is here: glinegraph-cairo

Any insight or help is greatly appreciated.

I just don't see where the problem could be. I've researched several OS X related GTK issues and I'm sure OS X/Quartz's surface implementation is a part of the problem. However, OS X is just my development environment; Linux is my primary delivery platform and target. These issues are present on CentOS7, Ubuntu, and Raspbian across Gtk+-3.10 thru Gtk+3.18; so OS X issues can be ignored.

There are older GTK+2.0 versions of this widget using cairo methods and one using gdk drawing methods, located on source forge under either 'gapcmon' or 'glinegraph-cairo' and 'glinegraph-gtk', if that's helpful.

Last edited by skoona; 05-20-2016 at 09:52 AM.
 
Old 05-23-2016, 03:32 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Hi,

I'm far from skilled at GTK programming but I've dabbled with it.

On my machine it seems the bottle neck is drawing the dots on the graph - cairo_arc() .

Starting out, I changed the timeout duration to 500 ms. and plotting stopped after 21 data series were plotted. The program continues to run using 100% of one cpu core but puts nothing on the screen.

In contrast, after commenting out the following line, still with the 500 ms. timeout, the app has been scrolling across the screen for ~20 minutes using 3.3% of one cpu core.
Code:
$ grep -n cairo_arc glg_cairo.c
2108://          cairo_arc (priv->cr, point_pos[v_index].x , point_pos[v_index].y , 3.0, 0., 360 * M_PI);
Don't know enough about GTK to offer a solution, but hopefully this will point you in the right direction.

EDIT: Just occurred to me - "360 * M_PI"?

Last edited by norobro; 05-23-2016 at 04:01 PM.
 
Old 05-24-2016, 07:38 AM   #3
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Original Poster
Rep: Reputation: 18
norobro,

Thanks for the feedback. I had not discovered which statement was the the biggest time consumer. Plus I will have to take another look at "360 * M_PI", hehe.

I have tested on versions Gtk+-3.10.2, 3.16.6, and 3.18.9. Only 16.6 performed decently. Having one version be performant caused my to back off deep statement analysis and suspect GTK itself. I also noted that resizing the window to twice it's size helps stabilize the drawing results.

looking into "360 * M_PI" now; should likely of been "2 * M_PI"

James,
 
Old 05-24-2016, 10:06 AM   #4
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Original Poster
Rep: Reputation: 18
norobro,

M_PI was the root cause. I've now able to use the standard cairo surface from '#gdk_window_create_similar_surface()' as the offline surface for drawing, which performs satisfactory on all versions of GTK3. The typical performance of the 101 data point is averaging 15 milliseconds for the TOTAL draw routine. This is excellent! I'll update the repo with these changes.

a Big Thanks to you for spotting that. I think we are done here (unless you've spotted something else)

James,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Showing a widget above a widget in GTK aarontwc Programming 4 11-26-2008 11:40 AM
gnome + gtk + cairo keratos Ubuntu 0 05-18-2007 10:40 AM
GTK widget which to use? cranium2004 Programming 1 02-20-2006 01:29 PM
gtk+2.8 and cairo John Velman Slackware 3 10-19-2005 04:16 PM
what is a gtk-widget ? gladeiator Programming 3 10-30-2003 05:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration