Posted on 2009-10-07 17:42:04-07 by hessu75
Devel::Cover crashes while creating HTML report - workaround
Hello/FYI,

This is an excellent tool but it uses way too much memory. The memory limit for single user application seems to be 2GB on 32 bit Windows system (3GB for Linux?). At least for me the Perl process reaches this limit when cover is generating the HTML report from data that is roughly 120 MB after running ~400 test cases with Devel::Cover.

By commenting the Storable::nstore line from below pasted code, it seems to be possible to push the limit bit further. The subroutine is from Devel::Cover DB.pm module. Most likely this is not so nice solution and someone more clever can come up with better solution. But at least for me it seems to work.

It seems that you have to use the comment only when HTML report is generated. When test cases are run, this line needs to be in place. When HTML report is being generated, this line seems to double the memory usage. For example if the memory consumption was 1GB before this, this line will double it to 2GB.

sub write { my $self = shift; $self->{db} = shift if @_; croak "No db specified" unless length $self->{db}; unless (-d $self->{db}) { mkdir $self->{db}, 0700 or croak "Can't mkdir $self->{db}: $!\n"; } $self->validate_db; my $db = { runs => $self->{runs}, }; #Storable::nstore($db, "$self->{db}/$DB"); $self->{structure}->write($self->{base}) if $self->{structure}; $self }

Also one comment about below pasted code. You may still need to try to generate the report couple of times if the memory usage is reaching its limits. The reason is that reading of cover.12 file seems to take random amount of memory, at least on Windows machine. Sometimes the memory consumption after reading the file is around few hundreds megabytes, sometimes around one gigabyte.

I was measuring memory consumption with Windows Task Manager and I am not absolute sure about this later comment.

sub new { my $class = shift; ... bless $self, $class; if (defined $self->{db}) { $self->validate_db; my $file = "$self->{db}/$DB"; # <-- This seems to eat random amount of memory. $self->read($file) if -e $file; } $self }

=========================================
Windows XP SP3
ActiveState Perl 5.8.9 build 826
Devel::Cover 0.65
Storable 2.21

Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.