line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
97498
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Devel::DumpSizes; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
999
|
use PadWalker; |
|
1
|
|
|
|
|
10116
|
|
|
1
|
|
|
|
|
103
|
|
7
|
1
|
|
|
1
|
|
2022
|
use Devel::Size; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Devel::Symdump; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw (dump_sizes); |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub dump_sizes { |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $dump_file_prefix = shift || ""; |
20
|
|
|
|
|
|
|
my $ref_of_mys = PadWalker::peek_my(1); |
21
|
|
|
|
|
|
|
my %var_sizes; |
22
|
|
|
|
|
|
|
my @sorted_vars; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ( $dump_file_prefix ) { |
25
|
|
|
|
|
|
|
open(DUMP, ">>$dump_file_prefix.my") or warn "Unable to open file to dump sizes\n"; |
26
|
|
|
|
|
|
|
} else { |
27
|
|
|
|
|
|
|
open(DUMP, ">&STDOUT") or warn "ould not dup STDOUT\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
print DUMP "Variable name -> Size in bytes\n"; |
31
|
|
|
|
|
|
|
print DUMP '-' x 80, "\n"; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Foreach my variable in the caller stack, get "name -> size" as told by Devel::Size::total_size |
34
|
|
|
|
|
|
|
foreach my $var_name ( keys(%$ref_of_mys) ) { |
35
|
|
|
|
|
|
|
ref($ref_of_mys->{$var_name}) ? $var_sizes{$var_name} = Devel::Size::total_size($ref_of_mys->{$var_name}) |
36
|
|
|
|
|
|
|
: $var_sizes{$var_name} = Devel::Size::total_size(\$ref_of_mys->{$var_name}); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
@sorted_vars = map { "$_ -> $var_sizes{$_}" } sort { $var_sizes{$b} <=> $var_sizes{$a} } (keys(%var_sizes)); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if ( caller(1) ) { |
41
|
|
|
|
|
|
|
print DUMP '-' x 30, 'my : ', time(), ' : ', @{[caller(1)]}[3], '/', @{[caller(1)]}[2], '-' x 30, "\n"; |
42
|
|
|
|
|
|
|
} else { |
43
|
|
|
|
|
|
|
print DUMP '-' x 30, 'my : ', time(), '-' x 40, "\n"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
print DUMP join("\n", @sorted_vars), "\n"; |
46
|
|
|
|
|
|
|
print DUMP '-' x 80, "\n"; |
47
|
|
|
|
|
|
|
close(DUMP); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $sym_obj = Devel::Symdump->new( (caller(1))[0] ); |
50
|
|
|
|
|
|
|
my @vars_array; |
51
|
|
|
|
|
|
|
if ( $dump_file_prefix ) { |
52
|
|
|
|
|
|
|
open(DUMP, ">>$dump_file_prefix.ol") or warn "Unable to open file to dump sizes\n"; |
53
|
|
|
|
|
|
|
} else { |
54
|
|
|
|
|
|
|
open(DUMP, ">&STDOUT") or warn "ould not dup STDOUT\n"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Anonymous subroutine for getting "name -> size" variables in symtab of package of caller. |
58
|
|
|
|
|
|
|
my $sub_ref = sub { |
59
|
|
|
|
|
|
|
my $var_prefix = shift; |
60
|
|
|
|
|
|
|
%var_sizes = (); |
61
|
|
|
|
|
|
|
@sorted_vars = (); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Foreach our/local variable in the symbol table of caller's package, get "name -> size" |
64
|
|
|
|
|
|
|
if ( $var_prefix eq '$' ) { |
65
|
|
|
|
|
|
|
foreach my $var_name (@vars_array) { |
66
|
|
|
|
|
|
|
no strict 'refs'; |
67
|
|
|
|
|
|
|
if ( $$var_name ) { |
68
|
|
|
|
|
|
|
ref($$var_name) ? $var_sizes{$var_name} = Devel::Size::total_size($$var_name) |
69
|
|
|
|
|
|
|
: $var_sizes{$var_name} = Devel::Size::size($$var_name); |
70
|
|
|
|
|
|
|
} else { |
71
|
|
|
|
|
|
|
$var_sizes{$var_name} = 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} elsif ( $var_prefix eq '@' ) { |
75
|
|
|
|
|
|
|
foreach my $var_name (@vars_array) { |
76
|
|
|
|
|
|
|
no strict 'refs'; |
77
|
|
|
|
|
|
|
if ( @$var_name ) { |
78
|
|
|
|
|
|
|
$var_sizes{$var_name} = Devel::Size::total_size(\@$var_name); |
79
|
|
|
|
|
|
|
} else { |
80
|
|
|
|
|
|
|
$var_sizes{$var_name} = 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} elsif ( $var_prefix eq '%' ) { |
84
|
|
|
|
|
|
|
foreach my $var_name (@vars_array) { |
85
|
|
|
|
|
|
|
no strict 'refs'; |
86
|
|
|
|
|
|
|
if ( %$var_name ) { |
87
|
|
|
|
|
|
|
$var_sizes{$var_name} = Devel::Size::total_size(\%$var_name); |
88
|
|
|
|
|
|
|
} else { |
89
|
|
|
|
|
|
|
$var_sizes{$var_name} = 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
@sorted_vars = map { "$var_prefix$_ -> $var_sizes{$_}" } sort { $var_sizes{$b} <=> $var_sizes{$a} } (keys(%var_sizes)); |
95
|
|
|
|
|
|
|
if ( caller(2) ) { |
96
|
|
|
|
|
|
|
print DUMP '-' x 30, 'our/local : ', time(), ' : ', @{[caller(2)]}[3], '/', @{[caller(2)]}[2], '-' x 30, "\n"; |
97
|
|
|
|
|
|
|
} else { |
98
|
|
|
|
|
|
|
print DUMP '-' x 30, 'our/local : ', time(), '-' x 40, "\n"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
print DUMP join("\n", @sorted_vars), "\n"; |
101
|
|
|
|
|
|
|
print DUMP '-' x 80, "\n"; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
@vars_array = (); |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
@vars_array = $sym_obj->scalars; |
107
|
|
|
|
|
|
|
$sub_ref->('$'); |
108
|
|
|
|
|
|
|
@vars_array = $sym_obj->arrays; |
109
|
|
|
|
|
|
|
$sub_ref->('@'); |
110
|
|
|
|
|
|
|
@vars_array = $sym_obj->hashes; |
111
|
|
|
|
|
|
|
$sub_ref->('%'); |
112
|
|
|
|
|
|
|
close(DUMP); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
__END__ |