| Filename | /usr/share/perl5/Cache/Memcached/GetParser.pm |
| Statements | Executed 1857 statements in 14.7ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 62 | 1 | 1 | 6.14ms | 1.42s | Cache::Memcached::GetParser::parse_buffer |
| 67 | 2 | 1 | 2.61ms | 2.61ms | Cache::Memcached::GetParser::CORE:sysread (opcode) |
| 171 | 2 | 1 | 1.91ms | 1.91ms | Cache::Memcached::GetParser::CORE:match (opcode) |
| 67 | 1 | 1 | 1.83ms | 1.57s | Cache::Memcached::GetParser::parse_from_sock |
| 1 | 1 | 1 | 1.56ms | 2.16ms | Cache::Memcached::GetParser::BEGIN@8 |
| 57 | 1 | 1 | 910µs | 910µs | Cache::Memcached::GetParser::new |
| 1 | 1 | 1 | 209µs | 214µs | Cache::Memcached::GetParser::BEGIN@4 |
| 1 | 1 | 1 | 16µs | 21µs | Cache::Memcached::GetParser::BEGIN@2 |
| 1 | 1 | 1 | 15µs | 96µs | Cache::Memcached::GetParser::BEGIN@6 |
| 1 | 1 | 1 | 11µs | 33µs | Cache::Memcached::GetParser::BEGIN@3 |
| 1 | 1 | 1 | 10µs | 47µs | Cache::Memcached::GetParser::BEGIN@9 |
| 1 | 1 | 1 | 9µs | 39µs | Cache::Memcached::GetParser::BEGIN@15 |
| 1 | 1 | 1 | 9µs | 40µs | Cache::Memcached::GetParser::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 38µs | Cache::Memcached::GetParser::BEGIN@13 |
| 1 | 1 | 1 | 8µs | 38µs | Cache::Memcached::GetParser::BEGIN@14 |
| 1 | 1 | 1 | 8µs | 38µs | Cache::Memcached::GetParser::BEGIN@12 |
| 1 | 1 | 1 | 7µs | 38µs | Cache::Memcached::GetParser::BEGIN@11 |
| 0 | 0 | 0 | 0s | 0s | Cache::Memcached::GetParser::current_key |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Cache::Memcached::GetParser; | ||||
| 2 | 3 | 31µs | 2 | 25µs | # spent 21µs (16+4) within Cache::Memcached::GetParser::BEGIN@2 which was called:
# once (16µs+4µs) by Cache::Memcached::BEGIN@20 at line 2 # spent 21µs making 1 call to Cache::Memcached::GetParser::BEGIN@2
# spent 4µs making 1 call to strict::import |
| 3 | 3 | 29µs | 2 | 55µs | # spent 33µs (11+22) within Cache::Memcached::GetParser::BEGIN@3 which was called:
# once (11µs+22µs) by Cache::Memcached::BEGIN@20 at line 3 # spent 33µs making 1 call to Cache::Memcached::GetParser::BEGIN@3
# spent 22µs making 1 call to warnings::import |
| 4 | 3 | 245µs | 2 | 221µs | # spent 214µs (209+6) within Cache::Memcached::GetParser::BEGIN@4 which was called:
# once (209µs+6µs) by Cache::Memcached::BEGIN@20 at line 4 # spent 214µs making 1 call to Cache::Memcached::GetParser::BEGIN@4
# spent 6µs making 1 call to integer::import |
| 5 | |||||
| 6 | 3 | 56µs | 2 | 176µs | # spent 96µs (15+80) within Cache::Memcached::GetParser::BEGIN@6 which was called:
# once (15µs+80µs) by Cache::Memcached::BEGIN@20 at line 6 # spent 96µs making 1 call to Cache::Memcached::GetParser::BEGIN@6
# spent 80µs making 1 call to Exporter::import |
| 7 | |||||
| 8 | 3 | 205µs | 2 | 2.29ms | # spent 2.16ms (1.56+607µs) within Cache::Memcached::GetParser::BEGIN@8 which was called:
# once (1.56ms+607µs) by Cache::Memcached::BEGIN@20 at line 8 # spent 2.16ms making 1 call to Cache::Memcached::GetParser::BEGIN@8
# spent 129µs making 1 call to constant::import |
| 9 | 3 | 34µs | 2 | 85µs | # spent 47µs (10+37) within Cache::Memcached::GetParser::BEGIN@9 which was called:
# once (10µs+37µs) by Cache::Memcached::BEGIN@20 at line 9 # spent 47µs making 1 call to Cache::Memcached::GetParser::BEGIN@9
# spent 37µs making 1 call to constant::import |
| 10 | 3 | 30µs | 2 | 71µs | # spent 40µs (9+31) within Cache::Memcached::GetParser::BEGIN@10 which was called:
# once (9µs+31µs) by Cache::Memcached::BEGIN@20 at line 10 # spent 40µs making 1 call to Cache::Memcached::GetParser::BEGIN@10
# spent 31µs making 1 call to constant::import |
| 11 | 3 | 29µs | 2 | 69µs | # spent 38µs (7+31) within Cache::Memcached::GetParser::BEGIN@11 which was called:
# once (7µs+31µs) by Cache::Memcached::BEGIN@20 at line 11 # spent 38µs making 1 call to Cache::Memcached::GetParser::BEGIN@11
# spent 31µs making 1 call to constant::import |
| 12 | 3 | 31µs | 2 | 68µs | # spent 38µs (8+30) within Cache::Memcached::GetParser::BEGIN@12 which was called:
# once (8µs+30µs) by Cache::Memcached::BEGIN@20 at line 12 # spent 38µs making 1 call to Cache::Memcached::GetParser::BEGIN@12
# spent 30µs making 1 call to constant::import |
| 13 | 3 | 29µs | 2 | 69µs | # spent 38µs (8+30) within Cache::Memcached::GetParser::BEGIN@13 which was called:
# once (8µs+30µs) by Cache::Memcached::BEGIN@20 at line 13 # spent 38µs making 1 call to Cache::Memcached::GetParser::BEGIN@13
# spent 30µs making 1 call to constant::import |
| 14 | 3 | 29µs | 2 | 68µs | # spent 38µs (8+30) within Cache::Memcached::GetParser::BEGIN@14 which was called:
# once (8µs+30µs) by Cache::Memcached::BEGIN@20 at line 14 # spent 38µs making 1 call to Cache::Memcached::GetParser::BEGIN@14
# spent 30µs making 1 call to constant::import |
| 15 | 3 | 712µs | 2 | 69µs | # spent 39µs (9+30) within Cache::Memcached::GetParser::BEGIN@15 which was called:
# once (9µs+30µs) by Cache::Memcached::BEGIN@20 at line 15 # spent 39µs making 1 call to Cache::Memcached::GetParser::BEGIN@15
# spent 30µs making 1 call to constant::import |
| 16 | |||||
| 17 | # spent 910µs within Cache::Memcached::GetParser::new which was called 57 times, avg 16µs/call:
# 57 times (910µs+0s) by Cache::Memcached::_load_multi at line 727 of Cache/Memcached.pm, avg 16µs/call | ||||
| 18 | 57 | 156µs | my ($class, $dest, $nslen, $on_item) = @_; | ||
| 19 | 57 | 821µs | return bless [$dest, $nslen, $on_item, '', 0, 0], $class; | ||
| 20 | } | ||||
| 21 | |||||
| 22 | sub current_key { | ||||
| 23 | return $_[0][KEY]; | ||||
| 24 | } | ||||
| 25 | |||||
| 26 | # returns 1 on success, -1 on failure, and 0 if still working. | ||||
| 27 | # spent 1.57s (1.83ms+1.57) within Cache::Memcached::GetParser::parse_from_sock which was called 67 times, avg 23.5ms/call:
# 67 times (1.83ms+1.57s) by Cache::Memcached::__ANON__[/usr/share/perl5/Cache/Memcached.pm:741] at line 733 of Cache/Memcached.pm, avg 23.5ms/call | ||||
| 28 | 67 | 100µs | my ($self, $sock) = @_; | ||
| 29 | 67 | 32µs | my $res; | ||
| 30 | |||||
| 31 | # where are we reading into? | ||||
| 32 | 67 | 74µs | if ($self->[STATE]) { # reading value into $ret | ||
| 33 | 5 | 4µs | my $ret = $self->[DEST]; | ||
| 34 | 5 | 179µs | 5 | 130µs | $res = sysread($sock, $ret->{$self->[KEY]}, # spent 130µs making 5 calls to Cache::Memcached::GetParser::CORE:sysread, avg 26µs/call |
| 35 | $self->[STATE] - $self->[OFFSET], | ||||
| 36 | $self->[OFFSET]); | ||||
| 37 | |||||
| 38 | 5 | 5µs | return 0 | ||
| 39 | if !defined($res) and $!==EWOULDBLOCK; | ||||
| 40 | |||||
| 41 | 5 | 4µs | if ($res == 0) { # catches 0=conn closed or undef=error | ||
| 42 | $self->[ON_ITEM] = undef; | ||||
| 43 | return -1; | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | 5 | 5µs | $self->[OFFSET] += $res; | ||
| 47 | 5 | 7µs | if ($self->[OFFSET] == $self->[STATE]) { # finished reading | ||
| 48 | 5 | 26µs | 5 | 153ms | $self->[ON_ITEM]->($self->[KEY], $self->[FLAGS]); # spent 153ms making 5 calls to Cache::Memcached::__ANON__[Cache/Memcached.pm:714], avg 30.7ms/call |
| 49 | 5 | 10µs | $self->[OFFSET] = 0; | ||
| 50 | 5 | 6µs | $self->[STATE] = 0; | ||
| 51 | # wait for another VALUE line or END... | ||||
| 52 | } | ||||
| 53 | 5 | 31µs | 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 | ||||
| 58 | 62 | 3.02ms | 62 | 2.48ms | $res = sysread($sock, $self->[BUF], # spent 2.48ms making 62 calls to Cache::Memcached::GetParser::CORE:sysread, avg 40µs/call |
| 59 | 128*1024, $self->[OFFSET]); | ||||
| 60 | 62 | 67µs | return 0 | ||
| 61 | if !defined($res) and $!==EWOULDBLOCK; | ||||
| 62 | 62 | 85µs | if ($res == 0) { | ||
| 63 | $self->[ON_ITEM] = undef; | ||||
| 64 | return -1; | ||||
| 65 | } | ||||
| 66 | |||||
| 67 | 62 | 72µs | $self->[OFFSET] += $res; | ||
| 68 | |||||
| 69 | 62 | 586µs | 62 | 1.42s | return $self->parse_buffer; # spent 1.42s making 62 calls to Cache::Memcached::GetParser::parse_buffer, avg 22.9ms/call |
| 70 | } | ||||
| 71 | |||||
| 72 | # returns 1 on success, -1 on failure, and 0 if still working. | ||||
| 73 | # spent 1.42s (6.14ms+1.41) within Cache::Memcached::GetParser::parse_buffer which was called 62 times, avg 22.9ms/call:
# 62 times (6.14ms+1.41s) by Cache::Memcached::GetParser::parse_from_sock at line 69, avg 22.9ms/call | ||||
| 74 | 62 | 83µs | my ($self) = @_; | ||
| 75 | 62 | 62µs | my $ret = $self->[DEST]; | ||
| 76 | |||||
| 77 | SEARCH: | ||||
| 78 | 62 | 44µs | while (1) { # may have to search many times | ||
| 79 | |||||
| 80 | # do we have a complete END line? | ||||
| 81 | 114 | 1.26ms | 114 | 673µs | if ($self->[BUF] =~ /^END\r\n/) { # spent 673µs making 114 calls to Cache::Memcached::GetParser::CORE:match, avg 6µs/call |
| 82 | 57 | 91µs | $self->[ON_ITEM] = undef; | ||
| 83 | 57 | 305µs | return 1; # we're done successfully, return 1 to finish | ||
| 84 | } | ||||
| 85 | |||||
| 86 | # do we have a complete VALUE line? | ||||
| 87 | 57 | 1.49ms | 57 | 1.23ms | if ($self->[BUF] =~ /^VALUE (\S+) (\d+) (\d+)\r\n/) { # spent 1.23ms making 57 calls to Cache::Memcached::GetParser::CORE:match, avg 22µs/call |
| 88 | 57 | 1.09ms | ($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: | ||||
| 94 | 57 | 304µs | my $p = $+[0]; | ||
| 95 | 57 | 68µs | my $len = length($self->[BUF]); | ||
| 96 | 57 | 132µs | my $copy = $len-$p > $self->[STATE] ? $self->[STATE] : $len-$p; | ||
| 97 | 57 | 1.57ms | $ret->{$self->[KEY]} = substr($self->[BUF], $p, $copy) | ||
| 98 | if $copy; | ||||
| 99 | 57 | 46µs | $self->[OFFSET] = $copy; | ||
| 100 | 57 | 765µs | substr($self->[BUF], 0, $p+$copy, ''); # delete the stuff we used | ||
| 101 | |||||
| 102 | 57 | 69µs | if ($self->[OFFSET] == $self->[STATE]) { # have it all? | ||
| 103 | 52 | 228µs | 52 | 1.41s | $self->[ON_ITEM]->($self->[KEY], $self->[FLAGS]); # spent 1.41s making 52 calls to Cache::Memcached::__ANON__[Cache/Memcached.pm:714], avg 27.1ms/call |
| 104 | 52 | 99µs | $self->[OFFSET] = 0; | ||
| 105 | 52 | 36µs | $self->[STATE] = 0; | ||
| 106 | 52 | 171µs | next SEARCH; # look again | ||
| 107 | } | ||||
| 108 | |||||
| 109 | 5 | 11µs | 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 | 5 | 36µs | return 0; | ||
| 123 | } | ||||
| 124 | |||||
| 125 | 1 | 5µs | 1; | ||
sub Cache::Memcached::GetParser::CORE:match; # opcode | |||||
sub Cache::Memcached::GetParser::CORE:sysread; # opcode |