Merge lp:~percona-toolkit-dev/percona-toolkit/version-in-all-bash-tools-bug-821502 into lp:percona-toolkit/2.2
- version-in-all-bash-tools-bug-821502
- Merge into 2.2
Proposed by
Daniel Nichter
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Daniel Nichter | ||||
Approved revision: | 571 | ||||
Merged at revision: | 569 | ||||
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/version-in-all-bash-tools-bug-821502 | ||||
Merge into: | lp:percona-toolkit/2.2 | ||||
Diff against target: |
3154 lines (+2722/-166) 6 files modified
bin/pt-align (+1094/-1) bin/pt-mext (+552/-42) bin/pt-pmp (+572/-92) bin/pt-sift (+481/-28) t/pt-mext/pt-mext.t (+21/-1) t/pt-pmp/pt-pmp.t (+2/-2) |
||||
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/version-in-all-bash-tools-bug-821502 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email: mp+157232@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/pt-align' | |||
2 | --- bin/pt-align 2013-03-14 17:20:35 +0000 | |||
3 | +++ bin/pt-align 2013-04-04 21:05:27 +0000 | |||
4 | @@ -4,6 +4,1084 @@ | |||
5 | 4 | # See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal | 4 | # See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal |
6 | 5 | # notices and disclaimers. | 5 | # notices and disclaimers. |
7 | 6 | 6 | ||
8 | 7 | use strict; | ||
9 | 8 | use warnings FATAL => 'all'; | ||
10 | 9 | |||
11 | 10 | # This tool is "fat-packed": most of its dependent modules are embedded | ||
12 | 11 | # in this file. Setting %INC to this file for each module makes Perl aware | ||
13 | 12 | # of this so it will not try to load the module from @INC. See the tool's | ||
14 | 13 | # documentation for a full list of dependencies. | ||
15 | 14 | BEGIN { | ||
16 | 15 | $INC{$_} = __FILE__ for map { (my $pkg = "$_.pm") =~ s!::!/!g; $pkg } (qw( | ||
17 | 16 | OptionParser | ||
18 | 17 | )); | ||
19 | 18 | } | ||
20 | 19 | |||
21 | 20 | # ########################################################################### | ||
22 | 21 | # OptionParser package | ||
23 | 22 | # This package is a copy without comments from the original. The original | ||
24 | 23 | # with comments and its test file can be found in the Bazaar repository at, | ||
25 | 24 | # lib/OptionParser.pm | ||
26 | 25 | # t/lib/OptionParser.t | ||
27 | 26 | # See https://launchpad.net/percona-toolkit for more information. | ||
28 | 27 | # ########################################################################### | ||
29 | 28 | { | ||
30 | 29 | package OptionParser; | ||
31 | 30 | |||
32 | 31 | use strict; | ||
33 | 32 | use warnings FATAL => 'all'; | ||
34 | 33 | use English qw(-no_match_vars); | ||
35 | 34 | use constant PTDEBUG => $ENV{PTDEBUG} || 0; | ||
36 | 35 | |||
37 | 36 | use List::Util qw(max); | ||
38 | 37 | use Getopt::Long; | ||
39 | 38 | use Data::Dumper; | ||
40 | 39 | |||
41 | 40 | my $POD_link_re = '[LC]<"?([^">]+)"?>'; | ||
42 | 41 | |||
43 | 42 | sub new { | ||
44 | 43 | my ( $class, %args ) = @_; | ||
45 | 44 | my @required_args = qw(); | ||
46 | 45 | foreach my $arg ( @required_args ) { | ||
47 | 46 | die "I need a $arg argument" unless $args{$arg}; | ||
48 | 47 | } | ||
49 | 48 | |||
50 | 49 | my ($program_name) = $PROGRAM_NAME =~ m/([.A-Za-z-]+)$/; | ||
51 | 50 | $program_name ||= $PROGRAM_NAME; | ||
52 | 51 | my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; | ||
53 | 52 | |||
54 | 53 | my %attributes = ( | ||
55 | 54 | 'type' => 1, | ||
56 | 55 | 'short form' => 1, | ||
57 | 56 | 'group' => 1, | ||
58 | 57 | 'default' => 1, | ||
59 | 58 | 'cumulative' => 1, | ||
60 | 59 | 'negatable' => 1, | ||
61 | 60 | ); | ||
62 | 61 | |||
63 | 62 | my $self = { | ||
64 | 63 | head1 => 'OPTIONS', # These args are used internally | ||
65 | 64 | skip_rules => 0, # to instantiate another Option- | ||
66 | 65 | item => '--(.*)', # Parser obj that parses the | ||
67 | 66 | attributes => \%attributes, # DSN OPTIONS section. Tools | ||
68 | 67 | parse_attributes => \&_parse_attribs, # don't tinker with these args. | ||
69 | 68 | |||
70 | 69 | %args, | ||
71 | 70 | |||
72 | 71 | strict => 1, # disabled by a special rule | ||
73 | 72 | program_name => $program_name, | ||
74 | 73 | opts => {}, | ||
75 | 74 | got_opts => 0, | ||
76 | 75 | short_opts => {}, | ||
77 | 76 | defaults => {}, | ||
78 | 77 | groups => {}, | ||
79 | 78 | allowed_groups => {}, | ||
80 | 79 | errors => [], | ||
81 | 80 | rules => [], # desc of rules for --help | ||
82 | 81 | mutex => [], # rule: opts are mutually exclusive | ||
83 | 82 | atleast1 => [], # rule: at least one opt is required | ||
84 | 83 | disables => {}, # rule: opt disables other opts | ||
85 | 84 | defaults_to => {}, # rule: opt defaults to value of other opt | ||
86 | 85 | DSNParser => undef, | ||
87 | 86 | default_files => [ | ||
88 | 87 | "/etc/percona-toolkit/percona-toolkit.conf", | ||
89 | 88 | "/etc/percona-toolkit/$program_name.conf", | ||
90 | 89 | "$home/.percona-toolkit.conf", | ||
91 | 90 | "$home/.$program_name.conf", | ||
92 | 91 | ], | ||
93 | 92 | types => { | ||
94 | 93 | string => 's', # standard Getopt type | ||
95 | 94 | int => 'i', # standard Getopt type | ||
96 | 95 | float => 'f', # standard Getopt type | ||
97 | 96 | Hash => 'H', # hash, formed from a comma-separated list | ||
98 | 97 | hash => 'h', # hash as above, but only if a value is given | ||
99 | 98 | Array => 'A', # array, similar to Hash | ||
100 | 99 | array => 'a', # array, similar to hash | ||
101 | 100 | DSN => 'd', # DSN | ||
102 | 101 | size => 'z', # size with kMG suffix (powers of 2^10) | ||
103 | 102 | time => 'm', # time, with an optional suffix of s/h/m/d | ||
104 | 103 | }, | ||
105 | 104 | }; | ||
106 | 105 | |||
107 | 106 | return bless $self, $class; | ||
108 | 107 | } | ||
109 | 108 | |||
110 | 109 | sub get_specs { | ||
111 | 110 | my ( $self, $file ) = @_; | ||
112 | 111 | $file ||= $self->{file} || __FILE__; | ||
113 | 112 | my @specs = $self->_pod_to_specs($file); | ||
114 | 113 | $self->_parse_specs(@specs); | ||
115 | 114 | |||
116 | 115 | open my $fh, "<", $file or die "Cannot open $file: $OS_ERROR"; | ||
117 | 116 | my $contents = do { local $/ = undef; <$fh> }; | ||
118 | 117 | close $fh; | ||
119 | 118 | if ( $contents =~ m/^=head1 DSN OPTIONS/m ) { | ||
120 | 119 | PTDEBUG && _d('Parsing DSN OPTIONS'); | ||
121 | 120 | my $dsn_attribs = { | ||
122 | 121 | dsn => 1, | ||
123 | 122 | copy => 1, | ||
124 | 123 | }; | ||
125 | 124 | my $parse_dsn_attribs = sub { | ||
126 | 125 | my ( $self, $option, $attribs ) = @_; | ||
127 | 126 | map { | ||
128 | 127 | my $val = $attribs->{$_}; | ||
129 | 128 | if ( $val ) { | ||
130 | 129 | $val = $val eq 'yes' ? 1 | ||
131 | 130 | : $val eq 'no' ? 0 | ||
132 | 131 | : $val; | ||
133 | 132 | $attribs->{$_} = $val; | ||
134 | 133 | } | ||
135 | 134 | } keys %$attribs; | ||
136 | 135 | return { | ||
137 | 136 | key => $option, | ||
138 | 137 | %$attribs, | ||
139 | 138 | }; | ||
140 | 139 | }; | ||
141 | 140 | my $dsn_o = new OptionParser( | ||
142 | 141 | description => 'DSN OPTIONS', | ||
143 | 142 | head1 => 'DSN OPTIONS', | ||
144 | 143 | dsn => 0, # XXX don't infinitely recurse! | ||
145 | 144 | item => '\* (.)', # key opts are a single character | ||
146 | 145 | skip_rules => 1, # no rules before opts | ||
147 | 146 | attributes => $dsn_attribs, | ||
148 | 147 | parse_attributes => $parse_dsn_attribs, | ||
149 | 148 | ); | ||
150 | 149 | my @dsn_opts = map { | ||
151 | 150 | my $opts = { | ||
152 | 151 | key => $_->{spec}->{key}, | ||
153 | 152 | dsn => $_->{spec}->{dsn}, | ||
154 | 153 | copy => $_->{spec}->{copy}, | ||
155 | 154 | desc => $_->{desc}, | ||
156 | 155 | }; | ||
157 | 156 | $opts; | ||
158 | 157 | } $dsn_o->_pod_to_specs($file); | ||
159 | 158 | $self->{DSNParser} = DSNParser->new(opts => \@dsn_opts); | ||
160 | 159 | } | ||
161 | 160 | |||
162 | 161 | if ( $contents =~ m/^=head1 VERSION\n\n^(.+)$/m ) { | ||
163 | 162 | $self->{version} = $1; | ||
164 | 163 | PTDEBUG && _d($self->{version}); | ||
165 | 164 | } | ||
166 | 165 | |||
167 | 166 | return; | ||
168 | 167 | } | ||
169 | 168 | |||
170 | 169 | sub DSNParser { | ||
171 | 170 | my ( $self ) = @_; | ||
172 | 171 | return $self->{DSNParser}; | ||
173 | 172 | }; | ||
174 | 173 | |||
175 | 174 | sub get_defaults_files { | ||
176 | 175 | my ( $self ) = @_; | ||
177 | 176 | return @{$self->{default_files}}; | ||
178 | 177 | } | ||
179 | 178 | |||
180 | 179 | sub _pod_to_specs { | ||
181 | 180 | my ( $self, $file ) = @_; | ||
182 | 181 | $file ||= $self->{file} || __FILE__; | ||
183 | 182 | open my $fh, '<', $file or die "Cannot open $file: $OS_ERROR"; | ||
184 | 183 | |||
185 | 184 | my @specs = (); | ||
186 | 185 | my @rules = (); | ||
187 | 186 | my $para; | ||
188 | 187 | |||
189 | 188 | local $INPUT_RECORD_SEPARATOR = ''; | ||
190 | 189 | while ( $para = <$fh> ) { | ||
191 | 190 | next unless $para =~ m/^=head1 $self->{head1}/; | ||
192 | 191 | last; | ||
193 | 192 | } | ||
194 | 193 | |||
195 | 194 | while ( $para = <$fh> ) { | ||
196 | 195 | last if $para =~ m/^=over/; | ||
197 | 196 | next if $self->{skip_rules}; | ||
198 | 197 | chomp $para; | ||
199 | 198 | $para =~ s/\s+/ /g; | ||
200 | 199 | $para =~ s/$POD_link_re/$1/go; | ||
201 | 200 | PTDEBUG && _d('Option rule:', $para); | ||
202 | 201 | push @rules, $para; | ||
203 | 202 | } | ||
204 | 203 | |||
205 | 204 | die "POD has no $self->{head1} section" unless $para; | ||
206 | 205 | |||
207 | 206 | do { | ||
208 | 207 | if ( my ($option) = $para =~ m/^=item $self->{item}/ ) { | ||
209 | 208 | chomp $para; | ||
210 | 209 | PTDEBUG && _d($para); | ||
211 | 210 | my %attribs; | ||
212 | 211 | |||
213 | 212 | $para = <$fh>; # read next paragraph, possibly attributes | ||
214 | 213 | |||
215 | 214 | if ( $para =~ m/: / ) { # attributes | ||
216 | 215 | $para =~ s/\s+\Z//g; | ||
217 | 216 | %attribs = map { | ||
218 | 217 | my ( $attrib, $val) = split(/: /, $_); | ||
219 | 218 | die "Unrecognized attribute for --$option: $attrib" | ||
220 | 219 | unless $self->{attributes}->{$attrib}; | ||
221 | 220 | ($attrib, $val); | ||
222 | 221 | } split(/; /, $para); | ||
223 | 222 | if ( $attribs{'short form'} ) { | ||
224 | 223 | $attribs{'short form'} =~ s/-//; | ||
225 | 224 | } | ||
226 | 225 | $para = <$fh>; # read next paragraph, probably short help desc | ||
227 | 226 | } | ||
228 | 227 | else { | ||
229 | 228 | PTDEBUG && _d('Option has no attributes'); | ||
230 | 229 | } | ||
231 | 230 | |||
232 | 231 | $para =~ s/\s+\Z//g; | ||
233 | 232 | $para =~ s/\s+/ /g; | ||
234 | 233 | $para =~ s/$POD_link_re/$1/go; | ||
235 | 234 | |||
236 | 235 | $para =~ s/\.(?:\n.*| [A-Z].*|\Z)//s; | ||
237 | 236 | PTDEBUG && _d('Short help:', $para); | ||
238 | 237 | |||
239 | 238 | die "No description after option spec $option" if $para =~ m/^=item/; | ||
240 | 239 | |||
241 | 240 | if ( my ($base_option) = $option =~ m/^\[no\](.*)/ ) { | ||
242 | 241 | $option = $base_option; | ||
243 | 242 | $attribs{'negatable'} = 1; | ||
244 | 243 | } | ||
245 | 244 | |||
246 | 245 | push @specs, { | ||
247 | 246 | spec => $self->{parse_attributes}->($self, $option, \%attribs), | ||
248 | 247 | desc => $para | ||
249 | 248 | . (defined $attribs{default} ? " (default $attribs{default})" : ''), | ||
250 | 249 | group => ($attribs{'group'} ? $attribs{'group'} : 'default'), | ||
251 | 250 | }; | ||
252 | 251 | } | ||
253 | 252 | while ( $para = <$fh> ) { | ||
254 | 253 | last unless $para; | ||
255 | 254 | if ( $para =~ m/^=head1/ ) { | ||
256 | 255 | $para = undef; # Can't 'last' out of a do {} block. | ||
257 | 256 | last; | ||
258 | 257 | } | ||
259 | 258 | last if $para =~ m/^=item /; | ||
260 | 259 | } | ||
261 | 260 | } while ( $para ); | ||
262 | 261 | |||
263 | 262 | die "No valid specs in $self->{head1}" unless @specs; | ||
264 | 263 | |||
265 | 264 | close $fh; | ||
266 | 265 | return @specs, @rules; | ||
267 | 266 | } | ||
268 | 267 | |||
269 | 268 | sub _parse_specs { | ||
270 | 269 | my ( $self, @specs ) = @_; | ||
271 | 270 | my %disables; # special rule that requires deferred checking | ||
272 | 271 | |||
273 | 272 | foreach my $opt ( @specs ) { | ||
274 | 273 | if ( ref $opt ) { # It's an option spec, not a rule. | ||
275 | 274 | PTDEBUG && _d('Parsing opt spec:', | ||
276 | 275 | map { ($_, '=>', $opt->{$_}) } keys %$opt); | ||
277 | 276 | |||
278 | 277 | my ( $long, $short ) = $opt->{spec} =~ m/^([\w-]+)(?:\|([^!+=]*))?/; | ||
279 | 278 | if ( !$long ) { | ||
280 | 279 | die "Cannot parse long option from spec $opt->{spec}"; | ||
281 | 280 | } | ||
282 | 281 | $opt->{long} = $long; | ||
283 | 282 | |||
284 | 283 | die "Duplicate long option --$long" if exists $self->{opts}->{$long}; | ||
285 | 284 | $self->{opts}->{$long} = $opt; | ||
286 | 285 | |||
287 | 286 | if ( length $long == 1 ) { | ||
288 | 287 | PTDEBUG && _d('Long opt', $long, 'looks like short opt'); | ||
289 | 288 | $self->{short_opts}->{$long} = $long; | ||
290 | 289 | } | ||
291 | 290 | |||
292 | 291 | if ( $short ) { | ||
293 | 292 | die "Duplicate short option -$short" | ||
294 | 293 | if exists $self->{short_opts}->{$short}; | ||
295 | 294 | $self->{short_opts}->{$short} = $long; | ||
296 | 295 | $opt->{short} = $short; | ||
297 | 296 | } | ||
298 | 297 | else { | ||
299 | 298 | $opt->{short} = undef; | ||
300 | 299 | } | ||
301 | 300 | |||
302 | 301 | $opt->{is_negatable} = $opt->{spec} =~ m/!/ ? 1 : 0; | ||
303 | 302 | $opt->{is_cumulative} = $opt->{spec} =~ m/\+/ ? 1 : 0; | ||
304 | 303 | $opt->{is_required} = $opt->{desc} =~ m/required/ ? 1 : 0; | ||
305 | 304 | |||
306 | 305 | $opt->{group} ||= 'default'; | ||
307 | 306 | $self->{groups}->{ $opt->{group} }->{$long} = 1; | ||
308 | 307 | |||
309 | 308 | $opt->{value} = undef; | ||
310 | 309 | $opt->{got} = 0; | ||
311 | 310 | |||
312 | 311 | my ( $type ) = $opt->{spec} =~ m/=(.)/; | ||
313 | 312 | $opt->{type} = $type; | ||
314 | 313 | PTDEBUG && _d($long, 'type:', $type); | ||
315 | 314 | |||
316 | 315 | |||
317 | 316 | $opt->{spec} =~ s/=./=s/ if ( $type && $type =~ m/[HhAadzm]/ ); | ||
318 | 317 | |||
319 | 318 | if ( (my ($def) = $opt->{desc} =~ m/default\b(?: ([^)]+))?/) ) { | ||
320 | 319 | $self->{defaults}->{$long} = defined $def ? $def : 1; | ||
321 | 320 | PTDEBUG && _d($long, 'default:', $def); | ||
322 | 321 | } | ||
323 | 322 | |||
324 | 323 | if ( $long eq 'config' ) { | ||
325 | 324 | $self->{defaults}->{$long} = join(',', $self->get_defaults_files()); | ||
326 | 325 | } | ||
327 | 326 | |||
328 | 327 | if ( (my ($dis) = $opt->{desc} =~ m/(disables .*)/) ) { | ||
329 | 328 | $disables{$long} = $dis; | ||
330 | 329 | PTDEBUG && _d('Deferring check of disables rule for', $opt, $dis); | ||
331 | 330 | } | ||
332 | 331 | |||
333 | 332 | $self->{opts}->{$long} = $opt; | ||
334 | 333 | } | ||
335 | 334 | else { # It's an option rule, not a spec. | ||
336 | 335 | PTDEBUG && _d('Parsing rule:', $opt); | ||
337 | 336 | push @{$self->{rules}}, $opt; | ||
338 | 337 | my @participants = $self->_get_participants($opt); | ||
339 | 338 | my $rule_ok = 0; | ||
340 | 339 | |||
341 | 340 | if ( $opt =~ m/mutually exclusive|one and only one/ ) { | ||
342 | 341 | $rule_ok = 1; | ||
343 | 342 | push @{$self->{mutex}}, \@participants; | ||
344 | 343 | PTDEBUG && _d(@participants, 'are mutually exclusive'); | ||
345 | 344 | } | ||
346 | 345 | if ( $opt =~ m/at least one|one and only one/ ) { | ||
347 | 346 | $rule_ok = 1; | ||
348 | 347 | push @{$self->{atleast1}}, \@participants; | ||
349 | 348 | PTDEBUG && _d(@participants, 'require at least one'); | ||
350 | 349 | } | ||
351 | 350 | if ( $opt =~ m/default to/ ) { | ||
352 | 351 | $rule_ok = 1; | ||
353 | 352 | $self->{defaults_to}->{$participants[0]} = $participants[1]; | ||
354 | 353 | PTDEBUG && _d($participants[0], 'defaults to', $participants[1]); | ||
355 | 354 | } | ||
356 | 355 | if ( $opt =~ m/restricted to option groups/ ) { | ||
357 | 356 | $rule_ok = 1; | ||
358 | 357 | my ($groups) = $opt =~ m/groups ([\w\s\,]+)/; | ||
359 | 358 | my @groups = split(',', $groups); | ||
360 | 359 | %{$self->{allowed_groups}->{$participants[0]}} = map { | ||
361 | 360 | s/\s+//; | ||
362 | 361 | $_ => 1; | ||
363 | 362 | } @groups; | ||
364 | 363 | } | ||
365 | 364 | if( $opt =~ m/accepts additional command-line arguments/ ) { | ||
366 | 365 | $rule_ok = 1; | ||
367 | 366 | $self->{strict} = 0; | ||
368 | 367 | PTDEBUG && _d("Strict mode disabled by rule"); | ||
369 | 368 | } | ||
370 | 369 | |||
371 | 370 | die "Unrecognized option rule: $opt" unless $rule_ok; | ||
372 | 371 | } | ||
373 | 372 | } | ||
374 | 373 | |||
375 | 374 | foreach my $long ( keys %disables ) { | ||
376 | 375 | my @participants = $self->_get_participants($disables{$long}); | ||
377 | 376 | $self->{disables}->{$long} = \@participants; | ||
378 | 377 | PTDEBUG && _d('Option', $long, 'disables', @participants); | ||
379 | 378 | } | ||
380 | 379 | |||
381 | 380 | return; | ||
382 | 381 | } | ||
383 | 382 | |||
384 | 383 | sub _get_participants { | ||
385 | 384 | my ( $self, $str ) = @_; | ||
386 | 385 | my @participants; | ||
387 | 386 | foreach my $long ( $str =~ m/--(?:\[no\])?([\w-]+)/g ) { | ||
388 | 387 | die "Option --$long does not exist while processing rule $str" | ||
389 | 388 | unless exists $self->{opts}->{$long}; | ||
390 | 389 | push @participants, $long; | ||
391 | 390 | } | ||
392 | 391 | PTDEBUG && _d('Participants for', $str, ':', @participants); | ||
393 | 392 | return @participants; | ||
394 | 393 | } | ||
395 | 394 | |||
396 | 395 | sub opts { | ||
397 | 396 | my ( $self ) = @_; | ||
398 | 397 | my %opts = %{$self->{opts}}; | ||
399 | 398 | return %opts; | ||
400 | 399 | } | ||
401 | 400 | |||
402 | 401 | sub short_opts { | ||
403 | 402 | my ( $self ) = @_; | ||
404 | 403 | my %short_opts = %{$self->{short_opts}}; | ||
405 | 404 | return %short_opts; | ||
406 | 405 | } | ||
407 | 406 | |||
408 | 407 | sub set_defaults { | ||
409 | 408 | my ( $self, %defaults ) = @_; | ||
410 | 409 | $self->{defaults} = {}; | ||
411 | 410 | foreach my $long ( keys %defaults ) { | ||
412 | 411 | die "Cannot set default for nonexistent option $long" | ||
413 | 412 | unless exists $self->{opts}->{$long}; | ||
414 | 413 | $self->{defaults}->{$long} = $defaults{$long}; | ||
415 | 414 | PTDEBUG && _d('Default val for', $long, ':', $defaults{$long}); | ||
416 | 415 | } | ||
417 | 416 | return; | ||
418 | 417 | } | ||
419 | 418 | |||
420 | 419 | sub get_defaults { | ||
421 | 420 | my ( $self ) = @_; | ||
422 | 421 | return $self->{defaults}; | ||
423 | 422 | } | ||
424 | 423 | |||
425 | 424 | sub get_groups { | ||
426 | 425 | my ( $self ) = @_; | ||
427 | 426 | return $self->{groups}; | ||
428 | 427 | } | ||
429 | 428 | |||
430 | 429 | sub _set_option { | ||
431 | 430 | my ( $self, $opt, $val ) = @_; | ||
432 | 431 | my $long = exists $self->{opts}->{$opt} ? $opt | ||
433 | 432 | : exists $self->{short_opts}->{$opt} ? $self->{short_opts}->{$opt} | ||
434 | 433 | : die "Getopt::Long gave a nonexistent option: $opt"; | ||
435 | 434 | |||
436 | 435 | $opt = $self->{opts}->{$long}; | ||
437 | 436 | if ( $opt->{is_cumulative} ) { | ||
438 | 437 | $opt->{value}++; | ||
439 | 438 | } | ||
440 | 439 | else { | ||
441 | 440 | $opt->{value} = $val; | ||
442 | 441 | } | ||
443 | 442 | $opt->{got} = 1; | ||
444 | 443 | PTDEBUG && _d('Got option', $long, '=', $val); | ||
445 | 444 | } | ||
446 | 445 | |||
447 | 446 | sub get_opts { | ||
448 | 447 | my ( $self ) = @_; | ||
449 | 448 | |||
450 | 449 | foreach my $long ( keys %{$self->{opts}} ) { | ||
451 | 450 | $self->{opts}->{$long}->{got} = 0; | ||
452 | 451 | $self->{opts}->{$long}->{value} | ||
453 | 452 | = exists $self->{defaults}->{$long} ? $self->{defaults}->{$long} | ||
454 | 453 | : $self->{opts}->{$long}->{is_cumulative} ? 0 | ||
455 | 454 | : undef; | ||
456 | 455 | } | ||
457 | 456 | $self->{got_opts} = 0; | ||
458 | 457 | |||
459 | 458 | $self->{errors} = []; | ||
460 | 459 | |||
461 | 460 | if ( @ARGV && $ARGV[0] eq "--config" ) { | ||
462 | 461 | shift @ARGV; | ||
463 | 462 | $self->_set_option('config', shift @ARGV); | ||
464 | 463 | } | ||
465 | 464 | if ( $self->has('config') ) { | ||
466 | 465 | my @extra_args; | ||
467 | 466 | foreach my $filename ( split(',', $self->get('config')) ) { | ||
468 | 467 | eval { | ||
469 | 468 | push @extra_args, $self->_read_config_file($filename); | ||
470 | 469 | }; | ||
471 | 470 | if ( $EVAL_ERROR ) { | ||
472 | 471 | if ( $self->got('config') ) { | ||
473 | 472 | die $EVAL_ERROR; | ||
474 | 473 | } | ||
475 | 474 | elsif ( PTDEBUG ) { | ||
476 | 475 | _d($EVAL_ERROR); | ||
477 | 476 | } | ||
478 | 477 | } | ||
479 | 478 | } | ||
480 | 479 | unshift @ARGV, @extra_args; | ||
481 | 480 | } | ||
482 | 481 | |||
483 | 482 | Getopt::Long::Configure('no_ignore_case', 'bundling'); | ||
484 | 483 | GetOptions( | ||
485 | 484 | map { $_->{spec} => sub { $self->_set_option(@_); } } | ||
486 | 485 | grep { $_->{long} ne 'config' } # --config is handled specially above. | ||
487 | 486 | values %{$self->{opts}} | ||
488 | 487 | ) or $self->save_error('Error parsing options'); | ||
489 | 488 | |||
490 | 489 | if ( exists $self->{opts}->{version} && $self->{opts}->{version}->{got} ) { | ||
491 | 490 | if ( $self->{version} ) { | ||
492 | 491 | print $self->{version}, "\n"; | ||
493 | 492 | } | ||
494 | 493 | else { | ||
495 | 494 | print "Error parsing version. See the VERSION section of the tool's documentation.\n"; | ||
496 | 495 | } | ||
497 | 496 | exit 1; | ||
498 | 497 | } | ||
499 | 498 | |||
500 | 499 | if ( @ARGV && $self->{strict} ) { | ||
501 | 500 | $self->save_error("Unrecognized command-line options @ARGV"); | ||
502 | 501 | } | ||
503 | 502 | |||
504 | 503 | foreach my $mutex ( @{$self->{mutex}} ) { | ||
505 | 504 | my @set = grep { $self->{opts}->{$_}->{got} } @$mutex; | ||
506 | 505 | if ( @set > 1 ) { | ||
507 | 506 | my $err = join(', ', map { "--$self->{opts}->{$_}->{long}" } | ||
508 | 507 | @{$mutex}[ 0 .. scalar(@$mutex) - 2] ) | ||
509 | 508 | . ' and --'.$self->{opts}->{$mutex->[-1]}->{long} | ||
510 | 509 | . ' are mutually exclusive.'; | ||
511 | 510 | $self->save_error($err); | ||
512 | 511 | } | ||
513 | 512 | } | ||
514 | 513 | |||
515 | 514 | foreach my $required ( @{$self->{atleast1}} ) { | ||
516 | 515 | my @set = grep { $self->{opts}->{$_}->{got} } @$required; | ||
517 | 516 | if ( @set == 0 ) { | ||
518 | 517 | my $err = join(', ', map { "--$self->{opts}->{$_}->{long}" } | ||
519 | 518 | @{$required}[ 0 .. scalar(@$required) - 2] ) | ||
520 | 519 | .' or --'.$self->{opts}->{$required->[-1]}->{long}; | ||
521 | 520 | $self->save_error("Specify at least one of $err"); | ||
522 | 521 | } | ||
523 | 522 | } | ||
524 | 523 | |||
525 | 524 | $self->_check_opts( keys %{$self->{opts}} ); | ||
526 | 525 | $self->{got_opts} = 1; | ||
527 | 526 | return; | ||
528 | 527 | } | ||
529 | 528 | |||
530 | 529 | sub _check_opts { | ||
531 | 530 | my ( $self, @long ) = @_; | ||
532 | 531 | my $long_last = scalar @long; | ||
533 | 532 | while ( @long ) { | ||
534 | 533 | foreach my $i ( 0..$#long ) { | ||
535 | 534 | my $long = $long[$i]; | ||
536 | 535 | next unless $long; | ||
537 | 536 | my $opt = $self->{opts}->{$long}; | ||
538 | 537 | if ( $opt->{got} ) { | ||
539 | 538 | if ( exists $self->{disables}->{$long} ) { | ||
540 | 539 | my @disable_opts = @{$self->{disables}->{$long}}; | ||
541 | 540 | map { $self->{opts}->{$_}->{value} = undef; } @disable_opts; | ||
542 | 541 | PTDEBUG && _d('Unset options', @disable_opts, | ||
543 | 542 | 'because', $long,'disables them'); | ||
544 | 543 | } | ||
545 | 544 | |||
546 | 545 | if ( exists $self->{allowed_groups}->{$long} ) { | ||
547 | 546 | |||
548 | 547 | my @restricted_groups = grep { | ||
549 | 548 | !exists $self->{allowed_groups}->{$long}->{$_} | ||
550 | 549 | } keys %{$self->{groups}}; | ||
551 | 550 | |||
552 | 551 | my @restricted_opts; | ||
553 | 552 | foreach my $restricted_group ( @restricted_groups ) { | ||
554 | 553 | RESTRICTED_OPT: | ||
555 | 554 | foreach my $restricted_opt ( | ||
556 | 555 | keys %{$self->{groups}->{$restricted_group}} ) | ||
557 | 556 | { | ||
558 | 557 | next RESTRICTED_OPT if $restricted_opt eq $long; | ||
559 | 558 | push @restricted_opts, $restricted_opt | ||
560 | 559 | if $self->{opts}->{$restricted_opt}->{got}; | ||
561 | 560 | } | ||
562 | 561 | } | ||
563 | 562 | |||
564 | 563 | if ( @restricted_opts ) { | ||
565 | 564 | my $err; | ||
566 | 565 | if ( @restricted_opts == 1 ) { | ||
567 | 566 | $err = "--$restricted_opts[0]"; | ||
568 | 567 | } | ||
569 | 568 | else { | ||
570 | 569 | $err = join(', ', | ||
571 | 570 | map { "--$self->{opts}->{$_}->{long}" } | ||
572 | 571 | grep { $_ } | ||
573 | 572 | @restricted_opts[0..scalar(@restricted_opts) - 2] | ||
574 | 573 | ) | ||
575 | 574 | . ' or --'.$self->{opts}->{$restricted_opts[-1]}->{long}; | ||
576 | 575 | } | ||
577 | 576 | $self->save_error("--$long is not allowed with $err"); | ||
578 | 577 | } | ||
579 | 578 | } | ||
580 | 579 | |||
581 | 580 | } | ||
582 | 581 | elsif ( $opt->{is_required} ) { | ||
583 | 582 | $self->save_error("Required option --$long must be specified"); | ||
584 | 583 | } | ||
585 | 584 | |||
586 | 585 | $self->_validate_type($opt); | ||
587 | 586 | if ( $opt->{parsed} ) { | ||
588 | 587 | delete $long[$i]; | ||
589 | 588 | } | ||
590 | 589 | else { | ||
591 | 590 | PTDEBUG && _d('Temporarily failed to parse', $long); | ||
592 | 591 | } | ||
593 | 592 | } | ||
594 | 593 | |||
595 | 594 | die "Failed to parse options, possibly due to circular dependencies" | ||
596 | 595 | if @long == $long_last; | ||
597 | 596 | $long_last = @long; | ||
598 | 597 | } | ||
599 | 598 | |||
600 | 599 | return; | ||
601 | 600 | } | ||
602 | 601 | |||
603 | 602 | sub _validate_type { | ||
604 | 603 | my ( $self, $opt ) = @_; | ||
605 | 604 | return unless $opt; | ||
606 | 605 | |||
607 | 606 | if ( !$opt->{type} ) { | ||
608 | 607 | $opt->{parsed} = 1; | ||
609 | 608 | return; | ||
610 | 609 | } | ||
611 | 610 | |||
612 | 611 | my $val = $opt->{value}; | ||
613 | 612 | |||
614 | 613 | if ( $val && $opt->{type} eq 'm' ) { # type time | ||
615 | 614 | PTDEBUG && _d('Parsing option', $opt->{long}, 'as a time value'); | ||
616 | 615 | my ( $prefix, $num, $suffix ) = $val =~ m/([+-]?)(\d+)([a-z])?$/; | ||
617 | 616 | if ( !$suffix ) { | ||
618 | 617 | my ( $s ) = $opt->{desc} =~ m/\(suffix (.)\)/; | ||
619 | 618 | $suffix = $s || 's'; | ||
620 | 619 | PTDEBUG && _d('No suffix given; using', $suffix, 'for', | ||
621 | 620 | $opt->{long}, '(value:', $val, ')'); | ||
622 | 621 | } | ||
623 | 622 | if ( $suffix =~ m/[smhd]/ ) { | ||
624 | 623 | $val = $suffix eq 's' ? $num # Seconds | ||
625 | 624 | : $suffix eq 'm' ? $num * 60 # Minutes | ||
626 | 625 | : $suffix eq 'h' ? $num * 3600 # Hours | ||
627 | 626 | : $num * 86400; # Days | ||
628 | 627 | $opt->{value} = ($prefix || '') . $val; | ||
629 | 628 | PTDEBUG && _d('Setting option', $opt->{long}, 'to', $val); | ||
630 | 629 | } | ||
631 | 630 | else { | ||
632 | 631 | $self->save_error("Invalid time suffix for --$opt->{long}"); | ||
633 | 632 | } | ||
634 | 633 | } | ||
635 | 634 | elsif ( $val && $opt->{type} eq 'd' ) { # type DSN | ||
636 | 635 | PTDEBUG && _d('Parsing option', $opt->{long}, 'as a DSN'); | ||
637 | 636 | my $prev = {}; | ||
638 | 637 | my $from_key = $self->{defaults_to}->{ $opt->{long} }; | ||
639 | 638 | if ( $from_key ) { | ||
640 | 639 | PTDEBUG && _d($opt->{long}, 'DSN copies from', $from_key, 'DSN'); | ||
641 | 640 | if ( $self->{opts}->{$from_key}->{parsed} ) { | ||
642 | 641 | $prev = $self->{opts}->{$from_key}->{value}; | ||
643 | 642 | } | ||
644 | 643 | else { | ||
645 | 644 | PTDEBUG && _d('Cannot parse', $opt->{long}, 'until', | ||
646 | 645 | $from_key, 'parsed'); | ||
647 | 646 | return; | ||
648 | 647 | } | ||
649 | 648 | } | ||
650 | 649 | my $defaults = $self->{DSNParser}->parse_options($self); | ||
651 | 650 | $opt->{value} = $self->{DSNParser}->parse($val, $prev, $defaults); | ||
652 | 651 | } | ||
653 | 652 | elsif ( $val && $opt->{type} eq 'z' ) { # type size | ||
654 | 653 | PTDEBUG && _d('Parsing option', $opt->{long}, 'as a size value'); | ||
655 | 654 | $self->_parse_size($opt, $val); | ||
656 | 655 | } | ||
657 | 656 | elsif ( $opt->{type} eq 'H' || (defined $val && $opt->{type} eq 'h') ) { | ||
658 | 657 | $opt->{value} = { map { $_ => 1 } split(/(?<!\\),\s*/, ($val || '')) }; | ||
659 | 658 | } | ||
660 | 659 | elsif ( $opt->{type} eq 'A' || (defined $val && $opt->{type} eq 'a') ) { | ||
661 | 660 | $opt->{value} = [ split(/(?<!\\),\s*/, ($val || '')) ]; | ||
662 | 661 | } | ||
663 | 662 | else { | ||
664 | 663 | PTDEBUG && _d('Nothing to validate for option', | ||
665 | 664 | $opt->{long}, 'type', $opt->{type}, 'value', $val); | ||
666 | 665 | } | ||
667 | 666 | |||
668 | 667 | $opt->{parsed} = 1; | ||
669 | 668 | return; | ||
670 | 669 | } | ||
671 | 670 | |||
672 | 671 | sub get { | ||
673 | 672 | my ( $self, $opt ) = @_; | ||
674 | 673 | my $long = (length $opt == 1 ? $self->{short_opts}->{$opt} : $opt); | ||
675 | 674 | die "Option $opt does not exist" | ||
676 | 675 | unless $long && exists $self->{opts}->{$long}; | ||
677 | 676 | return $self->{opts}->{$long}->{value}; | ||
678 | 677 | } | ||
679 | 678 | |||
680 | 679 | sub got { | ||
681 | 680 | my ( $self, $opt ) = @_; | ||
682 | 681 | my $long = (length $opt == 1 ? $self->{short_opts}->{$opt} : $opt); | ||
683 | 682 | die "Option $opt does not exist" | ||
684 | 683 | unless $long && exists $self->{opts}->{$long}; | ||
685 | 684 | return $self->{opts}->{$long}->{got}; | ||
686 | 685 | } | ||
687 | 686 | |||
688 | 687 | sub has { | ||
689 | 688 | my ( $self, $opt ) = @_; | ||
690 | 689 | my $long = (length $opt == 1 ? $self->{short_opts}->{$opt} : $opt); | ||
691 | 690 | return defined $long ? exists $self->{opts}->{$long} : 0; | ||
692 | 691 | } | ||
693 | 692 | |||
694 | 693 | sub set { | ||
695 | 694 | my ( $self, $opt, $val ) = @_; | ||
696 | 695 | my $long = (length $opt == 1 ? $self->{short_opts}->{$opt} : $opt); | ||
697 | 696 | die "Option $opt does not exist" | ||
698 | 697 | unless $long && exists $self->{opts}->{$long}; | ||
699 | 698 | $self->{opts}->{$long}->{value} = $val; | ||
700 | 699 | return; | ||
701 | 700 | } | ||
702 | 701 | |||
703 | 702 | sub save_error { | ||
704 | 703 | my ( $self, $error ) = @_; | ||
705 | 704 | push @{$self->{errors}}, $error; | ||
706 | 705 | return; | ||
707 | 706 | } | ||
708 | 707 | |||
709 | 708 | sub errors { | ||
710 | 709 | my ( $self ) = @_; | ||
711 | 710 | return $self->{errors}; | ||
712 | 711 | } | ||
713 | 712 | |||
714 | 713 | sub usage { | ||
715 | 714 | my ( $self ) = @_; | ||
716 | 715 | warn "No usage string is set" unless $self->{usage}; # XXX | ||
717 | 716 | return "Usage: " . ($self->{usage} || '') . "\n"; | ||
718 | 717 | } | ||
719 | 718 | |||
720 | 719 | sub descr { | ||
721 | 720 | my ( $self ) = @_; | ||
722 | 721 | warn "No description string is set" unless $self->{description}; # XXX | ||
723 | 722 | my $descr = ($self->{description} || $self->{program_name} || '') | ||
724 | 723 | . " For more details, please use the --help option, " | ||
725 | 724 | . "or try 'perldoc $PROGRAM_NAME' " | ||
726 | 725 | . "for complete documentation."; | ||
727 | 726 | $descr = join("\n", $descr =~ m/(.{0,80})(?:\s+|$)/g) | ||
728 | 727 | unless $ENV{DONT_BREAK_LINES}; | ||
729 | 728 | $descr =~ s/ +$//mg; | ||
730 | 729 | return $descr; | ||
731 | 730 | } | ||
732 | 731 | |||
733 | 732 | sub usage_or_errors { | ||
734 | 733 | my ( $self, $file, $return ) = @_; | ||
735 | 734 | $file ||= $self->{file} || __FILE__; | ||
736 | 735 | |||
737 | 736 | if ( !$self->{description} || !$self->{usage} ) { | ||
738 | 737 | PTDEBUG && _d("Getting description and usage from SYNOPSIS in", $file); | ||
739 | 738 | my %synop = $self->_parse_synopsis($file); | ||
740 | 739 | $self->{description} ||= $synop{description}; | ||
741 | 740 | $self->{usage} ||= $synop{usage}; | ||
742 | 741 | PTDEBUG && _d("Description:", $self->{description}, | ||
743 | 742 | "\nUsage:", $self->{usage}); | ||
744 | 743 | } | ||
745 | 744 | |||
746 | 745 | if ( $self->{opts}->{help}->{got} ) { | ||
747 | 746 | print $self->print_usage() or die "Cannot print usage: $OS_ERROR"; | ||
748 | 747 | exit 0 unless $return; | ||
749 | 748 | } | ||
750 | 749 | elsif ( scalar @{$self->{errors}} ) { | ||
751 | 750 | print $self->print_errors() or die "Cannot print errors: $OS_ERROR"; | ||
752 | 751 | exit 1 unless $return; | ||
753 | 752 | } | ||
754 | 753 | |||
755 | 754 | return; | ||
756 | 755 | } | ||
757 | 756 | |||
758 | 757 | sub print_errors { | ||
759 | 758 | my ( $self ) = @_; | ||
760 | 759 | my $usage = $self->usage() . "\n"; | ||
761 | 760 | if ( (my @errors = @{$self->{errors}}) ) { | ||
762 | 761 | $usage .= join("\n * ", 'Errors in command-line arguments:', @errors) | ||
763 | 762 | . "\n"; | ||
764 | 763 | } | ||
765 | 764 | return $usage . "\n" . $self->descr(); | ||
766 | 765 | } | ||
767 | 766 | |||
768 | 767 | sub print_usage { | ||
769 | 768 | my ( $self ) = @_; | ||
770 | 769 | die "Run get_opts() before print_usage()" unless $self->{got_opts}; | ||
771 | 770 | my @opts = values %{$self->{opts}}; | ||
772 | 771 | |||
773 | 772 | my $maxl = max( | ||
774 | 773 | map { | ||
775 | 774 | length($_->{long}) # option long name | ||
776 | 775 | + ($_->{is_negatable} ? 4 : 0) # "[no]" if opt is negatable | ||
777 | 776 | + ($_->{type} ? 2 : 0) # "=x" where x is the opt type | ||
778 | 777 | } | ||
779 | 778 | @opts); | ||
780 | 779 | |||
781 | 780 | my $maxs = max(0, | ||
782 | 781 | map { | ||
783 | 782 | length($_) | ||
784 | 783 | + ($self->{opts}->{$_}->{is_negatable} ? 4 : 0) | ||
785 | 784 | + ($self->{opts}->{$_}->{type} ? 2 : 0) | ||
786 | 785 | } | ||
787 | 786 | values %{$self->{short_opts}}); | ||
788 | 787 | |||
789 | 788 | my $lcol = max($maxl, ($maxs + 3)); | ||
790 | 789 | my $rcol = 80 - $lcol - 6; | ||
791 | 790 | my $rpad = ' ' x ( 80 - $rcol ); | ||
792 | 791 | |||
793 | 792 | $maxs = max($lcol - 3, $maxs); | ||
794 | 793 | |||
795 | 794 | my $usage = $self->descr() . "\n" . $self->usage(); | ||
796 | 795 | |||
797 | 796 | my @groups = reverse sort grep { $_ ne 'default'; } keys %{$self->{groups}}; | ||
798 | 797 | push @groups, 'default'; | ||
799 | 798 | |||
800 | 799 | foreach my $group ( reverse @groups ) { | ||
801 | 800 | $usage .= "\n".($group eq 'default' ? 'Options' : $group).":\n\n"; | ||
802 | 801 | foreach my $opt ( | ||
803 | 802 | sort { $a->{long} cmp $b->{long} } | ||
804 | 803 | grep { $_->{group} eq $group } | ||
805 | 804 | @opts ) | ||
806 | 805 | { | ||
807 | 806 | my $long = $opt->{is_negatable} ? "[no]$opt->{long}" : $opt->{long}; | ||
808 | 807 | my $short = $opt->{short}; | ||
809 | 808 | my $desc = $opt->{desc}; | ||
810 | 809 | |||
811 | 810 | $long .= $opt->{type} ? "=$opt->{type}" : ""; | ||
812 | 811 | |||
813 | 812 | if ( $opt->{type} && $opt->{type} eq 'm' ) { | ||
814 | 813 | my ($s) = $desc =~ m/\(suffix (.)\)/; | ||
815 | 814 | $s ||= 's'; | ||
816 | 815 | $desc =~ s/\s+\(suffix .\)//; | ||
817 | 816 | $desc .= ". Optional suffix s=seconds, m=minutes, h=hours, " | ||
818 | 817 | . "d=days; if no suffix, $s is used."; | ||
819 | 818 | } | ||
820 | 819 | $desc = join("\n$rpad", grep { $_ } $desc =~ m/(.{0,$rcol}(?!\W))(?:\s+|(?<=\W)|$)/g); | ||
821 | 820 | $desc =~ s/ +$//mg; | ||
822 | 821 | if ( $short ) { | ||
823 | 822 | $usage .= sprintf(" --%-${maxs}s -%s %s\n", $long, $short, $desc); | ||
824 | 823 | } | ||
825 | 824 | else { | ||
826 | 825 | $usage .= sprintf(" --%-${lcol}s %s\n", $long, $desc); | ||
827 | 826 | } | ||
828 | 827 | } | ||
829 | 828 | } | ||
830 | 829 | |||
831 | 830 | $usage .= "\nOption types: s=string, i=integer, f=float, h/H/a/A=comma-separated list, d=DSN, z=size, m=time\n"; | ||
832 | 831 | |||
833 | 832 | if ( (my @rules = @{$self->{rules}}) ) { | ||
834 | 833 | $usage .= "\nRules:\n\n"; | ||
835 | 834 | $usage .= join("\n", map { " $_" } @rules) . "\n"; | ||
836 | 835 | } | ||
837 | 836 | if ( $self->{DSNParser} ) { | ||
838 | 837 | $usage .= "\n" . $self->{DSNParser}->usage(); | ||
839 | 838 | } | ||
840 | 839 | $usage .= "\nOptions and values after processing arguments:\n\n"; | ||
841 | 840 | foreach my $opt ( sort { $a->{long} cmp $b->{long} } @opts ) { | ||
842 | 841 | my $val = $opt->{value}; | ||
843 | 842 | my $type = $opt->{type} || ''; | ||
844 | 843 | my $bool = $opt->{spec} =~ m/^[\w-]+(?:\|[\w-])?!?$/; | ||
845 | 844 | $val = $bool ? ( $val ? 'TRUE' : 'FALSE' ) | ||
846 | 845 | : !defined $val ? '(No value)' | ||
847 | 846 | : $type eq 'd' ? $self->{DSNParser}->as_string($val) | ||
848 | 847 | : $type =~ m/H|h/ ? join(',', sort keys %$val) | ||
849 | 848 | : $type =~ m/A|a/ ? join(',', @$val) | ||
850 | 849 | : $val; | ||
851 | 850 | $usage .= sprintf(" --%-${lcol}s %s\n", $opt->{long}, $val); | ||
852 | 851 | } | ||
853 | 852 | return $usage; | ||
854 | 853 | } | ||
855 | 854 | |||
856 | 855 | sub prompt_noecho { | ||
857 | 856 | shift @_ if ref $_[0] eq __PACKAGE__; | ||
858 | 857 | my ( $prompt ) = @_; | ||
859 | 858 | local $OUTPUT_AUTOFLUSH = 1; | ||
860 | 859 | print $prompt | ||
861 | 860 | or die "Cannot print: $OS_ERROR"; | ||
862 | 861 | my $response; | ||
863 | 862 | eval { | ||
864 | 863 | require Term::ReadKey; | ||
865 | 864 | Term::ReadKey::ReadMode('noecho'); | ||
866 | 865 | chomp($response = <STDIN>); | ||
867 | 866 | Term::ReadKey::ReadMode('normal'); | ||
868 | 867 | print "\n" | ||
869 | 868 | or die "Cannot print: $OS_ERROR"; | ||
870 | 869 | }; | ||
871 | 870 | if ( $EVAL_ERROR ) { | ||
872 | 871 | die "Cannot read response; is Term::ReadKey installed? $EVAL_ERROR"; | ||
873 | 872 | } | ||
874 | 873 | return $response; | ||
875 | 874 | } | ||
876 | 875 | |||
877 | 876 | sub _read_config_file { | ||
878 | 877 | my ( $self, $filename ) = @_; | ||
879 | 878 | open my $fh, "<", $filename or die "Cannot open $filename: $OS_ERROR\n"; | ||
880 | 879 | my @args; | ||
881 | 880 | my $prefix = '--'; | ||
882 | 881 | my $parse = 1; | ||
883 | 882 | |||
884 | 883 | LINE: | ||
885 | 884 | while ( my $line = <$fh> ) { | ||
886 | 885 | chomp $line; | ||
887 | 886 | next LINE if $line =~ m/^\s*(?:\#|\;|$)/; | ||
888 | 887 | $line =~ s/\s+#.*$//g; | ||
889 | 888 | $line =~ s/^\s+|\s+$//g; | ||
890 | 889 | if ( $line eq '--' ) { | ||
891 | 890 | $prefix = ''; | ||
892 | 891 | $parse = 0; | ||
893 | 892 | next LINE; | ||
894 | 893 | } | ||
895 | 894 | if ( $parse | ||
896 | 895 | && (my($opt, $arg) = $line =~ m/^\s*([^=\s]+?)(?:\s*=\s*(.*?)\s*)?$/) | ||
897 | 896 | ) { | ||
898 | 897 | push @args, grep { defined $_ } ("$prefix$opt", $arg); | ||
899 | 898 | } | ||
900 | 899 | elsif ( $line =~ m/./ ) { | ||
901 | 900 | push @args, $line; | ||
902 | 901 | } | ||
903 | 902 | else { | ||
904 | 903 | die "Syntax error in file $filename at line $INPUT_LINE_NUMBER"; | ||
905 | 904 | } | ||
906 | 905 | } | ||
907 | 906 | close $fh; | ||
908 | 907 | return @args; | ||
909 | 908 | } | ||
910 | 909 | |||
911 | 910 | sub read_para_after { | ||
912 | 911 | my ( $self, $file, $regex ) = @_; | ||
913 | 912 | open my $fh, "<", $file or die "Can't open $file: $OS_ERROR"; | ||
914 | 913 | local $INPUT_RECORD_SEPARATOR = ''; | ||
915 | 914 | my $para; | ||
916 | 915 | while ( $para = <$fh> ) { | ||
917 | 916 | next unless $para =~ m/^=pod$/m; | ||
918 | 917 | last; | ||
919 | 918 | } | ||
920 | 919 | while ( $para = <$fh> ) { | ||
921 | 920 | next unless $para =~ m/$regex/; | ||
922 | 921 | last; | ||
923 | 922 | } | ||
924 | 923 | $para = <$fh>; | ||
925 | 924 | chomp($para); | ||
926 | 925 | close $fh or die "Can't close $file: $OS_ERROR"; | ||
927 | 926 | return $para; | ||
928 | 927 | } | ||
929 | 928 | |||
930 | 929 | sub clone { | ||
931 | 930 | my ( $self ) = @_; | ||
932 | 931 | |||
933 | 932 | my %clone = map { | ||
934 | 933 | my $hashref = $self->{$_}; | ||
935 | 934 | my $val_copy = {}; | ||
936 | 935 | foreach my $key ( keys %$hashref ) { | ||
937 | 936 | my $ref = ref $hashref->{$key}; | ||
938 | 937 | $val_copy->{$key} = !$ref ? $hashref->{$key} | ||
939 | 938 | : $ref eq 'HASH' ? { %{$hashref->{$key}} } | ||
940 | 939 | : $ref eq 'ARRAY' ? [ @{$hashref->{$key}} ] | ||
941 | 940 | : $hashref->{$key}; | ||
942 | 941 | } | ||
943 | 942 | $_ => $val_copy; | ||
944 | 943 | } qw(opts short_opts defaults); | ||
945 | 944 | |||
946 | 945 | foreach my $scalar ( qw(got_opts) ) { | ||
947 | 946 | $clone{$scalar} = $self->{$scalar}; | ||
948 | 947 | } | ||
949 | 948 | |||
950 | 949 | return bless \%clone; | ||
951 | 950 | } | ||
952 | 951 | |||
953 | 952 | sub _parse_size { | ||
954 | 953 | my ( $self, $opt, $val ) = @_; | ||
955 | 954 | |||
956 | 955 | if ( lc($val || '') eq 'null' ) { | ||
957 | 956 | PTDEBUG && _d('NULL size for', $opt->{long}); | ||
958 | 957 | $opt->{value} = 'null'; | ||
959 | 958 | return; | ||
960 | 959 | } | ||
961 | 960 | |||
962 | 961 | my %factor_for = (k => 1_024, M => 1_048_576, G => 1_073_741_824); | ||
963 | 962 | my ($pre, $num, $factor) = $val =~ m/^([+-])?(\d+)([kMG])?$/; | ||
964 | 963 | if ( defined $num ) { | ||
965 | 964 | if ( $factor ) { | ||
966 | 965 | $num *= $factor_for{$factor}; | ||
967 | 966 | PTDEBUG && _d('Setting option', $opt->{y}, | ||
968 | 967 | 'to num', $num, '* factor', $factor); | ||
969 | 968 | } | ||
970 | 969 | $opt->{value} = ($pre || '') . $num; | ||
971 | 970 | } | ||
972 | 971 | else { | ||
973 | 972 | $self->save_error("Invalid size for --$opt->{long}: $val"); | ||
974 | 973 | } | ||
975 | 974 | return; | ||
976 | 975 | } | ||
977 | 976 | |||
978 | 977 | sub _parse_attribs { | ||
979 | 978 | my ( $self, $option, $attribs ) = @_; | ||
980 | 979 | my $types = $self->{types}; | ||
981 | 980 | return $option | ||
982 | 981 | . ($attribs->{'short form'} ? '|' . $attribs->{'short form'} : '' ) | ||
983 | 982 | . ($attribs->{'negatable'} ? '!' : '' ) | ||
984 | 983 | . ($attribs->{'cumulative'} ? '+' : '' ) | ||
985 | 984 | . ($attribs->{'type'} ? '=' . $types->{$attribs->{type}} : '' ); | ||
986 | 985 | } | ||
987 | 986 | |||
988 | 987 | sub _parse_synopsis { | ||
989 | 988 | my ( $self, $file ) = @_; | ||
990 | 989 | $file ||= $self->{file} || __FILE__; | ||
991 | 990 | PTDEBUG && _d("Parsing SYNOPSIS in", $file); | ||
992 | 991 | |||
993 | 992 | local $INPUT_RECORD_SEPARATOR = ''; # read paragraphs | ||
994 | 993 | open my $fh, "<", $file or die "Cannot open $file: $OS_ERROR"; | ||
995 | 994 | my $para; | ||
996 | 995 | 1 while defined($para = <$fh>) && $para !~ m/^=head1 SYNOPSIS/; | ||
997 | 996 | die "$file does not contain a SYNOPSIS section" unless $para; | ||
998 | 997 | my @synop; | ||
999 | 998 | for ( 1..2 ) { # 1 for the usage, 2 for the description | ||
1000 | 999 | my $para = <$fh>; | ||
1001 | 1000 | push @synop, $para; | ||
1002 | 1001 | } | ||
1003 | 1002 | close $fh; | ||
1004 | 1003 | PTDEBUG && _d("Raw SYNOPSIS text:", @synop); | ||
1005 | 1004 | my ($usage, $desc) = @synop; | ||
1006 | 1005 | die "The SYNOPSIS section in $file is not formatted properly" | ||
1007 | 1006 | unless $usage && $desc; | ||
1008 | 1007 | |||
1009 | 1008 | $usage =~ s/^\s*Usage:\s+(.+)/$1/; | ||
1010 | 1009 | chomp $usage; | ||
1011 | 1010 | |||
1012 | 1011 | $desc =~ s/\n/ /g; | ||
1013 | 1012 | $desc =~ s/\s{2,}/ /g; | ||
1014 | 1013 | $desc =~ s/\. ([A-Z][a-z])/. $1/g; | ||
1015 | 1014 | $desc =~ s/\s+$//; | ||
1016 | 1015 | |||
1017 | 1016 | return ( | ||
1018 | 1017 | description => $desc, | ||
1019 | 1018 | usage => $usage, | ||
1020 | 1019 | ); | ||
1021 | 1020 | }; | ||
1022 | 1021 | |||
1023 | 1022 | sub set_vars { | ||
1024 | 1023 | my ($self, $file) = @_; | ||
1025 | 1024 | $file ||= $self->{file} || __FILE__; | ||
1026 | 1025 | |||
1027 | 1026 | my %user_vars; | ||
1028 | 1027 | my $user_vars = $self->has('set-vars') ? $self->get('set-vars') : undef; | ||
1029 | 1028 | if ( $user_vars ) { | ||
1030 | 1029 | foreach my $var_val ( @$user_vars ) { | ||
1031 | 1030 | my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/; | ||
1032 | 1031 | die "Invalid --set-vars value: $var_val\n" unless $var && $val; | ||
1033 | 1032 | $user_vars{$var} = { | ||
1034 | 1033 | val => $val, | ||
1035 | 1034 | default => 0, | ||
1036 | 1035 | }; | ||
1037 | 1036 | } | ||
1038 | 1037 | } | ||
1039 | 1038 | |||
1040 | 1039 | my %default_vars; | ||
1041 | 1040 | my $default_vars = $self->read_para_after($file, qr/MAGIC_set_vars/); | ||
1042 | 1041 | if ( $default_vars ) { | ||
1043 | 1042 | %default_vars = map { | ||
1044 | 1043 | my $var_val = $_; | ||
1045 | 1044 | my ($var, $val) = $var_val =~ m/([^\s=]+)=(\S+)/; | ||
1046 | 1045 | die "Invalid --set-vars value: $var_val\n" unless $var && $val; | ||
1047 | 1046 | $var => { | ||
1048 | 1047 | val => $val, | ||
1049 | 1048 | default => 1, | ||
1050 | 1049 | }; | ||
1051 | 1050 | } split("\n", $default_vars); | ||
1052 | 1051 | } | ||
1053 | 1052 | |||
1054 | 1053 | my %vars = ( | ||
1055 | 1054 | %default_vars, # first the tool's defaults | ||
1056 | 1055 | %user_vars, # then the user's which overwrite the defaults | ||
1057 | 1056 | ); | ||
1058 | 1057 | PTDEBUG && _d('--set-vars:', Dumper(\%vars)); | ||
1059 | 1058 | return \%vars; | ||
1060 | 1059 | } | ||
1061 | 1060 | |||
1062 | 1061 | sub _d { | ||
1063 | 1062 | my ($package, undef, $line) = caller 0; | ||
1064 | 1063 | @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } | ||
1065 | 1064 | map { defined $_ ? $_ : 'undef' } | ||
1066 | 1065 | @_; | ||
1067 | 1066 | print STDERR "# $package:$line $PID ", join(' ', @_), "\n"; | ||
1068 | 1067 | } | ||
1069 | 1068 | |||
1070 | 1069 | if ( PTDEBUG ) { | ||
1071 | 1070 | print '# ', $^X, ' ', $], "\n"; | ||
1072 | 1071 | if ( my $uname = `uname -a` ) { | ||
1073 | 1072 | $uname =~ s/\s+/ /g; | ||
1074 | 1073 | print "# $uname\n"; | ||
1075 | 1074 | } | ||
1076 | 1075 | print '# Arguments: ', | ||
1077 | 1076 | join(' ', map { my $a = "_[$_]_"; $a =~ s/\n/\n# /g; $a; } @ARGV), "\n"; | ||
1078 | 1077 | } | ||
1079 | 1078 | |||
1080 | 1079 | 1; | ||
1081 | 1080 | } | ||
1082 | 1081 | # ########################################################################### | ||
1083 | 1082 | # End OptionParser package | ||
1084 | 1083 | # ########################################################################### | ||
1085 | 1084 | |||
1086 | 7 | # ########################################################################### | 1085 | # ########################################################################### |
1087 | 8 | # This is a combination of modules and programs in one -- a runnable module. | 1086 | # This is a combination of modules and programs in one -- a runnable module. |
1088 | 9 | # http://www.perl.com/pub/a/2006/07/13/lightning-articles.html?page=last | 1087 | # http://www.perl.com/pub/a/2006/07/13/lightning-articles.html?page=last |
1089 | @@ -25,6 +1103,11 @@ | |||
1090 | 25 | 1103 | ||
1091 | 26 | @ARGV = @_; # set global ARGV for this package | 1104 | @ARGV = @_; # set global ARGV for this package |
1092 | 27 | 1105 | ||
1093 | 1106 | my $o = OptionParser->new(); | ||
1094 | 1107 | $o->get_specs(); | ||
1095 | 1108 | $o->get_opts(); | ||
1096 | 1109 | $o->usage_or_errors(); | ||
1097 | 1110 | |||
1098 | 28 | # Read all lines | 1111 | # Read all lines |
1099 | 29 | my @lines; | 1112 | my @lines; |
1100 | 30 | my %word_count; | 1113 | my %word_count; |
1101 | @@ -130,7 +1213,17 @@ | |||
1102 | 130 | 1213 | ||
1103 | 131 | =head1 OPTIONS | 1214 | =head1 OPTIONS |
1104 | 132 | 1215 | ||
1106 | 133 | This tool does not have any command-line options. | 1216 | =over |
1107 | 1217 | |||
1108 | 1218 | =item --help | ||
1109 | 1219 | |||
1110 | 1220 | Show help and exit. | ||
1111 | 1221 | |||
1112 | 1222 | =item --version | ||
1113 | 1223 | |||
1114 | 1224 | Show version and exit. | ||
1115 | 1225 | |||
1116 | 1226 | =back | ||
1117 | 134 | 1227 | ||
1118 | 135 | =head1 ENVIRONMENT | 1228 | =head1 ENVIRONMENT |
1119 | 136 | 1229 | ||
1120 | 137 | 1230 | ||
1121 | === modified file 'bin/pt-mext' | |||
1122 | --- bin/pt-mext 2013-03-14 17:20:35 +0000 | |||
1123 | +++ bin/pt-mext 2013-04-04 21:05:27 +0000 | |||
1124 | @@ -4,18 +4,53 @@ | |||
1125 | 4 | # See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal | 4 | # See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal |
1126 | 5 | # notices and disclaimers. | 5 | # notices and disclaimers. |
1127 | 6 | 6 | ||
1134 | 7 | usage() { | 7 | # ########################################################################### |
1135 | 8 | if [ "${OPT_ERR}" ]; then | 8 | # log_warn_die package |
1136 | 9 | echo "${OPT_ERR}" >&2 | 9 | # This package is a copy without comments from the original. The original |
1137 | 10 | fi | 10 | # with comments and its test file can be found in the Bazaar repository at, |
1138 | 11 | echo "Usage: pt-mext [OPTIONS] -- COMMAND" >&2 | 11 | # lib/bash/log_warn_die.sh |
1139 | 12 | echo "For more information, 'man pt-mext' or 'perldoc $0'" >&2 | 12 | # t/lib/bash/log_warn_die.sh |
1140 | 13 | # See https://launchpad.net/percona-toolkit for more information. | ||
1141 | 14 | # ########################################################################### | ||
1142 | 15 | |||
1143 | 16 | |||
1144 | 17 | set -u | ||
1145 | 18 | |||
1146 | 19 | PTFUNCNAME="" | ||
1147 | 20 | PTDEBUG="${PTDEBUG:-""}" | ||
1148 | 21 | EXIT_STATUS=0 | ||
1149 | 22 | |||
1150 | 23 | ts() { | ||
1151 | 24 | TS=$(date +%F-%T | tr ':-' '_') | ||
1152 | 25 | echo "$TS $*" | ||
1153 | 26 | } | ||
1154 | 27 | |||
1155 | 28 | info() { | ||
1156 | 29 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
1157 | 30 | } | ||
1158 | 31 | |||
1159 | 32 | log() { | ||
1160 | 33 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" | ||
1161 | 34 | } | ||
1162 | 35 | |||
1163 | 36 | warn() { | ||
1164 | 37 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 | ||
1165 | 38 | EXIT_STATUS=1 | ||
1166 | 39 | } | ||
1167 | 40 | |||
1168 | 41 | die() { | ||
1169 | 42 | ts "$*" >&2 | ||
1170 | 43 | EXIT_STATUS=1 | ||
1171 | 13 | exit 1 | 44 | exit 1 |
1172 | 14 | } | 45 | } |
1173 | 15 | 46 | ||
1177 | 16 | if [ -z "$1" ]; then | 47 | _d () { |
1178 | 17 | usage; | 48 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 |
1179 | 18 | fi | 49 | } |
1180 | 50 | |||
1181 | 51 | # ########################################################################### | ||
1182 | 52 | # End log_warn_die package | ||
1183 | 53 | # ########################################################################### | ||
1184 | 19 | 54 | ||
1185 | 20 | # ########################################################################### | 55 | # ########################################################################### |
1186 | 21 | # tmpdir package | 56 | # tmpdir package |
1187 | @@ -58,51 +93,497 @@ | |||
1188 | 58 | # End tmpdir package | 93 | # End tmpdir package |
1189 | 59 | # ########################################################################### | 94 | # ########################################################################### |
1190 | 60 | 95 | ||
1191 | 96 | # ########################################################################### | ||
1192 | 97 | # parse_options package | ||
1193 | 98 | # This package is a copy without comments from the original. The original | ||
1194 | 99 | # with comments and its test file can be found in the Bazaar repository at, | ||
1195 | 100 | # lib/bash/parse_options.sh | ||
1196 | 101 | # t/lib/bash/parse_options.sh | ||
1197 | 102 | # See https://launchpad.net/percona-toolkit for more information. | ||
1198 | 103 | # ########################################################################### | ||
1199 | 104 | |||
1200 | 105 | |||
1201 | 106 | |||
1202 | 107 | |||
1203 | 108 | |||
1204 | 109 | set -u | ||
1205 | 110 | |||
1206 | 111 | ARGV="" # Non-option args (probably input files) | ||
1207 | 112 | EXT_ARGV="" # Everything after -- (args for an external command) | ||
1208 | 113 | HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV | ||
1209 | 114 | OPT_ERRS=0 # How many command line option errors | ||
1210 | 115 | OPT_VERSION="" # If --version was specified | ||
1211 | 116 | OPT_HELP="" # If --help was specified | ||
1212 | 117 | PO_DIR="" # Directory with program option spec files | ||
1213 | 118 | |||
1214 | 119 | usage() { | ||
1215 | 120 | local file="$1" | ||
1216 | 121 | |||
1217 | 122 | local usage="$(grep '^Usage: ' "$file")" | ||
1218 | 123 | echo $usage | ||
1219 | 124 | echo | ||
1220 | 125 | echo "For more information, 'man $TOOL' or 'perldoc $file'." | ||
1221 | 126 | } | ||
1222 | 127 | |||
1223 | 128 | usage_or_errors() { | ||
1224 | 129 | local file="$1" | ||
1225 | 130 | |||
1226 | 131 | if [ "$OPT_VERSION" ]; then | ||
1227 | 132 | local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") | ||
1228 | 133 | echo "$version" | ||
1229 | 134 | return 1 | ||
1230 | 135 | fi | ||
1231 | 136 | |||
1232 | 137 | if [ "$OPT_HELP" ]; then | ||
1233 | 138 | usage "$file" | ||
1234 | 139 | echo | ||
1235 | 140 | echo "Command line options:" | ||
1236 | 141 | echo | ||
1237 | 142 | perl -e ' | ||
1238 | 143 | use strict; | ||
1239 | 144 | use warnings FATAL => qw(all); | ||
1240 | 145 | my $lcol = 20; # Allow this much space for option names. | ||
1241 | 146 | my $rcol = 80 - $lcol; # The terminal is assumed to be 80 chars wide. | ||
1242 | 147 | my $name; | ||
1243 | 148 | while ( <> ) { | ||
1244 | 149 | my $line = $_; | ||
1245 | 150 | chomp $line; | ||
1246 | 151 | if ( $line =~ s/^long:/ --/ ) { | ||
1247 | 152 | $name = $line; | ||
1248 | 153 | } | ||
1249 | 154 | elsif ( $line =~ s/^desc:// ) { | ||
1250 | 155 | $line =~ s/ +$//mg; | ||
1251 | 156 | my @lines = grep { $_ } | ||
1252 | 157 | $line =~ m/(.{0,$rcol})(?:\s+|\Z)/g; | ||
1253 | 158 | if ( length($name) >= $lcol ) { | ||
1254 | 159 | print $name, "\n", (q{ } x $lcol); | ||
1255 | 160 | } | ||
1256 | 161 | else { | ||
1257 | 162 | printf "%-${lcol}s", $name; | ||
1258 | 163 | } | ||
1259 | 164 | print join("\n" . (q{ } x $lcol), @lines); | ||
1260 | 165 | print "\n"; | ||
1261 | 166 | } | ||
1262 | 167 | } | ||
1263 | 168 | ' "$PO_DIR"/* | ||
1264 | 169 | echo | ||
1265 | 170 | echo "Options and values after processing arguments:" | ||
1266 | 171 | echo | ||
1267 | 172 | ( | ||
1268 | 173 | cd "$PO_DIR" | ||
1269 | 174 | for opt in *; do | ||
1270 | 175 | local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)" | ||
1271 | 176 | eval local varvalue=\$$varname | ||
1272 | 177 | if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then | ||
1273 | 178 | if [ "$varvalue" -a "$varvalue" = "yes" ]; | ||
1274 | 179 | then varvalue="TRUE" | ||
1275 | 180 | else | ||
1276 | 181 | varvalue="FALSE" | ||
1277 | 182 | fi | ||
1278 | 183 | fi | ||
1279 | 184 | printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}" | ||
1280 | 185 | echo | ||
1281 | 186 | done | ||
1282 | 187 | ) | ||
1283 | 188 | return 1 | ||
1284 | 189 | fi | ||
1285 | 190 | |||
1286 | 191 | if [ $OPT_ERRS -gt 0 ]; then | ||
1287 | 192 | echo | ||
1288 | 193 | usage "$file" | ||
1289 | 194 | return 1 | ||
1290 | 195 | fi | ||
1291 | 196 | |||
1292 | 197 | return 0 | ||
1293 | 198 | } | ||
1294 | 199 | |||
1295 | 200 | option_error() { | ||
1296 | 201 | local err="$1" | ||
1297 | 202 | OPT_ERRS=$(($OPT_ERRS + 1)) | ||
1298 | 203 | echo "$err" >&2 | ||
1299 | 204 | } | ||
1300 | 205 | |||
1301 | 206 | parse_options() { | ||
1302 | 207 | local file="$1" | ||
1303 | 208 | shift | ||
1304 | 209 | |||
1305 | 210 | ARGV="" | ||
1306 | 211 | EXT_ARGV="" | ||
1307 | 212 | HAVE_EXT_ARGV="" | ||
1308 | 213 | OPT_ERRS=0 | ||
1309 | 214 | OPT_VERSION="" | ||
1310 | 215 | OPT_HELP="" | ||
1311 | 216 | PO_DIR="$PT_TMPDIR/po" | ||
1312 | 217 | |||
1313 | 218 | if [ ! -d "$PO_DIR" ]; then | ||
1314 | 219 | mkdir "$PO_DIR" | ||
1315 | 220 | if [ $? -ne 0 ]; then | ||
1316 | 221 | echo "Cannot mkdir $PO_DIR" >&2 | ||
1317 | 222 | exit 1 | ||
1318 | 223 | fi | ||
1319 | 224 | fi | ||
1320 | 225 | |||
1321 | 226 | rm -rf "$PO_DIR"/* | ||
1322 | 227 | if [ $? -ne 0 ]; then | ||
1323 | 228 | echo "Cannot rm -rf $PO_DIR/*" >&2 | ||
1324 | 229 | exit 1 | ||
1325 | 230 | fi | ||
1326 | 231 | |||
1327 | 232 | _parse_pod "$file" # Parse POD into program option (po) spec files | ||
1328 | 233 | _eval_po # Eval po into existence with default values | ||
1329 | 234 | |||
1330 | 235 | if [ $# -ge 2 ] && [ "$1" = "--config" ]; then | ||
1331 | 236 | shift # --config | ||
1332 | 237 | local user_config_files="$1" | ||
1333 | 238 | shift # that ^ | ||
1334 | 239 | local IFS="," | ||
1335 | 240 | for user_config_file in $user_config_files; do | ||
1336 | 241 | _parse_config_files "$user_config_file" | ||
1337 | 242 | done | ||
1338 | 243 | else | ||
1339 | 244 | _parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf" | ||
1340 | 245 | fi | ||
1341 | 246 | |||
1342 | 247 | _parse_command_line "${@:-""}" | ||
1343 | 248 | } | ||
1344 | 249 | |||
1345 | 250 | _parse_pod() { | ||
1346 | 251 | local file="$1" | ||
1347 | 252 | |||
1348 | 253 | cat "$file" | PO_DIR="$PO_DIR" perl -ne ' | ||
1349 | 254 | BEGIN { $/ = ""; } | ||
1350 | 255 | next unless $_ =~ m/^=head1 OPTIONS/; | ||
1351 | 256 | while ( defined(my $para = <>) ) { | ||
1352 | 257 | last if $para =~ m/^=head1/; | ||
1353 | 258 | chomp; | ||
1354 | 259 | if ( $para =~ m/^=item --(\S+)/ ) { | ||
1355 | 260 | my $opt = $1; | ||
1356 | 261 | my $file = "$ENV{PO_DIR}/$opt"; | ||
1357 | 262 | open my $opt_fh, ">", $file or die "Cannot open $file: $!"; | ||
1358 | 263 | print $opt_fh "long:$opt\n"; | ||
1359 | 264 | $para = <>; | ||
1360 | 265 | chomp; | ||
1361 | 266 | if ( $para =~ m/^[a-z ]+:/ ) { | ||
1362 | 267 | map { | ||
1363 | 268 | chomp; | ||
1364 | 269 | my ($attrib, $val) = split(/: /, $_); | ||
1365 | 270 | print $opt_fh "$attrib:$val\n"; | ||
1366 | 271 | } split(/; /, $para); | ||
1367 | 272 | $para = <>; | ||
1368 | 273 | chomp; | ||
1369 | 274 | } | ||
1370 | 275 | my ($desc) = $para =~ m/^([^?.]+)/; | ||
1371 | 276 | print $opt_fh "desc:$desc.\n"; | ||
1372 | 277 | close $opt_fh; | ||
1373 | 278 | } | ||
1374 | 279 | } | ||
1375 | 280 | last; | ||
1376 | 281 | ' | ||
1377 | 282 | } | ||
1378 | 283 | |||
1379 | 284 | _eval_po() { | ||
1380 | 285 | local IFS=":" | ||
1381 | 286 | for opt_spec in "$PO_DIR"/*; do | ||
1382 | 287 | local opt="" | ||
1383 | 288 | local default_val="" | ||
1384 | 289 | local neg=0 | ||
1385 | 290 | local size=0 | ||
1386 | 291 | while read key val; do | ||
1387 | 292 | case "$key" in | ||
1388 | 293 | long) | ||
1389 | 294 | opt=$(echo $val | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]') | ||
1390 | 295 | ;; | ||
1391 | 296 | default) | ||
1392 | 297 | default_val="$val" | ||
1393 | 298 | ;; | ||
1394 | 299 | "short form") | ||
1395 | 300 | ;; | ||
1396 | 301 | type) | ||
1397 | 302 | [ "$val" = "size" ] && size=1 | ||
1398 | 303 | ;; | ||
1399 | 304 | desc) | ||
1400 | 305 | ;; | ||
1401 | 306 | negatable) | ||
1402 | 307 | if [ "$val" = "yes" ]; then | ||
1403 | 308 | neg=1 | ||
1404 | 309 | fi | ||
1405 | 310 | ;; | ||
1406 | 311 | *) | ||
1407 | 312 | echo "Invalid attribute in $opt_spec: $line" >&2 | ||
1408 | 313 | exit 1 | ||
1409 | 314 | esac | ||
1410 | 315 | done < "$opt_spec" | ||
1411 | 316 | |||
1412 | 317 | if [ -z "$opt" ]; then | ||
1413 | 318 | echo "No long attribute in option spec $opt_spec" >&2 | ||
1414 | 319 | exit 1 | ||
1415 | 320 | fi | ||
1416 | 321 | |||
1417 | 322 | if [ $neg -eq 1 ]; then | ||
1418 | 323 | if [ -z "$default_val" ] || [ "$default_val" != "yes" ]; then | ||
1419 | 324 | echo "Option $opt_spec is negatable but not default: yes" >&2 | ||
1420 | 325 | exit 1 | ||
1421 | 326 | fi | ||
1422 | 327 | fi | ||
1423 | 328 | |||
1424 | 329 | if [ $size -eq 1 -a -n "$default_val" ]; then | ||
1425 | 330 | default_val=$(size_to_bytes $default_val) | ||
1426 | 331 | fi | ||
1427 | 332 | |||
1428 | 333 | eval "OPT_${opt}"="$default_val" | ||
1429 | 334 | done | ||
1430 | 335 | } | ||
1431 | 336 | |||
1432 | 337 | _parse_config_files() { | ||
1433 | 338 | |||
1434 | 339 | for config_file in "${@:-""}"; do | ||
1435 | 340 | test -f "$config_file" || continue | ||
1436 | 341 | |||
1437 | 342 | while read config_opt; do | ||
1438 | 343 | |||
1439 | 344 | echo "$config_opt" | grep '^[ ]*[^#]' >/dev/null 2>&1 || continue | ||
1440 | 345 | |||
1441 | 346 | config_opt="$(echo "$config_opt" | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')" | ||
1442 | 347 | |||
1443 | 348 | [ "$config_opt" = "" ] && continue | ||
1444 | 349 | |||
1445 | 350 | if ! [ "$HAVE_EXT_ARGV" ]; then | ||
1446 | 351 | config_opt="--$config_opt" | ||
1447 | 352 | fi | ||
1448 | 353 | |||
1449 | 354 | _parse_command_line "$config_opt" | ||
1450 | 355 | |||
1451 | 356 | done < "$config_file" | ||
1452 | 357 | |||
1453 | 358 | HAVE_EXT_ARGV="" # reset for each file | ||
1454 | 359 | |||
1455 | 360 | done | ||
1456 | 361 | } | ||
1457 | 362 | |||
1458 | 363 | _parse_command_line() { | ||
1459 | 364 | local opt="" | ||
1460 | 365 | local val="" | ||
1461 | 366 | local next_opt_is_val="" | ||
1462 | 367 | local opt_is_ok="" | ||
1463 | 368 | local opt_is_negated="" | ||
1464 | 369 | local real_opt="" | ||
1465 | 370 | local required_arg="" | ||
1466 | 371 | local spec="" | ||
1467 | 372 | |||
1468 | 373 | for opt in "${@:-""}"; do | ||
1469 | 374 | if [ "$opt" = "--" -o "$opt" = "----" ]; then | ||
1470 | 375 | HAVE_EXT_ARGV=1 | ||
1471 | 376 | continue | ||
1472 | 377 | fi | ||
1473 | 378 | if [ "$HAVE_EXT_ARGV" ]; then | ||
1474 | 379 | if [ "$EXT_ARGV" ]; then | ||
1475 | 380 | EXT_ARGV="$EXT_ARGV $opt" | ||
1476 | 381 | else | ||
1477 | 382 | EXT_ARGV="$opt" | ||
1478 | 383 | fi | ||
1479 | 384 | continue | ||
1480 | 385 | fi | ||
1481 | 386 | |||
1482 | 387 | if [ "$next_opt_is_val" ]; then | ||
1483 | 388 | next_opt_is_val="" | ||
1484 | 389 | if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then | ||
1485 | 390 | option_error "$real_opt requires a $required_arg argument" | ||
1486 | 391 | continue | ||
1487 | 392 | fi | ||
1488 | 393 | val="$opt" | ||
1489 | 394 | opt_is_ok=1 | ||
1490 | 395 | else | ||
1491 | 396 | if [ $(expr "$opt" : "\-") -eq 0 ]; then | ||
1492 | 397 | if [ -z "$ARGV" ]; then | ||
1493 | 398 | ARGV="$opt" | ||
1494 | 399 | else | ||
1495 | 400 | ARGV="$ARGV $opt" | ||
1496 | 401 | fi | ||
1497 | 402 | continue | ||
1498 | 403 | fi | ||
1499 | 404 | |||
1500 | 405 | real_opt="$opt" | ||
1501 | 406 | |||
1502 | 407 | if $(echo $opt | grep '^--no[^-]' >/dev/null); then | ||
1503 | 408 | local base_opt=$(echo $opt | sed 's/^--no//') | ||
1504 | 409 | if [ -f "$PT_TMPDIR/po/$base_opt" ]; then | ||
1505 | 410 | opt_is_negated=1 | ||
1506 | 411 | opt="$base_opt" | ||
1507 | 412 | else | ||
1508 | 413 | opt_is_negated="" | ||
1509 | 414 | opt=$(echo $opt | sed 's/^-*//') | ||
1510 | 415 | fi | ||
1511 | 416 | else | ||
1512 | 417 | if $(echo $opt | grep '^--no-' >/dev/null); then | ||
1513 | 418 | opt_is_negated=1 | ||
1514 | 419 | opt=$(echo $opt | sed 's/^--no-//') | ||
1515 | 420 | else | ||
1516 | 421 | opt_is_negated="" | ||
1517 | 422 | opt=$(echo $opt | sed 's/^-*//') | ||
1518 | 423 | fi | ||
1519 | 424 | fi | ||
1520 | 425 | |||
1521 | 426 | if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then | ||
1522 | 427 | val="$(echo $opt | awk -F= '{print $2}')" | ||
1523 | 428 | opt="$(echo $opt | awk -F= '{print $1}')" | ||
1524 | 429 | fi | ||
1525 | 430 | |||
1526 | 431 | if [ -f "$PT_TMPDIR/po/$opt" ]; then | ||
1527 | 432 | spec="$PT_TMPDIR/po/$opt" | ||
1528 | 433 | else | ||
1529 | 434 | spec=$(grep "^short form:-$opt\$" "$PT_TMPDIR"/po/* | cut -d ':' -f 1) | ||
1530 | 435 | if [ -z "$spec" ]; then | ||
1531 | 436 | option_error "Unknown option: $real_opt" | ||
1532 | 437 | continue | ||
1533 | 438 | fi | ||
1534 | 439 | fi | ||
1535 | 440 | |||
1536 | 441 | required_arg=$(cat "$spec" | awk -F: '/^type:/{print $2}') | ||
1537 | 442 | if [ "$required_arg" ]; then | ||
1538 | 443 | if [ "$val" ]; then | ||
1539 | 444 | opt_is_ok=1 | ||
1540 | 445 | else | ||
1541 | 446 | next_opt_is_val=1 | ||
1542 | 447 | fi | ||
1543 | 448 | else | ||
1544 | 449 | if [ "$val" ]; then | ||
1545 | 450 | option_error "Option $real_opt does not take a value" | ||
1546 | 451 | continue | ||
1547 | 452 | fi | ||
1548 | 453 | if [ "$opt_is_negated" ]; then | ||
1549 | 454 | val="" | ||
1550 | 455 | else | ||
1551 | 456 | val="yes" | ||
1552 | 457 | fi | ||
1553 | 458 | opt_is_ok=1 | ||
1554 | 459 | fi | ||
1555 | 460 | fi | ||
1556 | 461 | |||
1557 | 462 | if [ "$opt_is_ok" ]; then | ||
1558 | 463 | opt=$(cat "$spec" | grep '^long:' | cut -d':' -f2 | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]') | ||
1559 | 464 | |||
1560 | 465 | if grep "^type:size" "$spec" >/dev/null; then | ||
1561 | 466 | val=$(size_to_bytes $val) | ||
1562 | 467 | fi | ||
1563 | 468 | |||
1564 | 469 | eval "OPT_$opt"="'$val'" | ||
1565 | 470 | |||
1566 | 471 | opt="" | ||
1567 | 472 | val="" | ||
1568 | 473 | next_opt_is_val="" | ||
1569 | 474 | opt_is_ok="" | ||
1570 | 475 | opt_is_negated="" | ||
1571 | 476 | real_opt="" | ||
1572 | 477 | required_arg="" | ||
1573 | 478 | spec="" | ||
1574 | 479 | fi | ||
1575 | 480 | done | ||
1576 | 481 | } | ||
1577 | 482 | |||
1578 | 483 | size_to_bytes() { | ||
1579 | 484 | local size="$1" | ||
1580 | 485 | echo $size | perl -ne '%f=(B=>1, K=>1_024, M=>1_048_576, G=>1_073_741_824, T=>1_099_511_627_776); m/^(\d+)([kMGT])?/i; print $1 * $f{uc($2 || "B")};' | ||
1581 | 486 | } | ||
1582 | 487 | |||
1583 | 488 | # ########################################################################### | ||
1584 | 489 | # End parse_options package | ||
1585 | 490 | # ########################################################################### | ||
1586 | 491 | |||
1587 | 492 | # ########################################################################### | ||
1588 | 493 | # alt_cmds package | ||
1589 | 494 | # This package is a copy without comments from the original. The original | ||
1590 | 495 | # with comments and its test file can be found in the Bazaar repository at, | ||
1591 | 496 | # lib/bash/alt_cmds.sh | ||
1592 | 497 | # t/lib/bash/alt_cmds.sh | ||
1593 | 498 | # See https://launchpad.net/percona-toolkit for more information. | ||
1594 | 499 | # ########################################################################### | ||
1595 | 500 | |||
1596 | 501 | |||
1597 | 502 | set -u | ||
1598 | 503 | |||
1599 | 504 | _seq() { | ||
1600 | 505 | local i="$1" | ||
1601 | 506 | awk "BEGIN { for(i=1; i<=$i; i++) print i; }" | ||
1602 | 507 | } | ||
1603 | 508 | |||
1604 | 509 | _pidof() { | ||
1605 | 510 | local cmd="$1" | ||
1606 | 511 | if ! pidof "$cmd" 2>/dev/null; then | ||
1607 | 512 | ps -eo pid,ucomm | awk -v comm="$cmd" '$2 == comm { print $1 }' | ||
1608 | 513 | fi | ||
1609 | 514 | } | ||
1610 | 515 | |||
1611 | 516 | _lsof() { | ||
1612 | 517 | local pid="$1" | ||
1613 | 518 | if ! lsof -p $pid 2>/dev/null; then | ||
1614 | 519 | /bin/ls -l /proc/$pid/fd 2>/dev/null | ||
1615 | 520 | fi | ||
1616 | 521 | } | ||
1617 | 522 | |||
1618 | 523 | |||
1619 | 524 | |||
1620 | 525 | _which() { | ||
1621 | 526 | if [ -x /usr/bin/which ]; then | ||
1622 | 527 | /usr/bin/which "$1" 2>/dev/null | awk '{print $1}' | ||
1623 | 528 | elif which which 1>/dev/null 2>&1; then | ||
1624 | 529 | which "$1" 2>/dev/null | awk '{print $1}' | ||
1625 | 530 | else | ||
1626 | 531 | echo "$1" | ||
1627 | 532 | fi | ||
1628 | 533 | } | ||
1629 | 534 | |||
1630 | 535 | # ########################################################################### | ||
1631 | 536 | # End alt_cmds package | ||
1632 | 537 | # ########################################################################### | ||
1633 | 538 | |||
1634 | 539 | TOOL="pt-mext" | ||
1635 | 540 | |||
1636 | 541 | # Parse command line options. | ||
1637 | 61 | mk_tmpdir | 542 | mk_tmpdir |
1638 | 543 | parse_options "$0" "${@:-""}" | ||
1639 | 544 | |||
1640 | 545 | if [ -z "$OPT_HELP" -a -z "$OPT_VERSION" ]; then | ||
1641 | 546 | if [ -z "$EXT_ARGV" ]; then | ||
1642 | 547 | option_error "No COMMAND was given." | ||
1643 | 548 | fi | ||
1644 | 549 | fi | ||
1645 | 550 | |||
1646 | 551 | usage_or_errors "$0" | ||
1647 | 552 | po_status=$? | ||
1648 | 553 | |||
1649 | 554 | if [ $po_status -ne 0 ]; then | ||
1650 | 555 | [ $OPT_ERRS -gt 0 ] && exit 1 | ||
1651 | 556 | exit 0 | ||
1652 | 557 | fi | ||
1653 | 62 | 558 | ||
1654 | 63 | FILE="$PT_TMPDIR/mext_temp_file"; | 559 | FILE="$PT_TMPDIR/mext_temp_file"; |
1674 | 64 | NUM=0; | 560 | NUM=1; |
1656 | 65 | REL=0; | ||
1657 | 66 | |||
1658 | 67 | # Command-line parsing. | ||
1659 | 68 | args=`getopt -u -n mext r "$@"`; | ||
1660 | 69 | if [ "$?" = "1" ]; then | ||
1661 | 70 | usage; | ||
1662 | 71 | fi | ||
1663 | 72 | set -- $args | ||
1664 | 73 | for o; do | ||
1665 | 74 | case "$o" in | ||
1666 | 75 | -r) REL="1"; shift;; | ||
1667 | 76 | --) shift; break;; | ||
1668 | 77 | esac | ||
1669 | 78 | done | ||
1670 | 79 | |||
1671 | 80 | if [ -z "$1" ]; then | ||
1672 | 81 | usage; | ||
1673 | 82 | fi | ||
1675 | 83 | 561 | ||
1676 | 84 | # Split the output on empty lines and put each into a different file; eliminate | 562 | # Split the output on empty lines and put each into a different file; eliminate |
1677 | 85 | # lines that don't have "real" content. | 563 | # lines that don't have "real" content. |
1679 | 86 | $@ | grep -v '+' | grep -v Variable_name | sed 's/|//g' \ | 564 | $EXT_ARGV | grep -v '+' | grep -v Variable_name | sed 's/|//g' \ |
1680 | 87 | | while read line; do | 565 | | while read line; do |
1681 | 88 | if [ "$line" = "" ]; then | 566 | if [ "$line" = "" ]; then |
1683 | 89 | NUM=`expr $NUM + 1`; | 567 | NUM=$(($NUM + 1)) |
1684 | 90 | echo "" > "$FILE$NUM" | 568 | echo "" > "$FILE$NUM" |
1685 | 91 | fi | 569 | fi |
1686 | 92 | echo "$line" >> "$FILE$NUM" | 570 | echo "$line" >> "$FILE$NUM" |
1687 | 93 | done | 571 | done |
1688 | 94 | 572 | ||
1689 | 95 | # Count how many files there are and prepare to format the output | ||
1690 | 96 | SPEC="%-33s %13d" | 573 | SPEC="%-33s %13d" |
1691 | 97 | AWKS="" | 574 | AWKS="" |
1692 | 575 | |||
1693 | 576 | # Count how many files there are and prepare to format the output, but... | ||
1694 | 98 | NUM=`ls "$FILE"* | wc -l`; | 577 | NUM=`ls "$FILE"* | wc -l`; |
1697 | 99 | # The last file will be empty... | 578 | |
1698 | 100 | NUM=`expr $NUM - 3`; | 579 | # ... iterate through files 1..(N-2) because the last file is empty and |
1699 | 580 | # we join N to N+1 so also don't read the last real file. | ||
1700 | 581 | NUM=$((NUM - 2)) | ||
1701 | 101 | 582 | ||
1702 | 102 | # Join each file with the next file, joining on the first field. Build a printf | 583 | # Join each file with the next file, joining on the first field. Build a printf |
1703 | 103 | # spec and awk spec at the same time. | 584 | # spec and awk spec at the same time. |
1706 | 104 | for i in `seq 0 $NUM`; do | 585 | for i in `_seq $NUM`; do |
1707 | 105 | NEXTFILE=`expr $i + 1`; | 586 | NEXTFILE=$(($i + 1)) |
1708 | 106 | 587 | ||
1709 | 107 | # Sort each file and eliminate empty lines, so 'join' doesn't complain. | 588 | # Sort each file and eliminate empty lines, so 'join' doesn't complain. |
1710 | 108 | sort "$FILE$i" | grep . > "$FILE$i.tmp" | 589 | sort "$FILE$i" | grep . > "$FILE$i.tmp" |
1711 | @@ -119,10 +600,29 @@ | |||
1712 | 119 | MAXLEN=`awk '{print $2}' "$FILE${NEXTFILE}" | grep -v '[^0-9]' | awk '{print length($1)}' | sort -rn | head -n1` | 600 | MAXLEN=`awk '{print $2}' "$FILE${NEXTFILE}" | grep -v '[^0-9]' | awk '{print length($1)}' | sort -rn | head -n1` |
1713 | 120 | mv "$FILE" "$FILE${NEXTFILE}" | 601 | mv "$FILE" "$FILE${NEXTFILE}" |
1714 | 121 | SPEC="$SPEC %${MAXLEN}d"; | 602 | SPEC="$SPEC %${MAXLEN}d"; |
1717 | 122 | if [ "$REL" = "1" ]; then | 603 | |
1718 | 123 | AWKS="$AWKS, \$`expr $i + 3` - \$`expr $i + 2`"; | 604 | # The final file will contain lines like: |
1719 | 605 | # | ||
1720 | 606 | # Bytes_received 100 200 50 300 | ||
1721 | 607 | # | ||
1722 | 608 | # For each such line in awk, $1 is the var name and $2 is the first value | ||
1723 | 609 | # of the var, so these are fixed when we build AWKCMD after this loop. | ||
1724 | 610 | # When i=1, we're comparing file1 to file2, and the resulting value becomes | ||
1725 | 611 | # awk $3. Hence $i + 2=$3 below. Then incr and repeat for subsequent files. | ||
1726 | 612 | # | ||
1727 | 613 | # With --relative, the $i and awk field numbers are the same, but we print | ||
1728 | 614 | # differences $3-$2, $4-$3, $5-$4 from the input line for awk fields $3, $4, | ||
1729 | 615 | # and $5 respectively. Here's a table: | ||
1730 | 616 | # | ||
1731 | 617 | # i awk Input line fields | ||
1732 | 618 | # == === ================= | ||
1733 | 619 | # 1 $3 $3-$2 | ||
1734 | 620 | # 2 $4 $4-$3 | ||
1735 | 621 | # 3 $5 $5-$4 | ||
1736 | 622 | if [ "$OPT_RELATIVE" ]; then | ||
1737 | 623 | AWKS="$AWKS, \$`expr $i + 2` - \$`expr $i + 1`"; | ||
1738 | 124 | else | 624 | else |
1740 | 125 | AWKS="$AWKS, \$`expr $i + 3`"; | 625 | AWKS="$AWKS, \$$(($i + 2))"; |
1741 | 126 | fi | 626 | fi |
1742 | 127 | done | 627 | done |
1743 | 128 | 628 | ||
1744 | @@ -153,7 +653,7 @@ | |||
1745 | 153 | 653 | ||
1746 | 154 | Get output from C<mysqladmin>: | 654 | Get output from C<mysqladmin>: |
1747 | 155 | 655 | ||
1749 | 156 | pt-mext -r -- mysqladmin ext -i10 -c3" | 656 | pt-mext -r -- mysqladmin ext -i10 -c3 |
1750 | 157 | 657 | ||
1751 | 158 | Get output from a file: | 658 | Get output from a file: |
1752 | 159 | 659 | ||
1753 | @@ -191,9 +691,19 @@ | |||
1754 | 191 | 691 | ||
1755 | 192 | =over | 692 | =over |
1756 | 193 | 693 | ||
1760 | 194 | =item -r | 694 | =item --help |
1761 | 195 | 695 | ||
1762 | 196 | Relative: subtract each column from the previous column. | 696 | Show help and exit. |
1763 | 697 | |||
1764 | 698 | =item --relative | ||
1765 | 699 | |||
1766 | 700 | short form: -r | ||
1767 | 701 | |||
1768 | 702 | Subtract each column from the previous column. | ||
1769 | 703 | |||
1770 | 704 | =item --version | ||
1771 | 705 | |||
1772 | 706 | Show version and exit. | ||
1773 | 197 | 707 | ||
1774 | 198 | =back | 708 | =back |
1775 | 199 | 709 | ||
1776 | 200 | 710 | ||
1777 | === modified file 'bin/pt-pmp' | |||
1778 | --- bin/pt-pmp 2013-03-14 17:20:35 +0000 | |||
1779 | +++ bin/pt-pmp 2013-04-04 21:05:27 +0000 | |||
1780 | @@ -7,6 +7,54 @@ | |||
1781 | 7 | TOOL="pt-pmp" | 7 | TOOL="pt-pmp" |
1782 | 8 | 8 | ||
1783 | 9 | # ########################################################################### | 9 | # ########################################################################### |
1784 | 10 | # log_warn_die package | ||
1785 | 11 | # This package is a copy without comments from the original. The original | ||
1786 | 12 | # with comments and its test file can be found in the Bazaar repository at, | ||
1787 | 13 | # lib/bash/log_warn_die.sh | ||
1788 | 14 | # t/lib/bash/log_warn_die.sh | ||
1789 | 15 | # See https://launchpad.net/percona-toolkit for more information. | ||
1790 | 16 | # ########################################################################### | ||
1791 | 17 | |||
1792 | 18 | |||
1793 | 19 | set -u | ||
1794 | 20 | |||
1795 | 21 | PTFUNCNAME="" | ||
1796 | 22 | PTDEBUG="${PTDEBUG:-""}" | ||
1797 | 23 | EXIT_STATUS=0 | ||
1798 | 24 | |||
1799 | 25 | ts() { | ||
1800 | 26 | TS=$(date +%F-%T | tr ':-' '_') | ||
1801 | 27 | echo "$TS $*" | ||
1802 | 28 | } | ||
1803 | 29 | |||
1804 | 30 | info() { | ||
1805 | 31 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
1806 | 32 | } | ||
1807 | 33 | |||
1808 | 34 | log() { | ||
1809 | 35 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" | ||
1810 | 36 | } | ||
1811 | 37 | |||
1812 | 38 | warn() { | ||
1813 | 39 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 | ||
1814 | 40 | EXIT_STATUS=1 | ||
1815 | 41 | } | ||
1816 | 42 | |||
1817 | 43 | die() { | ||
1818 | 44 | ts "$*" >&2 | ||
1819 | 45 | EXIT_STATUS=1 | ||
1820 | 46 | exit 1 | ||
1821 | 47 | } | ||
1822 | 48 | |||
1823 | 49 | _d () { | ||
1824 | 50 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 | ||
1825 | 51 | } | ||
1826 | 52 | |||
1827 | 53 | # ########################################################################### | ||
1828 | 54 | # End log_warn_die package | ||
1829 | 55 | # ########################################################################### | ||
1830 | 56 | |||
1831 | 57 | # ########################################################################### | ||
1832 | 10 | # tmpdir package | 58 | # tmpdir package |
1833 | 11 | # This package is a copy without comments from the original. The original | 59 | # This package is a copy without comments from the original. The original |
1834 | 12 | # with comments and its test file can be found in the Bazaar repository at, | 60 | # with comments and its test file can be found in the Bazaar repository at, |
1835 | @@ -47,17 +95,451 @@ | |||
1836 | 47 | # End tmpdir package | 95 | # End tmpdir package |
1837 | 48 | # ########################################################################### | 96 | # ########################################################################### |
1838 | 49 | 97 | ||
1839 | 98 | # ########################################################################### | ||
1840 | 99 | # parse_options package | ||
1841 | 100 | # This package is a copy without comments from the original. The original | ||
1842 | 101 | # with comments and its test file can be found in the Bazaar repository at, | ||
1843 | 102 | # lib/bash/parse_options.sh | ||
1844 | 103 | # t/lib/bash/parse_options.sh | ||
1845 | 104 | # See https://launchpad.net/percona-toolkit for more information. | ||
1846 | 105 | # ########################################################################### | ||
1847 | 106 | |||
1848 | 107 | |||
1849 | 108 | |||
1850 | 109 | |||
1851 | 110 | |||
1852 | 111 | set -u | ||
1853 | 112 | |||
1854 | 113 | ARGV="" # Non-option args (probably input files) | ||
1855 | 114 | EXT_ARGV="" # Everything after -- (args for an external command) | ||
1856 | 115 | HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV | ||
1857 | 116 | OPT_ERRS=0 # How many command line option errors | ||
1858 | 117 | OPT_VERSION="" # If --version was specified | ||
1859 | 118 | OPT_HELP="" # If --help was specified | ||
1860 | 119 | PO_DIR="" # Directory with program option spec files | ||
1861 | 120 | |||
1862 | 121 | usage() { | ||
1863 | 122 | local file="$1" | ||
1864 | 123 | |||
1865 | 124 | local usage="$(grep '^Usage: ' "$file")" | ||
1866 | 125 | echo $usage | ||
1867 | 126 | echo | ||
1868 | 127 | echo "For more information, 'man $TOOL' or 'perldoc $file'." | ||
1869 | 128 | } | ||
1870 | 129 | |||
1871 | 130 | usage_or_errors() { | ||
1872 | 131 | local file="$1" | ||
1873 | 132 | |||
1874 | 133 | if [ "$OPT_VERSION" ]; then | ||
1875 | 134 | local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") | ||
1876 | 135 | echo "$version" | ||
1877 | 136 | return 1 | ||
1878 | 137 | fi | ||
1879 | 138 | |||
1880 | 139 | if [ "$OPT_HELP" ]; then | ||
1881 | 140 | usage "$file" | ||
1882 | 141 | echo | ||
1883 | 142 | echo "Command line options:" | ||
1884 | 143 | echo | ||
1885 | 144 | perl -e ' | ||
1886 | 145 | use strict; | ||
1887 | 146 | use warnings FATAL => qw(all); | ||
1888 | 147 | my $lcol = 20; # Allow this much space for option names. | ||
1889 | 148 | my $rcol = 80 - $lcol; # The terminal is assumed to be 80 chars wide. | ||
1890 | 149 | my $name; | ||
1891 | 150 | while ( <> ) { | ||
1892 | 151 | my $line = $_; | ||
1893 | 152 | chomp $line; | ||
1894 | 153 | if ( $line =~ s/^long:/ --/ ) { | ||
1895 | 154 | $name = $line; | ||
1896 | 155 | } | ||
1897 | 156 | elsif ( $line =~ s/^desc:// ) { | ||
1898 | 157 | $line =~ s/ +$//mg; | ||
1899 | 158 | my @lines = grep { $_ } | ||
1900 | 159 | $line =~ m/(.{0,$rcol})(?:\s+|\Z)/g; | ||
1901 | 160 | if ( length($name) >= $lcol ) { | ||
1902 | 161 | print $name, "\n", (q{ } x $lcol); | ||
1903 | 162 | } | ||
1904 | 163 | else { | ||
1905 | 164 | printf "%-${lcol}s", $name; | ||
1906 | 165 | } | ||
1907 | 166 | print join("\n" . (q{ } x $lcol), @lines); | ||
1908 | 167 | print "\n"; | ||
1909 | 168 | } | ||
1910 | 169 | } | ||
1911 | 170 | ' "$PO_DIR"/* | ||
1912 | 171 | echo | ||
1913 | 172 | echo "Options and values after processing arguments:" | ||
1914 | 173 | echo | ||
1915 | 174 | ( | ||
1916 | 175 | cd "$PO_DIR" | ||
1917 | 176 | for opt in *; do | ||
1918 | 177 | local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)" | ||
1919 | 178 | eval local varvalue=\$$varname | ||
1920 | 179 | if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then | ||
1921 | 180 | if [ "$varvalue" -a "$varvalue" = "yes" ]; | ||
1922 | 181 | then varvalue="TRUE" | ||
1923 | 182 | else | ||
1924 | 183 | varvalue="FALSE" | ||
1925 | 184 | fi | ||
1926 | 185 | fi | ||
1927 | 186 | printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}" | ||
1928 | 187 | echo | ||
1929 | 188 | done | ||
1930 | 189 | ) | ||
1931 | 190 | return 1 | ||
1932 | 191 | fi | ||
1933 | 192 | |||
1934 | 193 | if [ $OPT_ERRS -gt 0 ]; then | ||
1935 | 194 | echo | ||
1936 | 195 | usage "$file" | ||
1937 | 196 | return 1 | ||
1938 | 197 | fi | ||
1939 | 198 | |||
1940 | 199 | return 0 | ||
1941 | 200 | } | ||
1942 | 201 | |||
1943 | 202 | option_error() { | ||
1944 | 203 | local err="$1" | ||
1945 | 204 | OPT_ERRS=$(($OPT_ERRS + 1)) | ||
1946 | 205 | echo "$err" >&2 | ||
1947 | 206 | } | ||
1948 | 207 | |||
1949 | 208 | parse_options() { | ||
1950 | 209 | local file="$1" | ||
1951 | 210 | shift | ||
1952 | 211 | |||
1953 | 212 | ARGV="" | ||
1954 | 213 | EXT_ARGV="" | ||
1955 | 214 | HAVE_EXT_ARGV="" | ||
1956 | 215 | OPT_ERRS=0 | ||
1957 | 216 | OPT_VERSION="" | ||
1958 | 217 | OPT_HELP="" | ||
1959 | 218 | PO_DIR="$PT_TMPDIR/po" | ||
1960 | 219 | |||
1961 | 220 | if [ ! -d "$PO_DIR" ]; then | ||
1962 | 221 | mkdir "$PO_DIR" | ||
1963 | 222 | if [ $? -ne 0 ]; then | ||
1964 | 223 | echo "Cannot mkdir $PO_DIR" >&2 | ||
1965 | 224 | exit 1 | ||
1966 | 225 | fi | ||
1967 | 226 | fi | ||
1968 | 227 | |||
1969 | 228 | rm -rf "$PO_DIR"/* | ||
1970 | 229 | if [ $? -ne 0 ]; then | ||
1971 | 230 | echo "Cannot rm -rf $PO_DIR/*" >&2 | ||
1972 | 231 | exit 1 | ||
1973 | 232 | fi | ||
1974 | 233 | |||
1975 | 234 | _parse_pod "$file" # Parse POD into program option (po) spec files | ||
1976 | 235 | _eval_po # Eval po into existence with default values | ||
1977 | 236 | |||
1978 | 237 | if [ $# -ge 2 ] && [ "$1" = "--config" ]; then | ||
1979 | 238 | shift # --config | ||
1980 | 239 | local user_config_files="$1" | ||
1981 | 240 | shift # that ^ | ||
1982 | 241 | local IFS="," | ||
1983 | 242 | for user_config_file in $user_config_files; do | ||
1984 | 243 | _parse_config_files "$user_config_file" | ||
1985 | 244 | done | ||
1986 | 245 | else | ||
1987 | 246 | _parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf" | ||
1988 | 247 | fi | ||
1989 | 248 | |||
1990 | 249 | _parse_command_line "${@:-""}" | ||
1991 | 250 | } | ||
1992 | 251 | |||
1993 | 252 | _parse_pod() { | ||
1994 | 253 | local file="$1" | ||
1995 | 254 | |||
1996 | 255 | cat "$file" | PO_DIR="$PO_DIR" perl -ne ' | ||
1997 | 256 | BEGIN { $/ = ""; } | ||
1998 | 257 | next unless $_ =~ m/^=head1 OPTIONS/; | ||
1999 | 258 | while ( defined(my $para = <>) ) { | ||
2000 | 259 | last if $para =~ m/^=head1/; | ||
2001 | 260 | chomp; | ||
2002 | 261 | if ( $para =~ m/^=item --(\S+)/ ) { | ||
2003 | 262 | my $opt = $1; | ||
2004 | 263 | my $file = "$ENV{PO_DIR}/$opt"; | ||
2005 | 264 | open my $opt_fh, ">", $file or die "Cannot open $file: $!"; | ||
2006 | 265 | print $opt_fh "long:$opt\n"; | ||
2007 | 266 | $para = <>; | ||
2008 | 267 | chomp; | ||
2009 | 268 | if ( $para =~ m/^[a-z ]+:/ ) { | ||
2010 | 269 | map { | ||
2011 | 270 | chomp; | ||
2012 | 271 | my ($attrib, $val) = split(/: /, $_); | ||
2013 | 272 | print $opt_fh "$attrib:$val\n"; | ||
2014 | 273 | } split(/; /, $para); | ||
2015 | 274 | $para = <>; | ||
2016 | 275 | chomp; | ||
2017 | 276 | } | ||
2018 | 277 | my ($desc) = $para =~ m/^([^?.]+)/; | ||
2019 | 278 | print $opt_fh "desc:$desc.\n"; | ||
2020 | 279 | close $opt_fh; | ||
2021 | 280 | } | ||
2022 | 281 | } | ||
2023 | 282 | last; | ||
2024 | 283 | ' | ||
2025 | 284 | } | ||
2026 | 285 | |||
2027 | 286 | _eval_po() { | ||
2028 | 287 | local IFS=":" | ||
2029 | 288 | for opt_spec in "$PO_DIR"/*; do | ||
2030 | 289 | local opt="" | ||
2031 | 290 | local default_val="" | ||
2032 | 291 | local neg=0 | ||
2033 | 292 | local size=0 | ||
2034 | 293 | while read key val; do | ||
2035 | 294 | case "$key" in | ||
2036 | 295 | long) | ||
2037 | 296 | opt=$(echo $val | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]') | ||
2038 | 297 | ;; | ||
2039 | 298 | default) | ||
2040 | 299 | default_val="$val" | ||
2041 | 300 | ;; | ||
2042 | 301 | "short form") | ||
2043 | 302 | ;; | ||
2044 | 303 | type) | ||
2045 | 304 | [ "$val" = "size" ] && size=1 | ||
2046 | 305 | ;; | ||
2047 | 306 | desc) | ||
2048 | 307 | ;; | ||
2049 | 308 | negatable) | ||
2050 | 309 | if [ "$val" = "yes" ]; then | ||
2051 | 310 | neg=1 | ||
2052 | 311 | fi | ||
2053 | 312 | ;; | ||
2054 | 313 | *) | ||
2055 | 314 | echo "Invalid attribute in $opt_spec: $line" >&2 | ||
2056 | 315 | exit 1 | ||
2057 | 316 | esac | ||
2058 | 317 | done < "$opt_spec" | ||
2059 | 318 | |||
2060 | 319 | if [ -z "$opt" ]; then | ||
2061 | 320 | echo "No long attribute in option spec $opt_spec" >&2 | ||
2062 | 321 | exit 1 | ||
2063 | 322 | fi | ||
2064 | 323 | |||
2065 | 324 | if [ $neg -eq 1 ]; then | ||
2066 | 325 | if [ -z "$default_val" ] || [ "$default_val" != "yes" ]; then | ||
2067 | 326 | echo "Option $opt_spec is negatable but not default: yes" >&2 | ||
2068 | 327 | exit 1 | ||
2069 | 328 | fi | ||
2070 | 329 | fi | ||
2071 | 330 | |||
2072 | 331 | if [ $size -eq 1 -a -n "$default_val" ]; then | ||
2073 | 332 | default_val=$(size_to_bytes $default_val) | ||
2074 | 333 | fi | ||
2075 | 334 | |||
2076 | 335 | eval "OPT_${opt}"="$default_val" | ||
2077 | 336 | done | ||
2078 | 337 | } | ||
2079 | 338 | |||
2080 | 339 | _parse_config_files() { | ||
2081 | 340 | |||
2082 | 341 | for config_file in "${@:-""}"; do | ||
2083 | 342 | test -f "$config_file" || continue | ||
2084 | 343 | |||
2085 | 344 | while read config_opt; do | ||
2086 | 345 | |||
2087 | 346 | echo "$config_opt" | grep '^[ ]*[^#]' >/dev/null 2>&1 || continue | ||
2088 | 347 | |||
2089 | 348 | config_opt="$(echo "$config_opt" | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')" | ||
2090 | 349 | |||
2091 | 350 | [ "$config_opt" = "" ] && continue | ||
2092 | 351 | |||
2093 | 352 | if ! [ "$HAVE_EXT_ARGV" ]; then | ||
2094 | 353 | config_opt="--$config_opt" | ||
2095 | 354 | fi | ||
2096 | 355 | |||
2097 | 356 | _parse_command_line "$config_opt" | ||
2098 | 357 | |||
2099 | 358 | done < "$config_file" | ||
2100 | 359 | |||
2101 | 360 | HAVE_EXT_ARGV="" # reset for each file | ||
2102 | 361 | |||
2103 | 362 | done | ||
2104 | 363 | } | ||
2105 | 364 | |||
2106 | 365 | _parse_command_line() { | ||
2107 | 366 | local opt="" | ||
2108 | 367 | local val="" | ||
2109 | 368 | local next_opt_is_val="" | ||
2110 | 369 | local opt_is_ok="" | ||
2111 | 370 | local opt_is_negated="" | ||
2112 | 371 | local real_opt="" | ||
2113 | 372 | local required_arg="" | ||
2114 | 373 | local spec="" | ||
2115 | 374 | |||
2116 | 375 | for opt in "${@:-""}"; do | ||
2117 | 376 | if [ "$opt" = "--" -o "$opt" = "----" ]; then | ||
2118 | 377 | HAVE_EXT_ARGV=1 | ||
2119 | 378 | continue | ||
2120 | 379 | fi | ||
2121 | 380 | if [ "$HAVE_EXT_ARGV" ]; then | ||
2122 | 381 | if [ "$EXT_ARGV" ]; then | ||
2123 | 382 | EXT_ARGV="$EXT_ARGV $opt" | ||
2124 | 383 | else | ||
2125 | 384 | EXT_ARGV="$opt" | ||
2126 | 385 | fi | ||
2127 | 386 | continue | ||
2128 | 387 | fi | ||
2129 | 388 | |||
2130 | 389 | if [ "$next_opt_is_val" ]; then | ||
2131 | 390 | next_opt_is_val="" | ||
2132 | 391 | if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then | ||
2133 | 392 | option_error "$real_opt requires a $required_arg argument" | ||
2134 | 393 | continue | ||
2135 | 394 | fi | ||
2136 | 395 | val="$opt" | ||
2137 | 396 | opt_is_ok=1 | ||
2138 | 397 | else | ||
2139 | 398 | if [ $(expr "$opt" : "\-") -eq 0 ]; then | ||
2140 | 399 | if [ -z "$ARGV" ]; then | ||
2141 | 400 | ARGV="$opt" | ||
2142 | 401 | else | ||
2143 | 402 | ARGV="$ARGV $opt" | ||
2144 | 403 | fi | ||
2145 | 404 | continue | ||
2146 | 405 | fi | ||
2147 | 406 | |||
2148 | 407 | real_opt="$opt" | ||
2149 | 408 | |||
2150 | 409 | if $(echo $opt | grep '^--no[^-]' >/dev/null); then | ||
2151 | 410 | local base_opt=$(echo $opt | sed 's/^--no//') | ||
2152 | 411 | if [ -f "$PT_TMPDIR/po/$base_opt" ]; then | ||
2153 | 412 | opt_is_negated=1 | ||
2154 | 413 | opt="$base_opt" | ||
2155 | 414 | else | ||
2156 | 415 | opt_is_negated="" | ||
2157 | 416 | opt=$(echo $opt | sed 's/^-*//') | ||
2158 | 417 | fi | ||
2159 | 418 | else | ||
2160 | 419 | if $(echo $opt | grep '^--no-' >/dev/null); then | ||
2161 | 420 | opt_is_negated=1 | ||
2162 | 421 | opt=$(echo $opt | sed 's/^--no-//') | ||
2163 | 422 | else | ||
2164 | 423 | opt_is_negated="" | ||
2165 | 424 | opt=$(echo $opt | sed 's/^-*//') | ||
2166 | 425 | fi | ||
2167 | 426 | fi | ||
2168 | 427 | |||
2169 | 428 | if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then | ||
2170 | 429 | val="$(echo $opt | awk -F= '{print $2}')" | ||
2171 | 430 | opt="$(echo $opt | awk -F= '{print $1}')" | ||
2172 | 431 | fi | ||
2173 | 432 | |||
2174 | 433 | if [ -f "$PT_TMPDIR/po/$opt" ]; then | ||
2175 | 434 | spec="$PT_TMPDIR/po/$opt" | ||
2176 | 435 | else | ||
2177 | 436 | spec=$(grep "^short form:-$opt\$" "$PT_TMPDIR"/po/* | cut -d ':' -f 1) | ||
2178 | 437 | if [ -z "$spec" ]; then | ||
2179 | 438 | option_error "Unknown option: $real_opt" | ||
2180 | 439 | continue | ||
2181 | 440 | fi | ||
2182 | 441 | fi | ||
2183 | 442 | |||
2184 | 443 | required_arg=$(cat "$spec" | awk -F: '/^type:/{print $2}') | ||
2185 | 444 | if [ "$required_arg" ]; then | ||
2186 | 445 | if [ "$val" ]; then | ||
2187 | 446 | opt_is_ok=1 | ||
2188 | 447 | else | ||
2189 | 448 | next_opt_is_val=1 | ||
2190 | 449 | fi | ||
2191 | 450 | else | ||
2192 | 451 | if [ "$val" ]; then | ||
2193 | 452 | option_error "Option $real_opt does not take a value" | ||
2194 | 453 | continue | ||
2195 | 454 | fi | ||
2196 | 455 | if [ "$opt_is_negated" ]; then | ||
2197 | 456 | val="" | ||
2198 | 457 | else | ||
2199 | 458 | val="yes" | ||
2200 | 459 | fi | ||
2201 | 460 | opt_is_ok=1 | ||
2202 | 461 | fi | ||
2203 | 462 | fi | ||
2204 | 463 | |||
2205 | 464 | if [ "$opt_is_ok" ]; then | ||
2206 | 465 | opt=$(cat "$spec" | grep '^long:' | cut -d':' -f2 | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]') | ||
2207 | 466 | |||
2208 | 467 | if grep "^type:size" "$spec" >/dev/null; then | ||
2209 | 468 | val=$(size_to_bytes $val) | ||
2210 | 469 | fi | ||
2211 | 470 | |||
2212 | 471 | eval "OPT_$opt"="'$val'" | ||
2213 | 472 | |||
2214 | 473 | opt="" | ||
2215 | 474 | val="" | ||
2216 | 475 | next_opt_is_val="" | ||
2217 | 476 | opt_is_ok="" | ||
2218 | 477 | opt_is_negated="" | ||
2219 | 478 | real_opt="" | ||
2220 | 479 | required_arg="" | ||
2221 | 480 | spec="" | ||
2222 | 481 | fi | ||
2223 | 482 | done | ||
2224 | 483 | } | ||
2225 | 484 | |||
2226 | 485 | size_to_bytes() { | ||
2227 | 486 | local size="$1" | ||
2228 | 487 | echo $size | perl -ne '%f=(B=>1, K=>1_024, M=>1_048_576, G=>1_073_741_824, T=>1_099_511_627_776); m/^(\d+)([kMGT])?/i; print $1 * $f{uc($2 || "B")};' | ||
2229 | 488 | } | ||
2230 | 489 | |||
2231 | 490 | # ########################################################################### | ||
2232 | 491 | # End parse_options package | ||
2233 | 492 | # ########################################################################### | ||
2234 | 493 | |||
2235 | 494 | # ########################################################################### | ||
2236 | 495 | # alt_cmds package | ||
2237 | 496 | # This package is a copy without comments from the original. The original | ||
2238 | 497 | # with comments and its test file can be found in the Bazaar repository at, | ||
2239 | 498 | # lib/bash/alt_cmds.sh | ||
2240 | 499 | # t/lib/bash/alt_cmds.sh | ||
2241 | 500 | # See https://launchpad.net/percona-toolkit for more information. | ||
2242 | 501 | # ########################################################################### | ||
2243 | 502 | |||
2244 | 503 | |||
2245 | 504 | set -u | ||
2246 | 505 | |||
2247 | 506 | _seq() { | ||
2248 | 507 | local i="$1" | ||
2249 | 508 | awk "BEGIN { for(i=1; i<=$i; i++) print i; }" | ||
2250 | 509 | } | ||
2251 | 510 | |||
2252 | 511 | _pidof() { | ||
2253 | 512 | local cmd="$1" | ||
2254 | 513 | if ! pidof "$cmd" 2>/dev/null; then | ||
2255 | 514 | ps -eo pid,ucomm | awk -v comm="$cmd" '$2 == comm { print $1 }' | ||
2256 | 515 | fi | ||
2257 | 516 | } | ||
2258 | 517 | |||
2259 | 518 | _lsof() { | ||
2260 | 519 | local pid="$1" | ||
2261 | 520 | if ! lsof -p $pid 2>/dev/null; then | ||
2262 | 521 | /bin/ls -l /proc/$pid/fd 2>/dev/null | ||
2263 | 522 | fi | ||
2264 | 523 | } | ||
2265 | 524 | |||
2266 | 525 | |||
2267 | 526 | |||
2268 | 527 | _which() { | ||
2269 | 528 | if [ -x /usr/bin/which ]; then | ||
2270 | 529 | /usr/bin/which "$1" 2>/dev/null | awk '{print $1}' | ||
2271 | 530 | elif which which 1>/dev/null 2>&1; then | ||
2272 | 531 | which "$1" 2>/dev/null | awk '{print $1}' | ||
2273 | 532 | else | ||
2274 | 533 | echo "$1" | ||
2275 | 534 | fi | ||
2276 | 535 | } | ||
2277 | 536 | |||
2278 | 537 | # ########################################################################### | ||
2279 | 538 | # End alt_cmds package | ||
2280 | 539 | # ########################################################################### | ||
2281 | 540 | |||
2282 | 50 | set +u | 541 | set +u |
2283 | 51 | 542 | ||
2284 | 52 | usage() { | ||
2285 | 53 | if [ "${OPT_ERR}" ]; then | ||
2286 | 54 | echo "${OPT_ERR}" >&2 | ||
2287 | 55 | fi | ||
2288 | 56 | echo "Usage: pt-pmp [OPTIONS] [FILES]" >&2 | ||
2289 | 57 | echo "For more information, 'man pt-pmp' or 'perldoc $0'" >&2 | ||
2290 | 58 | exit 1 | ||
2291 | 59 | } | ||
2292 | 60 | |||
2293 | 61 | # Actually does the aggregation. The arguments are the max number of functions | 543 | # Actually does the aggregation. The arguments are the max number of functions |
2294 | 62 | # to aggregate, and the files to read. If maxlen=0, it means infinity. We have | 544 | # to aggregate, and the files to read. If maxlen=0, it means infinity. We have |
2295 | 63 | # to pass the maxlen argument into this function to make maxlen testable. | 545 | # to pass the maxlen argument into this function to make maxlen testable. |
2296 | @@ -153,70 +635,35 @@ | |||
2297 | 153 | 635 | ||
2298 | 154 | # The main program to run. | 636 | # The main program to run. |
2299 | 155 | main() { | 637 | main() { |
2347 | 156 | 638 | local output_file="${OPT_SAVE_SAMPLES:-"$PT_TMPDIR/percona-toolkit"}" | |
2348 | 157 | # Get command-line options | 639 | |
2349 | 158 | for o; do | 640 | if [ -z "$ARGV" ]; then |
2350 | 159 | case "${o}" in | 641 | # There are no files to analyze, so we'll make one. |
2351 | 160 | --) | 642 | if [ -z "$OPT_PID" ]; then |
2352 | 161 | shift; break; | 643 | OPT_PID=$(pidof -s "$OPT_BINARY" 2>/dev/null); |
2353 | 162 | ;; | 644 | if [ -z "$OPT_PID" ]; then |
2354 | 163 | --help) | 645 | OPT_PID=$(pgrep -o -x "$OPT_BINARY" 2>/dev/null) |
2308 | 164 | usage; | ||
2309 | 165 | ;; | ||
2310 | 166 | -b) | ||
2311 | 167 | shift; OPT_b="${1}"; shift; | ||
2312 | 168 | ;; | ||
2313 | 169 | -i) | ||
2314 | 170 | shift; OPT_i="${1}"; shift; | ||
2315 | 171 | ;; | ||
2316 | 172 | -k) | ||
2317 | 173 | shift; OPT_k="${1}"; shift; | ||
2318 | 174 | ;; | ||
2319 | 175 | -l) | ||
2320 | 176 | shift; OPT_l="${1}"; shift; | ||
2321 | 177 | ;; | ||
2322 | 178 | -p) | ||
2323 | 179 | shift; OPT_p="${1}"; shift; | ||
2324 | 180 | ;; | ||
2325 | 181 | -s) | ||
2326 | 182 | shift; OPT_s="${1}"; shift; | ||
2327 | 183 | ;; | ||
2328 | 184 | -*) | ||
2329 | 185 | OPT_ERR="Unknown option ${o}." | ||
2330 | 186 | usage | ||
2331 | 187 | ;; | ||
2332 | 188 | esac | ||
2333 | 189 | done | ||
2334 | 190 | export OPT_i="${OPT_i:-1}"; | ||
2335 | 191 | export OPT_k="${OPT_k:-}"; | ||
2336 | 192 | export OPT_l="${OPT_l:-0}"; | ||
2337 | 193 | export OPT_b="${OPT_b:-mysqld}"; | ||
2338 | 194 | export OPT_p="${OPT_p:-}"; | ||
2339 | 195 | export OPT_s="${OPT_s:-0}"; | ||
2340 | 196 | |||
2341 | 197 | if [ -z "${1}" ]; then | ||
2342 | 198 | # There's no file to analyze, so we'll make one. | ||
2343 | 199 | if [ -z "${OPT_p}" ]; then | ||
2344 | 200 | OPT_p=$(pidof -s "${OPT_b}" 2>/dev/null); | ||
2345 | 201 | if [ -z "${OPT_p}" ]; then | ||
2346 | 202 | OPT_p=$(pgrep -o -x "${OPT_b}" 2>/dev/null) | ||
2355 | 203 | fi | 646 | fi |
2358 | 204 | if [ -z "${OPT_p}" ]; then | 647 | if [ -z "$OPT_PID" ]; then |
2359 | 205 | OPT_p=$(ps -eaf | grep "${OPT_b}" | grep -v grep | awk '{print $2}' | head -n1); | 648 | OPT_PID=$(ps -eaf | grep "$OPT_BINARY" | grep -v grep | awk '{print $2}' | head -n1); |
2360 | 206 | fi | 649 | fi |
2361 | 207 | fi | 650 | fi |
2367 | 208 | date; | 651 | date |
2368 | 209 | for x in $(seq 1 $OPT_i); do | 652 | for x in $(_seq $OPT_ITERATIONS); do |
2369 | 210 | gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $OPT_p >> "${OPT_k:-$PT_TMPDIR/percona-toolkit}" | 653 | gdb -ex "set pagination 0" \ |
2370 | 211 | date +'TS %N.%s %F %T' >> "${OPT_k:-$PT_TMPDIR/percona-toolkit}" | 654 | -ex "thread apply all bt" \ |
2371 | 212 | sleep $OPT_s | 655 | -batch \ |
2372 | 656 | -p $OPT_PID \ | ||
2373 | 657 | >> "$output_file" | ||
2374 | 658 | date +'TS %N.%s %F %T' >> "$output_file" | ||
2375 | 659 | sleep $OPT_INTERVAL | ||
2376 | 213 | done | 660 | done |
2377 | 214 | fi | 661 | fi |
2378 | 215 | 662 | ||
2381 | 216 | if [ $# -eq 0 ]; then | 663 | if [ -z "$ARGV" ]; then |
2382 | 217 | aggregate_stacktrace "${OPT_l}" "${OPT_k:-$PT_TMPDIR/percona-toolkit}" | 664 | aggregate_stacktrace "$OPT_LINES" "$output_file" |
2383 | 218 | else | 665 | else |
2385 | 219 | aggregate_stacktrace "${OPT_l}" "$@" | 666 | aggregate_stacktrace "$OPT_LINES" $ARGV |
2386 | 220 | fi | 667 | fi |
2387 | 221 | } | 668 | } |
2388 | 222 | 669 | ||
2389 | @@ -224,8 +671,23 @@ | |||
2390 | 224 | # possible to include without executing, and thus test. | 671 | # possible to include without executing, and thus test. |
2391 | 225 | if [ "${0##*/}" = "$TOOL" ] \ | 672 | if [ "${0##*/}" = "$TOOL" ] \ |
2392 | 226 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then | 673 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
2393 | 674 | |||
2394 | 227 | mk_tmpdir | 675 | mk_tmpdir |
2396 | 228 | main "$@" | 676 | |
2397 | 677 | parse_options "$0" "${@:-""}" | ||
2398 | 678 | if [ -z "$OPT_HELP" -a -z "$OPT_VERSION" ]; then | ||
2399 | 679 | # Validate options | ||
2400 | 680 | : | ||
2401 | 681 | fi | ||
2402 | 682 | usage_or_errors "$0" | ||
2403 | 683 | po_status=$? | ||
2404 | 684 | if [ $po_status -ne 0 ]; then | ||
2405 | 685 | [ $OPT_ERRS -gt 0 ] && exit 1 | ||
2406 | 686 | exit 0 | ||
2407 | 687 | fi | ||
2408 | 688 | |||
2409 | 689 | main $ARGV | ||
2410 | 690 | |||
2411 | 229 | rm_tmpdir | 691 | rm_tmpdir |
2412 | 230 | fi | 692 | fi |
2413 | 231 | 693 | ||
2414 | @@ -289,33 +751,51 @@ | |||
2415 | 289 | 751 | ||
2416 | 290 | =head1 OPTIONS | 752 | =head1 OPTIONS |
2417 | 291 | 753 | ||
2418 | 292 | Options must precede files on the command line. | ||
2419 | 293 | |||
2420 | 294 | =over | 754 | =over |
2421 | 295 | 755 | ||
2445 | 296 | =item -b BINARY | 756 | =item --binary |
2446 | 297 | 757 | ||
2447 | 298 | Which binary to trace (default mysqld) | 758 | short form: -b; type: string; default: mysqld |
2448 | 299 | 759 | ||
2449 | 300 | =item -i ITERATIONS | 760 | Which binary to trace. |
2450 | 301 | 761 | ||
2451 | 302 | How many traces to gather and aggregate (default 1) | 762 | =item --help |
2452 | 303 | 763 | ||
2453 | 304 | =item -k KEEPFILE | 764 | Show help and exit. |
2454 | 305 | 765 | ||
2455 | 306 | Keep the raw traces in this file after aggregation | 766 | =item --interval |
2456 | 307 | 767 | ||
2457 | 308 | =item -l NUMBER | 768 | short form: -s; type: int; default: 0 |
2458 | 309 | 769 | ||
2459 | 310 | Aggregate only first NUMBER functions; 0=infinity (default 0) | 770 | Number of seconds to sleep between L<"--iterations">. |
2460 | 311 | 771 | ||
2461 | 312 | =item -p PID | 772 | =item --iterations |
2462 | 313 | 773 | ||
2463 | 314 | Process ID of the process to trace; overrides -b | 774 | short form: -i; type: int; default: 1 |
2464 | 315 | 775 | ||
2465 | 316 | =item -s SLEEPTIME | 776 | How many traces to gather and aggregate. |
2466 | 317 | 777 | ||
2467 | 318 | Number of seconds to sleep between iterations (default 0) | 778 | =item --lines |
2468 | 779 | |||
2469 | 780 | short form: -l; type: int; default: 0 | ||
2470 | 781 | |||
2471 | 782 | Aggregate only first specified number of many functions; 0=infinity. | ||
2472 | 783 | |||
2473 | 784 | =item --pid | ||
2474 | 785 | |||
2475 | 786 | short form: -p; type: int | ||
2476 | 787 | |||
2477 | 788 | Process ID of the process to trace; overrides L<"--binary">. | ||
2478 | 789 | |||
2479 | 790 | =item --save-samples | ||
2480 | 791 | |||
2481 | 792 | short form: -k; type: string | ||
2482 | 793 | |||
2483 | 794 | Keep the raw traces in this file after aggregation. | ||
2484 | 795 | |||
2485 | 796 | =item --version | ||
2486 | 797 | |||
2487 | 798 | Show version and exit. | ||
2488 | 319 | 799 | ||
2489 | 320 | =back | 800 | =back |
2490 | 321 | 801 | ||
2491 | 322 | 802 | ||
2492 | === modified file 'bin/pt-sift' | |||
2493 | --- bin/pt-sift 2013-03-14 17:20:35 +0000 | |||
2494 | +++ bin/pt-sift 2013-04-04 21:05:27 +0000 | |||
2495 | @@ -4,15 +4,54 @@ | |||
2496 | 4 | # See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal | 4 | # See "COPYRIGHT, LICENSE, AND WARRANTY" at the end of this file for legal |
2497 | 5 | # notices and disclaimers. | 5 | # notices and disclaimers. |
2498 | 6 | 6 | ||
2505 | 7 | usage() { | 7 | # ########################################################################### |
2506 | 8 | if [ "${OPT_ERR}" ]; then | 8 | # log_warn_die package |
2507 | 9 | echo "Error: $OPT_ERR" >&2 | 9 | # This package is a copy without comments from the original. The original |
2508 | 10 | fi | 10 | # with comments and its test file can be found in the Bazaar repository at, |
2509 | 11 | echo "Usage: pt-sift FILE|PREFIX|DIRECTORY" >&2 | 11 | # lib/bash/log_warn_die.sh |
2510 | 12 | echo "For more information, 'man pt-sift' or 'perldoc $0'." >&2 | 12 | # t/lib/bash/log_warn_die.sh |
2511 | 13 | # See https://launchpad.net/percona-toolkit for more information. | ||
2512 | 14 | # ########################################################################### | ||
2513 | 15 | |||
2514 | 16 | |||
2515 | 17 | set -u | ||
2516 | 18 | |||
2517 | 19 | PTFUNCNAME="" | ||
2518 | 20 | PTDEBUG="${PTDEBUG:-""}" | ||
2519 | 21 | EXIT_STATUS=0 | ||
2520 | 22 | |||
2521 | 23 | ts() { | ||
2522 | 24 | TS=$(date +%F-%T | tr ':-' '_') | ||
2523 | 25 | echo "$TS $*" | ||
2524 | 26 | } | ||
2525 | 27 | |||
2526 | 28 | info() { | ||
2527 | 29 | [ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*" | ||
2528 | 30 | } | ||
2529 | 31 | |||
2530 | 32 | log() { | ||
2531 | 33 | [ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*" | ||
2532 | 34 | } | ||
2533 | 35 | |||
2534 | 36 | warn() { | ||
2535 | 37 | [ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2 | ||
2536 | 38 | EXIT_STATUS=1 | ||
2537 | 39 | } | ||
2538 | 40 | |||
2539 | 41 | die() { | ||
2540 | 42 | ts "$*" >&2 | ||
2541 | 43 | EXIT_STATUS=1 | ||
2542 | 13 | exit 1 | 44 | exit 1 |
2543 | 14 | } | 45 | } |
2544 | 15 | 46 | ||
2545 | 47 | _d () { | ||
2546 | 48 | [ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2 | ||
2547 | 49 | } | ||
2548 | 50 | |||
2549 | 51 | # ########################################################################### | ||
2550 | 52 | # End log_warn_die package | ||
2551 | 53 | # ########################################################################### | ||
2552 | 54 | |||
2553 | 16 | # ########################################################################### | 55 | # ########################################################################### |
2554 | 17 | # tmpdir package | 56 | # tmpdir package |
2555 | 18 | # This package is a copy without comments from the original. The original | 57 | # This package is a copy without comments from the original. The original |
2556 | @@ -55,6 +94,402 @@ | |||
2557 | 55 | # ########################################################################### | 94 | # ########################################################################### |
2558 | 56 | 95 | ||
2559 | 57 | # ########################################################################### | 96 | # ########################################################################### |
2560 | 97 | # parse_options package | ||
2561 | 98 | # This package is a copy without comments from the original. The original | ||
2562 | 99 | # with comments and its test file can be found in the Bazaar repository at, | ||
2563 | 100 | # lib/bash/parse_options.sh | ||
2564 | 101 | # t/lib/bash/parse_options.sh | ||
2565 | 102 | # See https://launchpad.net/percona-toolkit for more information. | ||
2566 | 103 | # ########################################################################### | ||
2567 | 104 | |||
2568 | 105 | |||
2569 | 106 | |||
2570 | 107 | |||
2571 | 108 | |||
2572 | 109 | set -u | ||
2573 | 110 | |||
2574 | 111 | ARGV="" # Non-option args (probably input files) | ||
2575 | 112 | EXT_ARGV="" # Everything after -- (args for an external command) | ||
2576 | 113 | HAVE_EXT_ARGV="" # Got --, everything else is put into EXT_ARGV | ||
2577 | 114 | OPT_ERRS=0 # How many command line option errors | ||
2578 | 115 | OPT_VERSION="" # If --version was specified | ||
2579 | 116 | OPT_HELP="" # If --help was specified | ||
2580 | 117 | PO_DIR="" # Directory with program option spec files | ||
2581 | 118 | |||
2582 | 119 | usage() { | ||
2583 | 120 | local file="$1" | ||
2584 | 121 | |||
2585 | 122 | local usage="$(grep '^Usage: ' "$file")" | ||
2586 | 123 | echo $usage | ||
2587 | 124 | echo | ||
2588 | 125 | echo "For more information, 'man $TOOL' or 'perldoc $file'." | ||
2589 | 126 | } | ||
2590 | 127 | |||
2591 | 128 | usage_or_errors() { | ||
2592 | 129 | local file="$1" | ||
2593 | 130 | |||
2594 | 131 | if [ "$OPT_VERSION" ]; then | ||
2595 | 132 | local version=$(grep '^pt-[^ ]\+ [0-9]' "$file") | ||
2596 | 133 | echo "$version" | ||
2597 | 134 | return 1 | ||
2598 | 135 | fi | ||
2599 | 136 | |||
2600 | 137 | if [ "$OPT_HELP" ]; then | ||
2601 | 138 | usage "$file" | ||
2602 | 139 | echo | ||
2603 | 140 | echo "Command line options:" | ||
2604 | 141 | echo | ||
2605 | 142 | perl -e ' | ||
2606 | 143 | use strict; | ||
2607 | 144 | use warnings FATAL => qw(all); | ||
2608 | 145 | my $lcol = 20; # Allow this much space for option names. | ||
2609 | 146 | my $rcol = 80 - $lcol; # The terminal is assumed to be 80 chars wide. | ||
2610 | 147 | my $name; | ||
2611 | 148 | while ( <> ) { | ||
2612 | 149 | my $line = $_; | ||
2613 | 150 | chomp $line; | ||
2614 | 151 | if ( $line =~ s/^long:/ --/ ) { | ||
2615 | 152 | $name = $line; | ||
2616 | 153 | } | ||
2617 | 154 | elsif ( $line =~ s/^desc:// ) { | ||
2618 | 155 | $line =~ s/ +$//mg; | ||
2619 | 156 | my @lines = grep { $_ } | ||
2620 | 157 | $line =~ m/(.{0,$rcol})(?:\s+|\Z)/g; | ||
2621 | 158 | if ( length($name) >= $lcol ) { | ||
2622 | 159 | print $name, "\n", (q{ } x $lcol); | ||
2623 | 160 | } | ||
2624 | 161 | else { | ||
2625 | 162 | printf "%-${lcol}s", $name; | ||
2626 | 163 | } | ||
2627 | 164 | print join("\n" . (q{ } x $lcol), @lines); | ||
2628 | 165 | print "\n"; | ||
2629 | 166 | } | ||
2630 | 167 | } | ||
2631 | 168 | ' "$PO_DIR"/* | ||
2632 | 169 | echo | ||
2633 | 170 | echo "Options and values after processing arguments:" | ||
2634 | 171 | echo | ||
2635 | 172 | ( | ||
2636 | 173 | cd "$PO_DIR" | ||
2637 | 174 | for opt in *; do | ||
2638 | 175 | local varname="OPT_$(echo "$opt" | tr a-z- A-Z_)" | ||
2639 | 176 | eval local varvalue=\$$varname | ||
2640 | 177 | if ! grep -q "type:" "$PO_DIR/$opt" >/dev/null; then | ||
2641 | 178 | if [ "$varvalue" -a "$varvalue" = "yes" ]; | ||
2642 | 179 | then varvalue="TRUE" | ||
2643 | 180 | else | ||
2644 | 181 | varvalue="FALSE" | ||
2645 | 182 | fi | ||
2646 | 183 | fi | ||
2647 | 184 | printf -- " --%-30s %s" "$opt" "${varvalue:-(No value)}" | ||
2648 | 185 | echo | ||
2649 | 186 | done | ||
2650 | 187 | ) | ||
2651 | 188 | return 1 | ||
2652 | 189 | fi | ||
2653 | 190 | |||
2654 | 191 | if [ $OPT_ERRS -gt 0 ]; then | ||
2655 | 192 | echo | ||
2656 | 193 | usage "$file" | ||
2657 | 194 | return 1 | ||
2658 | 195 | fi | ||
2659 | 196 | |||
2660 | 197 | return 0 | ||
2661 | 198 | } | ||
2662 | 199 | |||
2663 | 200 | option_error() { | ||
2664 | 201 | local err="$1" | ||
2665 | 202 | OPT_ERRS=$(($OPT_ERRS + 1)) | ||
2666 | 203 | echo "$err" >&2 | ||
2667 | 204 | } | ||
2668 | 205 | |||
2669 | 206 | parse_options() { | ||
2670 | 207 | local file="$1" | ||
2671 | 208 | shift | ||
2672 | 209 | |||
2673 | 210 | ARGV="" | ||
2674 | 211 | EXT_ARGV="" | ||
2675 | 212 | HAVE_EXT_ARGV="" | ||
2676 | 213 | OPT_ERRS=0 | ||
2677 | 214 | OPT_VERSION="" | ||
2678 | 215 | OPT_HELP="" | ||
2679 | 216 | PO_DIR="$PT_TMPDIR/po" | ||
2680 | 217 | |||
2681 | 218 | if [ ! -d "$PO_DIR" ]; then | ||
2682 | 219 | mkdir "$PO_DIR" | ||
2683 | 220 | if [ $? -ne 0 ]; then | ||
2684 | 221 | echo "Cannot mkdir $PO_DIR" >&2 | ||
2685 | 222 | exit 1 | ||
2686 | 223 | fi | ||
2687 | 224 | fi | ||
2688 | 225 | |||
2689 | 226 | rm -rf "$PO_DIR"/* | ||
2690 | 227 | if [ $? -ne 0 ]; then | ||
2691 | 228 | echo "Cannot rm -rf $PO_DIR/*" >&2 | ||
2692 | 229 | exit 1 | ||
2693 | 230 | fi | ||
2694 | 231 | |||
2695 | 232 | _parse_pod "$file" # Parse POD into program option (po) spec files | ||
2696 | 233 | _eval_po # Eval po into existence with default values | ||
2697 | 234 | |||
2698 | 235 | if [ $# -ge 2 ] && [ "$1" = "--config" ]; then | ||
2699 | 236 | shift # --config | ||
2700 | 237 | local user_config_files="$1" | ||
2701 | 238 | shift # that ^ | ||
2702 | 239 | local IFS="," | ||
2703 | 240 | for user_config_file in $user_config_files; do | ||
2704 | 241 | _parse_config_files "$user_config_file" | ||
2705 | 242 | done | ||
2706 | 243 | else | ||
2707 | 244 | _parse_config_files "/etc/percona-toolkit/percona-toolkit.conf" "/etc/percona-toolkit/$TOOL.conf" "$HOME/.percona-toolkit.conf" "$HOME/.$TOOL.conf" | ||
2708 | 245 | fi | ||
2709 | 246 | |||
2710 | 247 | _parse_command_line "${@:-""}" | ||
2711 | 248 | } | ||
2712 | 249 | |||
2713 | 250 | _parse_pod() { | ||
2714 | 251 | local file="$1" | ||
2715 | 252 | |||
2716 | 253 | cat "$file" | PO_DIR="$PO_DIR" perl -ne ' | ||
2717 | 254 | BEGIN { $/ = ""; } | ||
2718 | 255 | next unless $_ =~ m/^=head1 OPTIONS/; | ||
2719 | 256 | while ( defined(my $para = <>) ) { | ||
2720 | 257 | last if $para =~ m/^=head1/; | ||
2721 | 258 | chomp; | ||
2722 | 259 | if ( $para =~ m/^=item --(\S+)/ ) { | ||
2723 | 260 | my $opt = $1; | ||
2724 | 261 | my $file = "$ENV{PO_DIR}/$opt"; | ||
2725 | 262 | open my $opt_fh, ">", $file or die "Cannot open $file: $!"; | ||
2726 | 263 | print $opt_fh "long:$opt\n"; | ||
2727 | 264 | $para = <>; | ||
2728 | 265 | chomp; | ||
2729 | 266 | if ( $para =~ m/^[a-z ]+:/ ) { | ||
2730 | 267 | map { | ||
2731 | 268 | chomp; | ||
2732 | 269 | my ($attrib, $val) = split(/: /, $_); | ||
2733 | 270 | print $opt_fh "$attrib:$val\n"; | ||
2734 | 271 | } split(/; /, $para); | ||
2735 | 272 | $para = <>; | ||
2736 | 273 | chomp; | ||
2737 | 274 | } | ||
2738 | 275 | my ($desc) = $para =~ m/^([^?.]+)/; | ||
2739 | 276 | print $opt_fh "desc:$desc.\n"; | ||
2740 | 277 | close $opt_fh; | ||
2741 | 278 | } | ||
2742 | 279 | } | ||
2743 | 280 | last; | ||
2744 | 281 | ' | ||
2745 | 282 | } | ||
2746 | 283 | |||
2747 | 284 | _eval_po() { | ||
2748 | 285 | local IFS=":" | ||
2749 | 286 | for opt_spec in "$PO_DIR"/*; do | ||
2750 | 287 | local opt="" | ||
2751 | 288 | local default_val="" | ||
2752 | 289 | local neg=0 | ||
2753 | 290 | local size=0 | ||
2754 | 291 | while read key val; do | ||
2755 | 292 | case "$key" in | ||
2756 | 293 | long) | ||
2757 | 294 | opt=$(echo $val | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]') | ||
2758 | 295 | ;; | ||
2759 | 296 | default) | ||
2760 | 297 | default_val="$val" | ||
2761 | 298 | ;; | ||
2762 | 299 | "short form") | ||
2763 | 300 | ;; | ||
2764 | 301 | type) | ||
2765 | 302 | [ "$val" = "size" ] && size=1 | ||
2766 | 303 | ;; | ||
2767 | 304 | desc) | ||
2768 | 305 | ;; | ||
2769 | 306 | negatable) | ||
2770 | 307 | if [ "$val" = "yes" ]; then | ||
2771 | 308 | neg=1 | ||
2772 | 309 | fi | ||
2773 | 310 | ;; | ||
2774 | 311 | *) | ||
2775 | 312 | echo "Invalid attribute in $opt_spec: $line" >&2 | ||
2776 | 313 | exit 1 | ||
2777 | 314 | esac | ||
2778 | 315 | done < "$opt_spec" | ||
2779 | 316 | |||
2780 | 317 | if [ -z "$opt" ]; then | ||
2781 | 318 | echo "No long attribute in option spec $opt_spec" >&2 | ||
2782 | 319 | exit 1 | ||
2783 | 320 | fi | ||
2784 | 321 | |||
2785 | 322 | if [ $neg -eq 1 ]; then | ||
2786 | 323 | if [ -z "$default_val" ] || [ "$default_val" != "yes" ]; then | ||
2787 | 324 | echo "Option $opt_spec is negatable but not default: yes" >&2 | ||
2788 | 325 | exit 1 | ||
2789 | 326 | fi | ||
2790 | 327 | fi | ||
2791 | 328 | |||
2792 | 329 | if [ $size -eq 1 -a -n "$default_val" ]; then | ||
2793 | 330 | default_val=$(size_to_bytes $default_val) | ||
2794 | 331 | fi | ||
2795 | 332 | |||
2796 | 333 | eval "OPT_${opt}"="$default_val" | ||
2797 | 334 | done | ||
2798 | 335 | } | ||
2799 | 336 | |||
2800 | 337 | _parse_config_files() { | ||
2801 | 338 | |||
2802 | 339 | for config_file in "${@:-""}"; do | ||
2803 | 340 | test -f "$config_file" || continue | ||
2804 | 341 | |||
2805 | 342 | while read config_opt; do | ||
2806 | 343 | |||
2807 | 344 | echo "$config_opt" | grep '^[ ]*[^#]' >/dev/null 2>&1 || continue | ||
2808 | 345 | |||
2809 | 346 | config_opt="$(echo "$config_opt" | sed -e 's/^ *//g' -e 's/ *$//g' -e 's/[ ]*=[ ]*/=/' -e 's/[ ]*#.*$//')" | ||
2810 | 347 | |||
2811 | 348 | [ "$config_opt" = "" ] && continue | ||
2812 | 349 | |||
2813 | 350 | if ! [ "$HAVE_EXT_ARGV" ]; then | ||
2814 | 351 | config_opt="--$config_opt" | ||
2815 | 352 | fi | ||
2816 | 353 | |||
2817 | 354 | _parse_command_line "$config_opt" | ||
2818 | 355 | |||
2819 | 356 | done < "$config_file" | ||
2820 | 357 | |||
2821 | 358 | HAVE_EXT_ARGV="" # reset for each file | ||
2822 | 359 | |||
2823 | 360 | done | ||
2824 | 361 | } | ||
2825 | 362 | |||
2826 | 363 | _parse_command_line() { | ||
2827 | 364 | local opt="" | ||
2828 | 365 | local val="" | ||
2829 | 366 | local next_opt_is_val="" | ||
2830 | 367 | local opt_is_ok="" | ||
2831 | 368 | local opt_is_negated="" | ||
2832 | 369 | local real_opt="" | ||
2833 | 370 | local required_arg="" | ||
2834 | 371 | local spec="" | ||
2835 | 372 | |||
2836 | 373 | for opt in "${@:-""}"; do | ||
2837 | 374 | if [ "$opt" = "--" -o "$opt" = "----" ]; then | ||
2838 | 375 | HAVE_EXT_ARGV=1 | ||
2839 | 376 | continue | ||
2840 | 377 | fi | ||
2841 | 378 | if [ "$HAVE_EXT_ARGV" ]; then | ||
2842 | 379 | if [ "$EXT_ARGV" ]; then | ||
2843 | 380 | EXT_ARGV="$EXT_ARGV $opt" | ||
2844 | 381 | else | ||
2845 | 382 | EXT_ARGV="$opt" | ||
2846 | 383 | fi | ||
2847 | 384 | continue | ||
2848 | 385 | fi | ||
2849 | 386 | |||
2850 | 387 | if [ "$next_opt_is_val" ]; then | ||
2851 | 388 | next_opt_is_val="" | ||
2852 | 389 | if [ $# -eq 0 ] || [ $(expr "$opt" : "\-") -eq 1 ]; then | ||
2853 | 390 | option_error "$real_opt requires a $required_arg argument" | ||
2854 | 391 | continue | ||
2855 | 392 | fi | ||
2856 | 393 | val="$opt" | ||
2857 | 394 | opt_is_ok=1 | ||
2858 | 395 | else | ||
2859 | 396 | if [ $(expr "$opt" : "\-") -eq 0 ]; then | ||
2860 | 397 | if [ -z "$ARGV" ]; then | ||
2861 | 398 | ARGV="$opt" | ||
2862 | 399 | else | ||
2863 | 400 | ARGV="$ARGV $opt" | ||
2864 | 401 | fi | ||
2865 | 402 | continue | ||
2866 | 403 | fi | ||
2867 | 404 | |||
2868 | 405 | real_opt="$opt" | ||
2869 | 406 | |||
2870 | 407 | if $(echo $opt | grep '^--no[^-]' >/dev/null); then | ||
2871 | 408 | local base_opt=$(echo $opt | sed 's/^--no//') | ||
2872 | 409 | if [ -f "$PT_TMPDIR/po/$base_opt" ]; then | ||
2873 | 410 | opt_is_negated=1 | ||
2874 | 411 | opt="$base_opt" | ||
2875 | 412 | else | ||
2876 | 413 | opt_is_negated="" | ||
2877 | 414 | opt=$(echo $opt | sed 's/^-*//') | ||
2878 | 415 | fi | ||
2879 | 416 | else | ||
2880 | 417 | if $(echo $opt | grep '^--no-' >/dev/null); then | ||
2881 | 418 | opt_is_negated=1 | ||
2882 | 419 | opt=$(echo $opt | sed 's/^--no-//') | ||
2883 | 420 | else | ||
2884 | 421 | opt_is_negated="" | ||
2885 | 422 | opt=$(echo $opt | sed 's/^-*//') | ||
2886 | 423 | fi | ||
2887 | 424 | fi | ||
2888 | 425 | |||
2889 | 426 | if $(echo $opt | grep '^[a-z-][a-z-]*=' >/dev/null 2>&1); then | ||
2890 | 427 | val="$(echo $opt | awk -F= '{print $2}')" | ||
2891 | 428 | opt="$(echo $opt | awk -F= '{print $1}')" | ||
2892 | 429 | fi | ||
2893 | 430 | |||
2894 | 431 | if [ -f "$PT_TMPDIR/po/$opt" ]; then | ||
2895 | 432 | spec="$PT_TMPDIR/po/$opt" | ||
2896 | 433 | else | ||
2897 | 434 | spec=$(grep "^short form:-$opt\$" "$PT_TMPDIR"/po/* | cut -d ':' -f 1) | ||
2898 | 435 | if [ -z "$spec" ]; then | ||
2899 | 436 | option_error "Unknown option: $real_opt" | ||
2900 | 437 | continue | ||
2901 | 438 | fi | ||
2902 | 439 | fi | ||
2903 | 440 | |||
2904 | 441 | required_arg=$(cat "$spec" | awk -F: '/^type:/{print $2}') | ||
2905 | 442 | if [ "$required_arg" ]; then | ||
2906 | 443 | if [ "$val" ]; then | ||
2907 | 444 | opt_is_ok=1 | ||
2908 | 445 | else | ||
2909 | 446 | next_opt_is_val=1 | ||
2910 | 447 | fi | ||
2911 | 448 | else | ||
2912 | 449 | if [ "$val" ]; then | ||
2913 | 450 | option_error "Option $real_opt does not take a value" | ||
2914 | 451 | continue | ||
2915 | 452 | fi | ||
2916 | 453 | if [ "$opt_is_negated" ]; then | ||
2917 | 454 | val="" | ||
2918 | 455 | else | ||
2919 | 456 | val="yes" | ||
2920 | 457 | fi | ||
2921 | 458 | opt_is_ok=1 | ||
2922 | 459 | fi | ||
2923 | 460 | fi | ||
2924 | 461 | |||
2925 | 462 | if [ "$opt_is_ok" ]; then | ||
2926 | 463 | opt=$(cat "$spec" | grep '^long:' | cut -d':' -f2 | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]') | ||
2927 | 464 | |||
2928 | 465 | if grep "^type:size" "$spec" >/dev/null; then | ||
2929 | 466 | val=$(size_to_bytes $val) | ||
2930 | 467 | fi | ||
2931 | 468 | |||
2932 | 469 | eval "OPT_$opt"="'$val'" | ||
2933 | 470 | |||
2934 | 471 | opt="" | ||
2935 | 472 | val="" | ||
2936 | 473 | next_opt_is_val="" | ||
2937 | 474 | opt_is_ok="" | ||
2938 | 475 | opt_is_negated="" | ||
2939 | 476 | real_opt="" | ||
2940 | 477 | required_arg="" | ||
2941 | 478 | spec="" | ||
2942 | 479 | fi | ||
2943 | 480 | done | ||
2944 | 481 | } | ||
2945 | 482 | |||
2946 | 483 | size_to_bytes() { | ||
2947 | 484 | local size="$1" | ||
2948 | 485 | echo $size | perl -ne '%f=(B=>1, K=>1_024, M=>1_048_576, G=>1_073_741_824, T=>1_099_511_627_776); m/^(\d+)([kMGT])?/i; print $1 * $f{uc($2 || "B")};' | ||
2949 | 486 | } | ||
2950 | 487 | |||
2951 | 488 | # ########################################################################### | ||
2952 | 489 | # End parse_options package | ||
2953 | 490 | # ########################################################################### | ||
2954 | 491 | |||
2955 | 492 | # ########################################################################### | ||
2956 | 58 | # Global variables | 493 | # Global variables |
2957 | 59 | # ########################################################################### | 494 | # ########################################################################### |
2958 | 60 | 495 | ||
2959 | @@ -106,11 +541,6 @@ | |||
2960 | 106 | # prefix. The outcome of this block of code should be that BASEDIR is the | 541 | # prefix. The outcome of this block of code should be that BASEDIR is the |
2961 | 107 | # directory where the files live, without a trailing slash; and PREFIX is | 542 | # directory where the files live, without a trailing slash; and PREFIX is |
2962 | 108 | # either empty or a timestamp, such as "2011_02_08_16_58_07". | 543 | # either empty or a timestamp, such as "2011_02_08_16_58_07". |
2963 | 109 | if [ $# -gt 1 ]; then | ||
2964 | 110 | OPT_ERR="Specify only one PREFIX or DIR" | ||
2965 | 111 | usage | ||
2966 | 112 | fi | ||
2967 | 113 | |||
2968 | 114 | if [ $# -eq 1 ]; then | 544 | if [ $# -eq 1 ]; then |
2969 | 115 | if [ -d "$1" ]; then | 545 | if [ -d "$1" ]; then |
2970 | 116 | BASEDIR="$1" | 546 | BASEDIR="$1" |
2971 | @@ -147,9 +577,6 @@ | |||
2972 | 147 | fi | 577 | fi |
2973 | 148 | done | 578 | done |
2974 | 149 | 579 | ||
2975 | 150 | # Make a secure tmpdir. | ||
2976 | 151 | mk_tmpdir | ||
2977 | 152 | |||
2978 | 153 | # We need to generate a list of timestamps, and ask the user to choose one if | 580 | # We need to generate a list of timestamps, and ask the user to choose one if |
2979 | 154 | # there is no PREFIX yet. NOTE: we rely on the "-df" files here. | 581 | # there is no PREFIX yet. NOTE: we rely on the "-df" files here. |
2980 | 155 | ( | 582 | ( |
2981 | @@ -580,15 +1007,31 @@ | |||
2982 | 580 | ;; | 1007 | ;; |
2983 | 581 | esac | 1008 | esac |
2984 | 582 | done | 1009 | done |
2985 | 583 | |||
2986 | 584 | rm_tmpdir | ||
2987 | 585 | } | 1010 | } |
2988 | 586 | 1011 | ||
2989 | 587 | # Execute the program if it was not included from another file. This makes it | 1012 | # Execute the program if it was not included from another file. This makes it |
2990 | 588 | # possible to include without executing, and thus test. | 1013 | # possible to include without executing, and thus test. |
2991 | 589 | if [ "${0##*/}" = "$TOOL" ] \ | 1014 | if [ "${0##*/}" = "$TOOL" ] \ |
2992 | 590 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then | 1015 | || [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then |
2994 | 591 | main "${@:-""}" | 1016 | |
2995 | 1017 | mk_tmpdir | ||
2996 | 1018 | |||
2997 | 1019 | parse_options "$0" "${@:-""}" | ||
2998 | 1020 | if [ -z "$OPT_HELP" -a -z "$OPT_VERSION" ]; then | ||
2999 | 1021 | if [ $# -gt 1 ]; then | ||
3000 | 1022 | option_error "Specify only one PREFIX or DIR" | ||
3001 | 1023 | fi | ||
3002 | 1024 | fi | ||
3003 | 1025 | usage_or_errors "$0" | ||
3004 | 1026 | po_status=$? | ||
3005 | 1027 | if [ $po_status -ne 0 ]; then | ||
3006 | 1028 | [ $OPT_ERRS -gt 0 ] && exit 1 | ||
3007 | 1029 | exit 0 | ||
3008 | 1030 | fi | ||
3009 | 1031 | |||
3010 | 1032 | main "${@:-""}" | ||
3011 | 1033 | |||
3012 | 1034 | rm_tmpdir | ||
3013 | 592 | fi | 1035 | fi |
3014 | 593 | 1036 | ||
3015 | 594 | # ############################################################################ | 1037 | # ############################################################################ |
3016 | @@ -644,47 +1087,47 @@ | |||
3017 | 644 | 1087 | ||
3018 | 645 | =over | 1088 | =over |
3019 | 646 | 1089 | ||
3021 | 647 | =item d | 1090 | =item * d |
3022 | 648 | 1091 | ||
3023 | 649 | Sets the action to start the L<pt-diskstats> tool on the sample's disk | 1092 | Sets the action to start the L<pt-diskstats> tool on the sample's disk |
3024 | 650 | performance statistics. | 1093 | performance statistics. |
3025 | 651 | 1094 | ||
3027 | 652 | =item i | 1095 | =item * i |
3028 | 653 | 1096 | ||
3029 | 654 | Sets the action to view the first INNODB STATUS sample in less. | 1097 | Sets the action to view the first INNODB STATUS sample in less. |
3030 | 655 | 1098 | ||
3032 | 656 | =item m | 1099 | =item * m |
3033 | 657 | 1100 | ||
3034 | 658 | Displays the first 4 samples of SHOW STATUS counters side by side with the | 1101 | Displays the first 4 samples of SHOW STATUS counters side by side with the |
3035 | 659 | L<pt-mext> tool. | 1102 | L<pt-mext> tool. |
3036 | 660 | 1103 | ||
3038 | 661 | =item n | 1104 | =item * n |
3039 | 662 | 1105 | ||
3040 | 663 | Summarizes the first sample of netstat data in two ways: by originating host, | 1106 | Summarizes the first sample of netstat data in two ways: by originating host, |
3041 | 664 | and by connection state. | 1107 | and by connection state. |
3042 | 665 | 1108 | ||
3044 | 666 | =item j | 1109 | =item * j |
3045 | 667 | 1110 | ||
3046 | 668 | Select the next timestamp as the active sample. | 1111 | Select the next timestamp as the active sample. |
3047 | 669 | 1112 | ||
3049 | 670 | =item k | 1113 | =item * k |
3050 | 671 | 1114 | ||
3051 | 672 | Select the previous timestamp as the active sample. | 1115 | Select the previous timestamp as the active sample. |
3052 | 673 | 1116 | ||
3054 | 674 | =item q | 1117 | =item * q |
3055 | 675 | 1118 | ||
3056 | 676 | Quit the program. | 1119 | Quit the program. |
3057 | 677 | 1120 | ||
3059 | 678 | =item 1 | 1121 | =item * 1 |
3060 | 679 | 1122 | ||
3061 | 680 | Sets the action for each sample to the default, which is to view a summary | 1123 | Sets the action for each sample to the default, which is to view a summary |
3062 | 681 | of the sample. | 1124 | of the sample. |
3063 | 682 | 1125 | ||
3065 | 683 | =item 0 | 1126 | =item * 0 |
3066 | 684 | 1127 | ||
3067 | 685 | Sets the action to just list the files in the sample. | 1128 | Sets the action to just list the files in the sample. |
3068 | 686 | 1129 | ||
3070 | 687 | =item * | 1130 | =item * * |
3071 | 688 | 1131 | ||
3072 | 689 | Sets the action to view all of the sample's files in the less program. | 1132 | Sets the action to view all of the sample's files in the less program. |
3073 | 690 | 1133 | ||
3074 | @@ -692,7 +1135,17 @@ | |||
3075 | 692 | 1135 | ||
3076 | 693 | =head1 OPTIONS | 1136 | =head1 OPTIONS |
3077 | 694 | 1137 | ||
3079 | 695 | This tool does not have any command-line options. | 1138 | =over |
3080 | 1139 | |||
3081 | 1140 | =item --help | ||
3082 | 1141 | |||
3083 | 1142 | Show help and exit. | ||
3084 | 1143 | |||
3085 | 1144 | =item --version | ||
3086 | 1145 | |||
3087 | 1146 | Show version and exit. | ||
3088 | 1147 | |||
3089 | 1148 | =back | ||
3090 | 696 | 1149 | ||
3091 | 697 | =head1 ENVIRONMENT | 1150 | =head1 ENVIRONMENT |
3092 | 698 | 1151 | ||
3093 | 699 | 1152 | ||
3094 | === modified file 't/pt-mext/pt-mext.t' | |||
3095 | --- t/pt-mext/pt-mext.t 2011-08-02 21:14:06 +0000 | |||
3096 | +++ t/pt-mext/pt-mext.t 2013-04-04 21:05:27 +0000 | |||
3097 | @@ -9,7 +9,7 @@ | |||
3098 | 9 | use strict; | 9 | use strict; |
3099 | 10 | use warnings FATAL => 'all'; | 10 | use warnings FATAL => 'all'; |
3100 | 11 | use English qw(-no_match_vars); | 11 | use English qw(-no_match_vars); |
3102 | 12 | use Test::More tests => 1; | 12 | use Test::More; |
3103 | 13 | 13 | ||
3104 | 14 | use PerconaTest; | 14 | use PerconaTest; |
3105 | 15 | 15 | ||
3106 | @@ -19,7 +19,27 @@ | |||
3107 | 19 | 'It runs' | 19 | 'It runs' |
3108 | 20 | ); | 20 | ); |
3109 | 21 | 21 | ||
3110 | 22 | my $cmd = "$trunk/bin/pt-mext"; | ||
3111 | 23 | my $sample = "$trunk/t/pt-mext/samples"; | ||
3112 | 24 | |||
3113 | 25 | ok( | ||
3114 | 26 | no_diff( | ||
3115 | 27 | "$cmd -- cat $sample/mext-001.txt", | ||
3116 | 28 | "t/pt-mext/samples/mext-001-result.txt", | ||
3117 | 29 | ), | ||
3118 | 30 | "mext-001" | ||
3119 | 31 | ) or diag($test_diff); | ||
3120 | 32 | |||
3121 | 33 | ok( | ||
3122 | 34 | no_diff( | ||
3123 | 35 | "$cmd -r -- cat $sample/mext-002.txt", | ||
3124 | 36 | "t/pt-mext/samples/mext-002-result.txt", | ||
3125 | 37 | ), | ||
3126 | 38 | "mext-002 -r" | ||
3127 | 39 | ) or diag($test_diff); | ||
3128 | 40 | |||
3129 | 22 | # ############################################################################# | 41 | # ############################################################################# |
3130 | 23 | # Done. | 42 | # Done. |
3131 | 24 | # ############################################################################# | 43 | # ############################################################################# |
3132 | 44 | done_testing; | ||
3133 | 25 | exit; | 45 | exit; |
3134 | 26 | 46 | ||
3135 | === modified file 't/pt-pmp/pt-pmp.t' | |||
3136 | --- t/pt-pmp/pt-pmp.t 2013-02-04 17:04:30 +0000 | |||
3137 | +++ t/pt-pmp/pt-pmp.t 2013-04-04 21:05:27 +0000 | |||
3138 | @@ -25,7 +25,7 @@ | |||
3139 | 25 | "t/pt-pmp/samples/$outfile", | 25 | "t/pt-pmp/samples/$outfile", |
3140 | 26 | ), | 26 | ), |
3141 | 27 | "$file" | 27 | "$file" |
3143 | 28 | ); | 28 | ) or diag($test_diff); |
3144 | 29 | } | 29 | } |
3145 | 30 | closedir $dh; | 30 | closedir $dh; |
3146 | 31 | 31 | ||
3147 | @@ -35,6 +35,6 @@ | |||
3148 | 35 | "t/pt-pmp/samples/stacktrace003-limit2.out", | 35 | "t/pt-pmp/samples/stacktrace003-limit2.out", |
3149 | 36 | ), | 36 | ), |
3150 | 37 | "Limit 2 (stacktrace003-limit2.out)" | 37 | "Limit 2 (stacktrace003-limit2.out)" |
3152 | 38 | ); | 38 | ) or diag($test_diff); |
3153 | 39 | 39 | ||
3154 | 40 | done_testing; | 40 | done_testing; |