← Index
Performance Profile   « block view • line view • sub view »
For opac/opac-main.pl
  Run on Fri Jul 18 13:58:34 2008
Reported on Fri Jul 18 13:58:43 2008

File/usr/local/share/perl/5.8.8/Cache/Memcached/GetParser.pm
Statements Executed60
Total Time0.000254 seconds

Subroutines — ordered by inclusive time then name
CallsInclusive
Time
Subroutine
20.00089Cache::Memcached::GetParser::parse_from_sock
20.00079Cache::Memcached::GetParser::parse_buffer
20.00004Cache::Memcached::GetParser::new
00Cache::Memcached::GetParser::BEGIN
00Cache::Memcached::GetParser::current_key

LineStmts.Exclusive
Time
Avg.Code
1package Cache::Memcached::GetParser;
2use strict;
3use warnings;
4use integer;
5
6use Errno qw( EINPROGRESS EWOULDBLOCK EISCONN );
7
8use constant DEST => 0; # destination hashref we're writing into
9use constant NSLEN => 1; # length of namespace to ignore on keys
10use constant ON_ITEM => 2;
11use constant BUF => 3; # read buffer
12use constant STATE => 4; # 0 = waiting for a line, N = reading N bytes
13use constant OFFSET => 5; # offsets to read into buffers
14use constant FLAGS => 6;
15use constant KEY => 7; # current key we're parsing (without the namespace prefix)
16
17
# spent 0.00004s within Cache::Memcached::GetParser::new which was called 2 times, avg 0.00002s/call: # 2 times (0.00004s) by Cache::Memcached::_load_multi at line 681 of /usr/local/share/perl/5.8.8/Cache/Memcached.pm, avg 0.00002s/call
sub new {
1824e-062e-06 my ($class, $dest, $nslen, $on_item) = @_;
1920.000020.00001 return bless [$dest, $nslen, $on_item, '', 0, 0], $class;
20}
21
22sub current_key {
23 return $_[0][KEY];
24}
25
26# returns 1 on success, -1 on failure, and 0 if still working.
27
# spent 0.00089s within Cache::Memcached::GetParser::parse_from_sock which was called 2 times, avg 0.00044s/call: # 2 times (0.00089s) by Cache::Memcached::_load_multi or Cache::Memcached::__ANON__[/usr/local/share/perl/5.8.8/Cache/Memcached.pm:695] at line 687 of /usr/local/share/perl/5.8.8/Cache/Memcached.pm, avg 0.00044s/call
sub parse_from_sock {
2822e-061e-06 my ($self, $sock) = @_;
2921e-065e-07 my $res;
30
31 # where are we reading into?
3222e-061e-06 if ($self->[STATE]) { # reading value into $ret
33 my $ret = $self->[DEST];
34 $res = sysread($sock, $ret->{$self->[KEY]},
35 $self->[STATE] - $self->[OFFSET],
36 $self->[OFFSET]);
37
38 return 0
39 if !defined($res) and $!==EWOULDBLOCK;
40
41 if ($res == 0) { # catches 0=conn closed or undef=error
42 $self->[ON_ITEM] = undef;
43 return -1;
44 }
45
46 $self->[OFFSET] += $res;
47 if ($self->[OFFSET] == $self->[STATE]) { # finished reading
48 $self->[ON_ITEM]->($self->[KEY], $self->[FLAGS]);
49 $self->[OFFSET] = 0;
50 $self->[STATE] = 0;
51 # wait for another VALUE line or END...
52 }
53 return 0; # still working, haven't got to end yet
54 }
55
56 # we're reading a single line.
57 # first, read whatever's there, but be satisfied with 2048 bytes
5820.000050.00002 $res = sysread($sock, $self->[BUF],
59 128*1024, $self->[OFFSET]);
6022e-061e-06 return 0
61 if !defined($res) and $!==EWOULDBLOCK;
6222e-061e-06 if ($res == 0) {
63 $self->[ON_ITEM] = undef;
64 return -1;
65 }
66
6722e-061e-06 $self->[OFFSET] += $res;
68
6920.000028e-06 return $self->parse_buffer;
# spent 0.00079s making 2 calls to Cache::Memcached::GetParser::parse_buffer, avg 0.00040s/call
70}
71
72# returns 1 on success, -1 on failure, and 0 if still working.
73
# spent 0.00079s within Cache::Memcached::GetParser::parse_buffer which was called 2 times, avg 0.00040s/call: # 2 times (0.00079s) by Cache::Memcached::GetParser::parse_from_sock at line 69 of /usr/local/share/perl/5.8.8/Cache/Memcached/GetParser.pm, avg 0.00040s/call
sub parse_buffer {
7422e-061e-06 my ($self) = @_;
7522e-061e-06 my $ret = $self->[DEST];
76
77 SEARCH:
7823e-062e-06 while (1) { # may have to search many times
79
80 # do we have a complete END line?
8141e-052e-06 if ($self->[BUF] =~ /^END\r\n/) {
8221e-065e-07 $self->[ON_ITEM] = undef;
8324e-062e-06 return 1; # we're done successfully, return 1 to finish
84 }
85
86 # do we have a complete VALUE line?
8720.000021e-05 if ($self->[BUF] =~ /^VALUE (\S+) (\d+) (\d+)\r\n/) {
8820.000020.00001 ($self->[KEY], $self->[FLAGS], $self->[STATE]) =
89 (substr($1, $self->[NSLEN]), int($2), $3+2);
90 # Note: we use $+[0] and not pos($self->[BUF]) because pos()
91 # seems to have problems under perl's taint mode. nobody
92 # on the list discovered why, but this seems a reasonable
93 # work-around:
9427e-063e-06 my $p = $+[0];
9522e-061e-06 my $len = length($self->[BUF]);
9623e-062e-06 my $copy = $len-$p > $self->[STATE] ? $self->[STATE] : $len-$p;
9720.000030.00002 $ret->{$self->[KEY]} = substr($self->[BUF], $p, $copy)
98 if $copy;
9921e-065e-07 $self->[OFFSET] = $copy;
10020.000021e-05 substr($self->[BUF], 0, $p+$copy, ''); # delete the stuff we used
101
10222e-061e-06 if ($self->[OFFSET] == $self->[STATE]) { # have it all?
10320.000017e-06 $self->[ON_ITEM]->($self->[KEY], $self->[FLAGS]);
# spent 0.00061s making 2 calls to Cache::Memcached::__ANON__[/usr/local/share/perl/5.8.8/Cache/Memcached.pm:668], avg 0.00030s/call
10422e-061e-06 $self->[OFFSET] = 0;
10522e-061e-06 $self->[STATE] = 0;
10622e-061e-06 next SEARCH; # look again
107 }
108
109 last SEARCH; # buffer is empty now
110 }
111
112 # if we're here probably means we only have a partial VALUE
113 # or END line in the buffer. Could happen with multi-get,
114 # though probably very rarely. Exit the loop and let it read
115 # more.
116
117 # but first, make sure subsequent reads don't destroy our
118 # partial VALUE/END line.
119 $self->[OFFSET] = length($self->[BUF]);
120 last SEARCH;
121 }
122 return 0;
123}
124
1251;