perldebguts.pod
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 878 行 · 第 1/3 页
POD
878 行
# Literals EXACT sv Match this string (preceded by length). EXACTF sv Match this string, folded (prec. by length). EXACTFL sv Match this string, folded in locale (w/len). # Do nothing NOTHING no Match empty string. # A variant of above which delimits a group, thus stops optimizations TAIL no Match empty string. Can jump here from outside. # STAR,PLUS '?', and complex '*' and '+', are implemented as circular # BRANCH structures using BACK. Simple cases (one character # per match) are implemented with STAR and PLUS for speed # and to minimize recursive plunges. # STAR node Match this (simple) thing 0 or more times. PLUS node Match this (simple) thing 1 or more times. CURLY sv 2 Match this simple thing {n,m} times. CURLYN no 2 Match next-after-this simple thing # {n,m} times, set parens. CURLYM no 2 Match this medium-complex thing {n,m} times. CURLYX sv 2 Match this complex thing {n,m} times. # This terminator creates a loop structure for CURLYX WHILEM no Do curly processing and see if rest matches. # OPEN,CLOSE,GROUPP ...are numbered at compile time. OPEN num 1 Mark this point in input as start of #n. CLOSE num 1 Analogous to OPEN. REF num 1 Match some already matched string REFF num 1 Match already matched string, folded REFFL num 1 Match already matched string, folded in loc. # grouping assertions IFMATCH off 1 2 Succeeds if the following matches. UNLESSM off 1 2 Fails if the following matches. SUSPEND off 1 1 "Independent" sub-regex. IFTHEN off 1 1 Switch, should be preceded by switcher . GROUPP num 1 Whether the group matched. # Support for long regex LONGJMP off 1 1 Jump far away. BRANCHJ off 1 1 BRANCH with long offset. # The heavy worker EVAL evl 1 Execute some Perl code. # Modifiers MINMOD no Next operator is not greedy. LOGICAL no Next opcode should set the flag only. # This is not used yet RENUM off 1 1 Group with independently numbered parens. # This is not really a node, but an optimized away piece of a "long" node. # To simplify debugging output, we mark it as if it were a node OPTIMIZED off Placeholder for dump.=for unprinted-creditsNext section M-J. Dominus (mjd-perl-patch+@plover.com) 20010421Following the optimizer information is a dump of the offset/lengthtable, here split across several lines: Offsets: [45] 1[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 5[1] 0[0] 12[1] 0[0] 6[1] 0[0] 7[1] 0[0] 9[1] 8[1] 0[0] 10[1] 0[0] 11[1] 0[0] 12[0] 12[0] 13[1] 0[0] 14[4] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 0[0] 18[1] 0[0] 19[1] 20[0] The first line here indicates that the offset/length table contains 45entries. Each entry is a pair of integers, denoted by C<offset[length]>.Entries are numbered starting with 1, so entry #1 here is C<1[4]> andentry #12 is C<5[1]>. C<1[4]> indicates that the node labeled C<1:>(the C<1: ANYOF[bc]>) begins at character position 1 in thepre-compiled form of the regex, and has a length of 4 characters.C<5[1]> in position 12 indicates that the node labeled C<12:>(the C<< 12: EXACT <d> >>) begins at character position 5 in thepre-compiled form of the regex, and has a length of 1 character.C<12[1]> in position 14 indicates that the node labeled C<14:>(the C<< 14: CURLYX[0] {1,32767} >>) begins at character position 12 in thepre-compiled form of the regex, and has a length of 1 character---thatis, it corresponds to the C<+> symbol in the precompiled regex.C<0[0]> items indicate that there is no corresponding node.=head2 Run-time outputFirst of all, when doing a match, one may get no run-time output evenif debugging is enabled. This means that the regex engine was neverentered and that all of the job was therefore done by the optimizer.If the regex engine was entered, the output may look like this: Matching `[bc]d(ef*g)+h[ij]k$' against `abcdefg__gh__' Setting an EVAL scope, savestack=3 2 <ab> <cdefg__gh_> | 1: ANYOF 3 <abc> <defg__gh_> | 11: EXACT <d> 4 <abcd> <efg__gh_> | 13: CURLYX {1,32767} 4 <abcd> <efg__gh_> | 26: WHILEM 0 out of 1..32767 cc=effff31c 4 <abcd> <efg__gh_> | 15: OPEN1 4 <abcd> <efg__gh_> | 17: EXACT <e> 5 <abcde> <fg__gh_> | 19: STAR EXACT <f> can match 1 times out of 32767... Setting an EVAL scope, savestack=3 6 <bcdef> <g__gh__> | 22: EXACT <g> 7 <bcdefg> <__gh__> | 24: CLOSE1 7 <bcdefg> <__gh__> | 26: WHILEM 1 out of 1..32767 cc=effff31c Setting an EVAL scope, savestack=12 7 <bcdefg> <__gh__> | 15: OPEN1 7 <bcdefg> <__gh__> | 17: EXACT <e> restoring \1 to 4(4)..7 failed, try continuation... 7 <bcdefg> <__gh__> | 27: NOTHING 7 <bcdefg> <__gh__> | 28: EXACT <h> failed... failed...The most significant information in the output is about the particular I<node>of the compiled regex that is currently being tested against the target string.The format of these lines isC< >I<STRING-OFFSET> <I<PRE-STRING>> <I<POST-STRING>> |I<ID>: I<TYPE>The I<TYPE> info is indented with respect to the backtracking level.Other incidental information appears interspersed within.=head1 Debugging Perl memory usagePerl is a profligate wastrel when it comes to memory use. Thereis a saying that to estimate memory usage of Perl, assume a reasonablealgorithm for memory allocation, multiply that estimate by 10, andwhile you still may miss the mark, at least you won't be quite soastonished. This is not absolutely true, but may provide a goodgrasp of what happens.Assume that an integer cannot take less than 20 bytes of memory, afloat cannot take less than 24 bytes, a string cannot take lessthan 32 bytes (all these examples assume 32-bit architectures, theresult are quite a bit worse on 64-bit architectures). If a variableis accessed in two of three different ways (which require an integer,a float, or a string), the memory footprint may increase yet another20 bytes. A sloppy malloc(3) implementation can inflate thesenumbers dramatically.On the opposite end of the scale, a declaration like sub foo;may take up to 500 bytes of memory, depending on which release of Perlyou're running.Anecdotal estimates of source-to-compiled code bloat suggest aneightfold increase. This means that the compiled form of reasonable(normally commented, properly indented etc.) code will takeabout eight times more space in memory than the code tookon disk.The B<-DL> command-line switch is obsolete since circa Perl 5.6.0(it was available only if Perl was built with C<-DDEBUGGING>).The switch was used to track Perl's memory allocations and possiblememory leaks. These days the use of malloc debugging tools likeF<Purify> or F<valgrind> is suggested instead. See alsoL<perlhack/PERL_MEM_LOG>.One way to find out how much memory is being used by Perl datastructures is to install the Devel::Size module from CPAN: it givesyou the minimum number of bytes required to store a particular datastructure. Please be mindful of the difference between the size()and total_size().If Perl has been compiled using Perl's malloc you can analyze Perlmemory usage by setting the $ENV{PERL_DEBUG_MSTATS}.=head2 Using C<$ENV{PERL_DEBUG_MSTATS}>If your perl is using Perl's malloc() and was compiled with thenecessary switches (this is the default), then it will print memoryusage statistics after compiling your code when C<< $ENV{PERL_DEBUG_MSTATS}> 1 >>, and before termination of the program when C<<$ENV{PERL_DEBUG_MSTATS} >= 1 >>. The report format is similar tothe following example: $ PERL_DEBUG_MSTATS=2 perl -e "require Carp" Memory allocation statistics after compilation: (buckets 4(4)..8188(8192) 14216 free: 130 117 28 7 9 0 2 2 1 0 0 437 61 36 0 5 60924 used: 125 137 161 55 7 8 6 16 2 0 1 74 109 304 84 20 Total sbrk(): 77824/21:119. Odd ends: pad+heads+chain+tail: 0+636+0+2048. Memory allocation statistics after execution: (buckets 4(4)..8188(8192) 30888 free: 245 78 85 13 6 2 1 3 2 0 1 315 162 39 42 11 175816 used: 265 176 1112 111 26 22 11 27 2 1 1 196 178 1066 798 39 Total sbrk(): 215040/47:145. Odd ends: pad+heads+chain+tail: 0+2192+0+6144.It is possible to ask for such a statistic at arbitrary points inyour execution using the mstat() function out of the standardDevel::Peek module.Here is some explanation of that format:=over 4=item C<buckets SMALLEST(APPROX)..GREATEST(APPROX)>Perl's malloc() uses bucketed allocations. Every request is roundedup to the closest bucket size available, and a bucket is taken fromthe pool of buckets of that size.The line above describes the limits of buckets currently in use.Each bucket has two sizes: memory footprint and the maximal sizeof user data that can fit into this bucket. Suppose in the aboveexample that the smallest bucket were size 4. The biggest bucketwould have usable size 8188, and the memory footprint would be 8192.In a Perl built for debugging, some buckets may have negative usablesize. This means that these buckets cannot (and will not) be used.For larger buckets, the memory footprint may be one page greaterthan a power of 2. If so, case the corresponding power of two isprinted in the C<APPROX> field above.=item Free/UsedThe 1 or 2 rows of numbers following that correspond to the numberof buckets of each size between C<SMALLEST> and C<GREATEST>. Inthe first row, the sizes (memory footprints) of buckets are powersof two--or possibly one page greater. In the second row, if present,the memory footprints of the buckets are between the memory footprintsof two buckets "above".For example, suppose under the previous example, the memory footprintswere free: 8 16 32 64 128 256 512 1024 2048 4096 8192 4 12 24 48 80With non-C<DEBUGGING> perl, the buckets starting from C<128> havea 4-byte overhead, and thus an 8192-long bucket may take up to8188-byte allocations.=item C<Total sbrk(): SBRKed/SBRKs:CONTINUOUS>The first two fields give the total amount of memory perl sbrk(2)ed(ess-broken? :-) and number of sbrk(2)s used. The third number iswhat perl thinks about continuity of returned chunks. So long asthis number is positive, malloc() will assume that it is probablethat sbrk(2) will provide continuous memory.Memory allocated by external libraries is not counted.=item C<pad: 0>The amount of sbrk(2)ed memory needed to keep buckets aligned.=item C<heads: 2192>Although memory overhead of bigger buckets is kept inside the bucket, forsmaller buckets, it is kept in separate areas. This field gives thetotal size of these areas.=item C<chain: 0>malloc() may want to subdivide a bigger bucket into smaller buckets.If only a part of the deceased bucket is left unsubdivided, the restis kept as an element of a linked list. This field gives the totalsize of these chunks.=item C<tail: 6144>To minimize the number of sbrk(2)s, malloc() asks for more memory. Thisfield gives the size of the yet unused part, which is sbrk(2)ed, butnever touched.=back=head1 SEE ALSOL<perldebug>,L<perlguts>,L<perlrun>L<re>,andL<Devel::DProf>.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?