blib/lib/UR/Namespace/Command/Test/TrackObjectRelease.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 83 SCAR 42.8
CC
8
Cov
0%
execute
72.0
help_brief
2.0
help_synopsis
2.0
CRAP 72.0
1 package UR::Namespace::Command::Test::TrackObjectRelease;
2  
3 use strict;
4 use warnings;
5  
6 use UR;
7 our $VERSION = "0.46"; # UR $VERSION;
8 use IO::File;
9  
10 class UR::Namespace::Command::Test::TrackObjectRelease {
11 is => 'UR::Namespace::Command::Base',
12 has => [
13 file => { is => 'Text', doc => 'pathname of the input file' },
14 ],
15 };
16  
17 sub help_brief { 'Parse the data produced by UR_DEBUG_OBJECT_RELEASE and report possible memory leaks' };
18  
19 sub help_synopsis {
20 "ur test track-object-release --file /path/to/text.file > /path/to/results"
21 }
22  
23 sub help_detail {
24 "When a UR-based program is run with the UR_DEBUG_OBJECT_RELEASE environment
25 variable set to 1, it will emit messages to STDERR describing the various
26 stages of releasing an object. This command parses those messages and
27 provides a report on objects which did not completely deallocate themselves,
28 usually because of a reference being held."
29 }
30  
31 sub execute {
32 my $self = shift;
33  
34 #$DB::single = 1;
35 my $file = $self->file;
36 my $fh = IO::File->new($file,'r');
37  
38 unless ($fh) {
39 $self->error_message("Can't open input file: $!");
40 return;
41 }
42  
43 # for a given state, it's legal predecessor
44 my %prev_states = ( 'PRUNE object' => '',
45 'DESTROY object' => 'PRUNE object',
46 'UNLOAD object' => 'DESTROY object',
47 'DELETE object' => 'UNLOAD object',
48 'BURY object' => 'DELETE object',
49 'DESTROY deletedref' => 'BURY object',
50 );
51 my %next_states = reverse %prev_states;
52 # After this we stop stracking it
53 my %terminal_states = ( 'DESTROY deletedref' => 1 );
54 my %objects;
55  
56  
57 while(<$fh>) {
58 chomp;
59  
60 my ($action,$refaddr);
61 if (m/MEM ((PRUNE|DESTROY|UNLOAD|DELETE|BURY) (object|deletedref)) (\S+)/) {
62 $action = $1;
63 my $refstr = $4;
64 ($refaddr) = ($refstr =~ m/=HASH\((.*)\)/);
65 } else {
66 next;
67 }
68 my($class,$id) = m/class (\S+) id (.*)/; # These don't appear in the deletedref line, and are optional
69  
70 my $expected_prev_state = $prev_states{$action};
71 if (defined $expected_prev_state && $expected_prev_state) {
72 # This state must have a predecessor
73 if ($objects{$expected_prev_state}->{$refaddr}) {
74 if ($terminal_states{$action}) {
75 delete $objects{$expected_prev_state}->{$refaddr};
76 } else {
77 $objects{$action}->{$refaddr} = delete $objects{$expected_prev_state}->{$refaddr};
78 }
79 } else {
80 print STDERR "$action for $refaddr without matching $expected_prev_state at line $.\n";
81 }
82  
83 } elsif (defined $expected_prev_state) {
84 # The initial state
85 $objects{$action}->{$refaddr} = $_;
86  
87 } else {
88 print STDERR "Unknown action $action at line $.\n";
89 }
90 }
91  
92 foreach my $action (keys %objects) {
93 if (keys %{$objects{$action}} ) {
94 print "\n$action but not $next_states{$action}\n";
95 foreach (keys %{$objects{$action}}) {
96 print "$_ : ",$objects{$action}->{$_},"\n";
97 }
98 }
99 }
100  
101 return 1;
102 }
103  
104 1;
105  
106