CPU load increasing with IO watch



I have the following code using IO watch
open($file, "-|","$prog $inp1 $opts $newfile  2>&1" );
my $end_mark=$buffer->create_mark('end',$buffer->get_end_iter,0);
our $tag=  Glib::IO->add_watch ( fileno($file), ['in', 'hup'], sub {
         my ($fileno, $condition,$tag) = @_;
         if ($condition eq 'hup') {

                 close $file;
                 return 0;  # uninstall
         }


         my $line ;
         sysread $file, $line, 256;
my $start=$buffer->get_iter_at_line(25);
my $endline;
if ($buffer->get_line_count() >34){
$endline=$buffer->get_line_count()-10;
}
else {$endline=$buffer->get_line_count()};

my $end=$buffer->get_iter_at_line($endline);

$buffer->signal_connect(insert_text=>sub{
$textview->scroll_to_mark($end_mark,0.0,1,0.0,1.0);});
if ($endline >34){
        $buffer->delete($start,$end);
}
         $buffer->insert($buffer->get_end_iter, $line);
#$buffer->set_text($line);
sleep 10;


         return 1;

 }

);

The problem I have is that as the watch progresses CPU load for the
watch increases at the expense of external program being run.

(example cmd line is ffmpeg -async 12 -vd /dev/video -ad /dev/dsp -f
avi -r 25 -s 540x432 -croptop 8 -cropbottom 8 -cropleft 8 -cropright 8
-sameq -aspect 4:3 -acodec mp2 -ac 2 -ab 224k -ar 48000 -t 04:30:30 -y
vcr30.avi)

Which when program starts shows cpu load as
ffmpeg 50-60%
watch prog 3-4%

However as program progresses this changes to
ffmpeg 40-50%
watch prog 30-40%

and idle % decreases accordingly

anyone any ideas how to stop this behaviour



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]