Hi All
One of my colleagues has recently been using PowerTop to look at
processes running on his machine to see which ones are generating
‘wakeups’ (which stop the processor idling in low power mode):
Saving power with Linux on Intel hardware
One offender on his machine was a Ruby/Gtk program written by me. To
help isolate the problem, I created this test program:
=================================================================
#!/usr/bin/ruby
require ‘gtk2’
Gtk.init
window = Gtk::Window.new( Gtk::TOPLEVEL )
window.signal_connect(‘destroy’) { Gtk.main_quit }
b1 = Gtk::Button.new(‘Exit’)
b1.signal_connect(‘clicked’) { Gtk.main_quit }
window.add(b1)
window.show_all
Gtk.main
The program displays a button and when the button is pressed the program
exits. I expected that after window initialisation, the process would
essentially be idle. Instead, strace (on Ubuntu Linux) showed me that
it was looping through these system calls:
12:31:46 select(4, [3], [], [], {0, 0}) = 0 (Timeout)
12:31:46 ioctl(3, FIONREAD, [0]) = 0
12:31:46 gettimeofday({1190939506, 358}, NULL) = 0
The loop repeats about 20 times per second, so it is only using a tiny
amount of CPU - I’m just surprised that it’s using any.
By contract, I implemented the same program in Perl:
=================================================================
#!/usr/bin/perl -w
use strict;
use Gtk2 -init;
my $window = Gtk2::Window->new;
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
my $b1 = Gtk2::Button->new(‘Exit’);
$b1->signal_connect(clicked => sub { Gtk2->main_quit; });
$window->add($b1);
$window->show_all;
Gtk2->main;
After window initialisation, strace showed that this program sat quietly
in a poll:
12:35:28 poll(
As long as I didn’t generate events via the keyboard or mouse etc, the
process was completely idle.
I was surprised by the difference in behaviour between the two language
bindings. Does anyone have an explanation?
Regards
Grant