← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Tue Nov 7 05:38:10 2017
Reported on Tue Nov 7 06:16:02 2017

Filename/usr/local/lib/perl5/5.24/mach/Digest/SHA.pm
StatementsExecuted 26 statements in 3.76ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
156112111.26s1.26sDigest::SHA::::sha1Digest::SHA::sha1 (xsub)
6881114.6ms14.6msDigest::SHA::::sha1_hexDigest::SHA::sha1_hex (xsub)
111200µs200µsDigest::SHA::::bootstrapDigest::SHA::bootstrap (xsub)
11156µs63µsDigest::SHA::::BEGIN@5Digest::SHA::BEGIN@5
11137µs46µsDigest::SHA::::BEGIN@196Digest::SHA::BEGIN@196
11134µs2.41msDigest::SHA::::BEGIN@8Digest::SHA::BEGIN@8
11127µs34µsDigest::SHA::::BEGIN@9Digest::SHA::BEGIN@9
11123µs50µsDigest::SHA::::BEGIN@6Digest::SHA::BEGIN@6
11122µs332µsDigest::SHA::::BEGIN@7Digest::SHA::BEGIN@7
11116µs16µsDigest::SHA::::BEGIN@55Digest::SHA::BEGIN@55
0000s0sDigest::SHA::::_addfileDigest::SHA::_addfile
0000s0sDigest::SHA::::_bailDigest::SHA::_bail
0000s0sDigest::SHA::::_istextDigest::SHA::_istext
0000s0sDigest::SHA::::add_bitsDigest::SHA::add_bits
0000s0sDigest::SHA::::addfileDigest::SHA::addfile
0000s0sDigest::SHA::::dumpDigest::SHA::dump
0000s0sDigest::SHA::::getstateDigest::SHA::getstate
0000s0sDigest::SHA::::loadDigest::SHA::load
0000s0sDigest::SHA::::newDigest::SHA::new
0000s0sDigest::SHA::::putstateDigest::SHA::putstate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Digest::SHA;
2
3133µsrequire 5.003000;
4
5271µs271µs
# spent 63µs (56+7) within Digest::SHA::BEGIN@5 which was called: # once (56µs+7µs) by Mail::SpamAssassin::Message::BEGIN@49 at line 5
use strict;
# spent 63µs making 1 call to Digest::SHA::BEGIN@5 # spent 7µs making 1 call to strict::import
6286µs277µs
# spent 50µs (23+27) within Digest::SHA::BEGIN@6 which was called: # once (23µs+27µs) by Mail::SpamAssassin::Message::BEGIN@49 at line 6
use warnings;
# spent 50µs making 1 call to Digest::SHA::BEGIN@6 # spent 27µs making 1 call to warnings::import
7267µs2642µs
# spent 332µs (22+310) within Digest::SHA::BEGIN@7 which was called: # once (22µs+310µs) by Mail::SpamAssassin::Message::BEGIN@49 at line 7
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
# spent 332µs making 1 call to Digest::SHA::BEGIN@7 # spent 310µs making 1 call to vars::import
8289µs24.78ms
# spent 2.41ms (34µs+2.37) within Digest::SHA::BEGIN@8 which was called: # once (34µs+2.37ms) by Mail::SpamAssassin::Message::BEGIN@49 at line 8
use Fcntl;
# spent 2.41ms making 1 call to Digest::SHA::BEGIN@8 # spent 2.37ms making 1 call to Exporter::import
92452µs240µs
# spent 34µs (27+7) within Digest::SHA::BEGIN@9 which was called: # once (27µs+7µs) by Mail::SpamAssassin::Message::BEGIN@49 at line 9
use integer;
# spent 34µs making 1 call to Digest::SHA::BEGIN@9 # spent 7µs making 1 call to integer::import
10
1112µs$VERSION = '5.95_01';
12
1315µsrequire Exporter;
1412µsrequire DynaLoader;
15120µs@ISA = qw(Exporter DynaLoader);
16111µs@EXPORT_OK = qw(
17 hmac_sha1 hmac_sha1_base64 hmac_sha1_hex
18 hmac_sha224 hmac_sha224_base64 hmac_sha224_hex
19 hmac_sha256 hmac_sha256_base64 hmac_sha256_hex
20 hmac_sha384 hmac_sha384_base64 hmac_sha384_hex
21 hmac_sha512 hmac_sha512_base64 hmac_sha512_hex
22 hmac_sha512224 hmac_sha512224_base64 hmac_sha512224_hex
23 hmac_sha512256 hmac_sha512256_base64 hmac_sha512256_hex
24 sha1 sha1_base64 sha1_hex
25 sha224 sha224_base64 sha224_hex
26 sha256 sha256_base64 sha256_hex
27 sha384 sha384_base64 sha384_hex
28 sha512 sha512_base64 sha512_hex
29 sha512224 sha512224_base64 sha512224_hex
30 sha512256 sha512256_base64 sha512256_hex);
31
32# Inherit from Digest::base if possible
33
3415µseval {
351305µs require Digest::base;
36119µs push(@ISA, 'Digest::base');
37};
38
39# The following routines aren't time-critical, so they can be left in Perl
40
41sub new {
42 my($class, $alg) = @_;
43 $alg =~ s/\D+//g if defined $alg;
44 if (ref($class)) { # instance method
45 if (!defined($alg) || ($alg == $class->algorithm)) {
46 sharewind($class);
47 return($class);
48 }
49 return shainit($class, $alg) ? $class : undef;
50 }
51 $alg = 1 unless defined $alg;
52 return $class->newSHA($alg);
53}
54
5511.86ms116µs
# spent 16µs within Digest::SHA::BEGIN@55 which was called: # once (16µs+0s) by Mail::SpamAssassin::Message::BEGIN@49 at line 55
BEGIN { *reset = \&new }
# spent 16µs making 1 call to Digest::SHA::BEGIN@55
56
57sub add_bits {
58 my($self, $data, $nbits) = @_;
59 unless (defined $nbits) {
60 $nbits = length($data);
61 $data = pack("B*", $data);
62 }
63 $nbits = length($data) * 8 if $nbits > length($data) * 8;
64 shawrite($data, $nbits, $self);
65 return($self);
66}
67
68sub _bail {
69 my $msg = shift;
70
71 $msg .= ": $!";
72 require Carp;
73 Carp::croak($msg);
74}
75
76{
7712µs my $_can_T_filehandle;
78
79 sub _istext {
80 local *FH = shift;
81 my $file = shift;
82
83 if (! defined $_can_T_filehandle) {
84 local $^W = 0;
85 my $istext = eval { -T FH };
86 $_can_T_filehandle = $@ ? 0 : 1;
87 return $_can_T_filehandle ? $istext : -T $file;
88 }
89 return $_can_T_filehandle ? -T FH : -T $file;
90 }
91}
92
9314µssub _addfile {
94 my ($self, $handle) = @_;
95
96 my $n;
97 my $buf = "";
98
99 while (($n = read($handle, $buf, 4096))) {
100 $self->add($buf);
101 }
102 _bail("Read failed") unless defined $n;
103
104 $self;
105}
106
107sub addfile {
108 my ($self, $file, $mode) = @_;
109
110 return(_addfile($self, $file)) unless ref(\$file) eq 'SCALAR';
111
112 $mode = defined($mode) ? $mode : "";
113 my ($binary, $UNIVERSAL, $BITS, $portable) =
114 map { $_ eq $mode } ("b", "U", "0", "p");
115
116 ## Always interpret "-" to mean STDIN; otherwise use
117 ## sysopen to handle full range of POSIX file names
118
119 local *FH;
120 $file eq '-' and open(FH, '< -')
121 or sysopen(FH, $file, O_RDONLY)
122 or _bail('Open failed');
123
124 if ($BITS) {
125 my ($n, $buf) = (0, "");
126 while (($n = read(FH, $buf, 4096))) {
127 $buf =~ s/[^01]//g;
128 $self->add_bits($buf);
129 }
130 _bail("Read failed") unless defined $n;
131 close(FH);
132 return($self);
133 }
134
135 binmode(FH) if $binary || $portable || $UNIVERSAL;
136 if ($UNIVERSAL && _istext(*FH, $file)) {
137 $self->_addfileuniv(*FH);
138 }
139 elsif ($portable && _istext(*FH, $file)) {
140 while (<FH>) {
141 s/\015?\015\012/\012/g;
142 s/\015/\012/g;
143 $self->add($_);
144 }
145 }
146 else { $self->_addfilebin(*FH) }
147 close(FH);
148
149 $self;
150}
151
152sub getstate {
153 my $self = shift;
154
155 my $alg = $self->algorithm or return;
156 my $state = $self->_getstate or return;
157 my $nD = $alg <= 256 ? 8 : 16;
158 my $nH = $alg <= 256 ? 32 : 64;
159 my $nB = $alg <= 256 ? 64 : 128;
160 my($H, $block, $blockcnt, $lenhh, $lenhl, $lenlh, $lenll) =
161 $state =~ /^(.{$nH})(.{$nB})(.{4})(.{4})(.{4})(.{4})(.{4})$/s;
162 for ($alg, $H, $block, $blockcnt, $lenhh, $lenhl, $lenlh, $lenll) {
163 return unless defined $_;
164 }
165
166 my @s = ();
167 push(@s, "alg:" . $alg);
168 push(@s, "H:" . join(":", unpack("H*", $H) =~ /.{$nD}/g));
169 push(@s, "block:" . join(":", unpack("H*", $block) =~ /.{2}/g));
170 push(@s, "blockcnt:" . unpack("N", $blockcnt));
171 push(@s, "lenhh:" . unpack("N", $lenhh));
172 push(@s, "lenhl:" . unpack("N", $lenhl));
173 push(@s, "lenlh:" . unpack("N", $lenlh));
174 push(@s, "lenll:" . unpack("N", $lenll));
175 join("\n", @s) . "\n";
176}
177
178sub putstate {
179 my($class, $state) = @_;
180
181 my %s = ();
182 for (split(/\n/, $state)) {
183 s/^\s+//;
184 s/\s+$//;
185 next if (/^(#|$)/);
186 my @f = split(/[:\s]+/);
187 my $tag = shift(@f);
188 $s{$tag} = join('', @f);
189 }
190
191 # H and block may contain arbitrary values, but check everything else
192 grep { $_ == $s{'alg'} } (1,224,256,384,512,512224,512256) or return;
193 length($s{'H'}) == ($s{'alg'} <= 256 ? 64 : 128) or return;
194 length($s{'block'}) == ($s{'alg'} <= 256 ? 128 : 256) or return;
195 {
1962662µs254µs
# spent 46µs (37+9) within Digest::SHA::BEGIN@196 which was called: # once (37µs+9µs) by Mail::SpamAssassin::Message::BEGIN@49 at line 196
no integer;
# spent 46µs making 1 call to Digest::SHA::BEGIN@196 # spent 9µs making 1 call to integer::unimport
197 for (qw(blockcnt lenhh lenhl lenlh lenll)) {
198 0 <= $s{$_} or return;
199 $s{$_} <= 4294967295 or return;
200 }
201 $s{'blockcnt'} < ($s{'alg'} <= 256 ? 512 : 1024) or return;
202 }
203
204 my $packed_state = (
205 pack("H*", $s{'H'}) .
206 pack("H*", $s{'block'}) .
207 pack("N", $s{'blockcnt'}) .
208 pack("N", $s{'lenhh'}) .
209 pack("N", $s{'lenhl'}) .
210 pack("N", $s{'lenlh'}) .
211 pack("N", $s{'lenll'})
212 );
213
214 return $class->new($s{'alg'})->_putstate($packed_state);
215}
216
217sub dump {
218 my $self = shift;
219 my $file = shift;
220
221 my $state = $self->getstate or return;
222 $file = "-" if (!defined($file) || $file eq "");
223
224 local *FH;
225 open(FH, "> $file") or return;
226 print FH $state;
227 close(FH);
228
229 return($self);
230}
231
232sub load {
233 my $class = shift;
234 my $file = shift;
235
236 $file = "-" if (!defined($file) || $file eq "");
237
238 local *FH;
239 open(FH, "< $file") or return;
240 my $str = join('', <FH>);
241 close(FH);
242
243 $class->putstate($str);
244}
245
246130µs1791µsDigest::SHA->bootstrap($VERSION);
# spent 791µs making 1 call to DynaLoader::bootstrap
247
248137µs1;
249__END__
 
# spent 200µs within Digest::SHA::bootstrap which was called: # once (200µs+0s) by DynaLoader::bootstrap at line 210 of DynaLoader.pm
sub Digest::SHA::bootstrap; # xsub
# spent 1.26s within Digest::SHA::sha1 which was called 156112 times, avg 8µs/call: # 156112 times (1.26s+0s) by Mail::SpamAssassin::Plugin::Bayes::tokenize at line 1124 of Mail/SpamAssassin/Plugin/Bayes.pm, avg 8µs/call
sub Digest::SHA::sha1; # xsub
# spent 14.6ms within Digest::SHA::sha1_hex which was called 688 times, avg 21µs/call: # 688 times (14.6ms+0s) by Mail::SpamAssassin::Plugin::Bayes::get_msgid at line 1009 of Mail/SpamAssassin/Plugin/Bayes.pm, avg 21µs/call
sub Digest::SHA::sha1_hex; # xsub