Changeset 2337 for branches/release-38/lib/MT/TheSchwartz.pm
- Timestamp:
- 05/14/08 23:35:55 (19 months ago)
- Files:
-
- 1 modified
-
branches/release-38/lib/MT/TheSchwartz.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-38/lib/MT/TheSchwartz.pm
r2336 r2337 30 30 my $class = shift; 31 31 $class->instance->SUPER::insert(@_); 32 } 33 34 sub default_logger { 35 my ($msg, $job) = @_; 36 # suppress TheSchwartz::Job's 'job completed' 37 return if $msg eq 'job completed'; 38 39 $msg =~ s/\s+$//; 40 print STDERR "$msg\n"; 32 41 } 33 42 … … 41 50 # Reports object usage inbetween jobs if Devel::Leak::Object is loaded 42 51 $OBJECT_REPORT = 1 if $Devel::Leak::Object::VERSION; 52 53 $param{verbose} = \&default_logger 54 if $param{verbose} && (ref $param{verbose} ne 'CODE'); 43 55 44 56 my $client = $class->SUPER::new(%param); … … 134 146 my $did_work = 0; 135 147 148 # holds state of objects at start 149 my %obj_start; 136 150 if ($OBJECT_REPORT) { 137 Devel::Leak::Object::status(); 138 print "\n\n"; 151 %obj_start = %Devel::Leak::Object::OBJECT_COUNT; 139 152 } 140 153 141 154 while (1) { 155 my %obj_pre; 156 if ($OBJECT_REPORT) { 157 %obj_pre = %Devel::Leak::Object::OBJECT_COUNT; 158 } 159 142 160 if ($client->work_once) { 143 161 $did_work = 1; … … 157 175 $did_work = 0; 158 176 if ($OBJECT_REPORT) { 159 Devel::Leak::Object::status(); 160 print "\n\n"; 177 leak_report(\%obj_start, \%obj_pre, \%Devel::Leak::Object::OBJECT_COUNT); 161 178 } 162 179 } 163 180 164 181 sleep $delay; 182 } 183 } 184 185 our %persistent; 186 BEGIN { 187 %persistent = map { $_ => 1 } qw( MT::Task MT::Plugin MT::Component MT::ArchiveType MT::TaskMgr MT::WeblogPublisher MT::Serializer TheSchwartz::Job TheSchwartz::JobHandle ); 188 } 189 sub leak_report { 190 my ($start, $pre, $post) = @_; 191 my $reported; 192 foreach my $class (sort keys %$post) { 193 # skip reporting classes that are persistent in nature 194 next if exists $persistent{$class}; 195 196 my $post_count = $post->{$class}; 197 next if ! $post_count; 198 my $pre_count = $pre->{$class} || 0; 199 my $start_count = $start->{$class} || 0; 200 next if $post_count == 1; # ignores most singletons 201 if (($pre_count != $post_count) || ($post_count != $start_count)) { 202 print "Leak report (class, total, delta from last job(s), delta since process start):\n" unless $reported; 203 printf "%-40s %-10d %-10d %-10d\n", $class, $post_count, $post_count - $pre_count, $post_count - $start_count; 204 $reported = 1; 205 } 165 206 } 166 207 }
