| 1 | package PBS::Logs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | PBS::Logs - general parser for PBS log files | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | See the sections below: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | use PBS::Logs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head2 EXPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | None by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =item The PBS Pro 5.4 Administrator Guide | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =item PBS::Logs::Acct | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =item PBS::Logs::Event | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | Dr R K Owen, E<lt>rkowen@nersc.govE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | Copyright (C) 2005 The Regents of the University of California | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | This library is free software; you can redistribute it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | and/or modify it under the terms of the GNU Lesser General | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | Public License as published by the Free Software Foundation; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | either version 2.1 of the License, or (at your option) any | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | This library is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | but WITHOUT ANY WARRANTY; without even the implied warranty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | the GNU Lesser General Public License for more details, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | which can be found at: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | http://www.gnu.org/copyleft/lesser.html | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | or http://www.opensource.org/licenses/lgpl-license.php | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 44 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 44 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 44 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 44 | ▶ | use Time::Local; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 44 | our @ISA = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 44 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 44 | my $debug = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 44 | my $datetime_regex = '(\d{2})/(\d{2})/(\d{4}) (\d{2}):(\d{2}):(\d{2})'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 44 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 44 | my @fields = qw{input type}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # construct read-only accessor functions here - no need for AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 44 | foreach my $f (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 88 | my $code = "package ".__PACKAGE__.";\n" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | .qq{sub $f { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | my \$self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | carp __PACKAGE__."->$f \$self (".join(',',\@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | if (\$debug || \$self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | \$self->{'$f'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | eval $code; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input: not called CC=3 SCAR=16.9
Subroutine
type: called CC=3 SCAR=16.9
Pod
undocumented
Pod
undocumented
Branch: 2 branches
Condition16%1/6
$debug or $self->{"-debug"}
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table0%0/3
A or B
A= $debugB= $self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # Preloaded methods go here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head1 new('file_name') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | =head1 new(\@array_ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =head1 new(\*FILE_HANDLE) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | Create a PBS::Logs object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | It takes only one argument which is either a filename, array reference, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | or a FILE glob reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | Pass a PBS log file name to read: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | my $pl = new PBS::Logs('/var/spool/PBS/server_logs/20050512'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Slurp the file into an array and pass the array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | open PL, '/var/spool/PBS/server_logs/20050512' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | || die "can not open log"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | my @pl = <PL>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | my $pl = new PBS::Logs(\@pl); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | Or finally, pass a FILEHANDLE glob. This can be useful if creating a filter. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | my $pl = new PBS::Logs(\*STDIN); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 48 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 48 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 48 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 48 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | '-debug' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | '-lastline' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | '-start' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | '-end' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 'input' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 'line' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'type' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | carp __PACKAGE__.": creating $self\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 48 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 48 | my $x = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 48 | ▶ | if (ref $x eq "ARRAY") { # slurped ARRAY | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 26 | $self->{'input'} = $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 26 | $self->{'type'} = 'ARRAY'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } elsif (ref $x eq "GLOB") { # FILEHANDLE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | $self->{'input'} = $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | $self->{'type'} = 'FILTER'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } elsif (! ref $x) { # filename | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 10 | ▶ | open PBSIN, $x | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | or croak __PACKAGE__.": new - can not open '$x'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | $self->{'input'} = \*PBSIN; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | $self->{'type'} = 'FILE'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | croak __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | .": new - must pass either filename, array reference, " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ."or filehandle glob ... not ".ref($x)." '$x'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 42 | bless ($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 42 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 42 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | carp __PACKAGE__.": destroying $self\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 42 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 42 | ▶ | close $self->{'input'} if ref $self->{'input'} eq "GLOB"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 44 | ▶ | sub END { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 44 | ▶ | carp __PACKAGE__.": ending\n" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | if ($debug); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | =head1 debug([enable]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | Debugging can be enabled for the entire class by calling | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | C<PBS::Logs::debug(1)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | Or debugging can be enabled for a single object with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | C<$obj-E<gt>debug(1)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | To disable debugging just set to 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Calling either form with no argument will just cause | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | the current value to be returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 16 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 16 | ▶ | if (index(ref($self), __PACKAGE__) == 0) { # just myself | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | @_ ? $self->{'-debug'} = shift | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | ▶ | : $self->{'-debug'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } else { # whole class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | ▶ | defined($self) ? $debug = $self | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | : $debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | =head1 line() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | Return the "log line number" that will be read next (zero based), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | and returns -1 when at the "end of file". (Remember the "file" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | could have been slurped into an array.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1169 | ▶ | sub line { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1169 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | carp __PACKAGE__." : line $self (".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1169 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1169 | ▶ | return undef if ! defined $self->{'line'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # the line count is always high by one since we must pre-read a line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1153 | ▶ | $self->{'line'} > 0 ? $self->{'line'} - 1 : $self->{'line'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | =head1 current() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | Return the "current" concatenated PBS record that has been read and that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | meets the selection criterion. Remember, though, that actuall PBS logs can | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | have a record that is spread across multiple lines. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | New records begin with a date/time-stamp. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | This gives the entire record as one line. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1231 | ▶ | sub current { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1231 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | carp __PACKAGE__." : current $self (".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1231 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1231 | ▶ | return undef if ! defined $self->{'current'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1015 | $self->{'current'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | =head1 start() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | Begin reading at the start of the log, if not a filter. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 66 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=6 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 66 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | carp __PACKAGE__.": start $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 66 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 66 | ▶ | if ($self->{'type'} eq "FILE") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | seek $self->{'input'}, 0, 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | or croak __PACKAGE__.": start - can not seek on file"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 66 | $self->{'-lastline'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 66 | ▶ | $self->{'line'} = 0 if ($self->{'type'} ne 'FILTER'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 66 | $self->{'current'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | =head1 end() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | End reading of the log and close it out, if not a filter. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | Sets all the internal values to undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 16 | ▶ | sub end { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | carp __PACKAGE__.": end $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 16 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 16 | ▶ | if ($self->{'type'} eq "FILE") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 8 | close $self->{'input'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 16 | $self->{'-lastline'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 16 | $self->{'-start'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 16 | $self->{'-end'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 16 | $self->{'input'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 16 | $self->{'line'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 16 | $self->{'current'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 16 | $self->{'type'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | #=head1 getline() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | #Get the next text line from the log returning a string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # (stripped of trailing \n's). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | #This method is used internally only, and should not be called directly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | #=cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4633 | ▶ | sub getline { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getline: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 4633 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | carp __PACKAGE__.": getline $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 4633 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4633 | my $l = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4633 | ▶ | if ($self->{'type'} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | $l = $self->{'input'}->[$self->{'line'}] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 3709 | if scalar @{$self->{'input'}} > $self->{'line'} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 3709 | ▶ | && $self->{'line'} != -1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @{$self->{"input"};} > $self->{"line"} and $self->{"line"} != -1
MC/DC100%2/2
scalar @{$self->{"input"};} > $self->{"line"} and $self->{"line"} != -1
scalar @{$self->{"input"};} > $self->{"line"}
$self->{"line"} != -1
Truth table100%3/3
A and B
A= scalar @{$self->{"input"};} > $self->{"line"}B= $self->{"line"} != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | $l = readline $self->{'input'} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 924 | ▶ | if not eof($self->{'input'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 4633 | ▶ | if (defined $l) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4485 | chomp $l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 4485 | $self->{'line'}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } else { # reached EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 148 | $self->{'line'} = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 148 | $self->{'current'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 4633 | $l; # return array ref | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | #=head1 getdata() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | #Get the next data batch from the log returning an array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | #of elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | #This method is used internally only, and should not be called directly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | #=cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1389 | ▶ | sub getdata { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getdata: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1389 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | carp __PACKAGE__.": getdata $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1389 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1389 | my ($a,$l,$line) = (undef,undef,$self->{'-lastline'}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1389 | ▶ | $line = $self->getline() if ! defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 1389 | ▶ | while ($l = $self->getline()) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 4385 | ▶ | last if ! defined $l; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4385 | ▶ | if ($l =~ /^$datetime_regex/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1265 | $self->{'-lastline'} = $l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1265 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } else { # a continuation record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 3120 | $line .= " $l"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1389 | ▶ | $self->{'-lastline'} = undef if ! defined $l; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1389 | ▶ | if (defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1365 | $a = [split(';',$line)]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1365 | $self->{'current'} = $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 24 | $self->{'current'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1389 | $a; # return array ref | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =head1 get() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | Get the next entry from the log and return as an array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | if in an scalar context, else return a list if called otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | $a = $pl->get(); # returns array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | @a = $pl->get(); # returns array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | However, at the end of the log the array reference context will return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | and the array context will return an empty list (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1243 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=13 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1243 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | carp __PACKAGE__.": get $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1243 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1243 | ▶ | if ($self->{'line'} == -1) { # nothing to do at EOF | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 76 | $self->{'current'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 76 | ▶ | return () if (wantarray); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 61 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # my ($a,$l,$line) = (undef,undef,$self->{'-lastline'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1167 | my $a; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1167 | ▶ | while ($a = $self->getdata()) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1365 | my $dt = $self->datetime($a->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | next if defined($self->{'-start'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1365 | ▶ | && ($dt < $self->{'-start'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"-start"} and $dt < $self->{"-start"}
MC/DC100%2/2
defined $self->{"-start"} and $dt < $self->{"-start"}
defined $self->{"-start"}
$dt < $self->{"-start"}
Truth table100%3/3
A and B
A= defined $self->{"-start"}B= $dt < $self->{"-start"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | next if defined($self->{'-end'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1275 | ▶ | && ($dt > $self->{'-end'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"-end"} and $dt > $self->{"-end"}
MC/DC100%2/2
defined $self->{"-end"} and $dt > $self->{"-end"}
defined $self->{"-end"}
$dt > $self->{"-end"}
Truth table100%3/3
A and B
A= defined $self->{"-end"}B= $dt > $self->{"-end"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1143 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1167 | ▶ | return if ! defined wantarray; # just read log line | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1167 | ▶ | return (defined $a ? @$a : ()) if (wantarray); # return array | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 967 | $a; # return array ref | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | =head1 datetime($datetime) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | Parse the PBS date-time string and return the number of seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | since the epoch if in a scalar context (UTC time), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | or return a 6-element array similar to the gmtime() or localtime() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | functions with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | (0:$sec, 1:$min, 2:$hour, 3:$mday, 4:$mon, 5:$year) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | where $mon is in the range 0..11 and $year is a 4-digit year. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | $dt = '02/01/2005 18:48:10'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | $a = $pl->datetime($dt); # returns seconds since January 1, 1970 UTC | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | @a = $pl->datetime($dt); # returns array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1409 | ▶ | sub datetime { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
datetime: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1409 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | carp __PACKAGE__.": datetime $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1409 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1409 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1409 | ▶ | carp __PACKAGE__.": datetime : received an undefined value" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | if ! defined $dt; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1409 | my @dt = $dt =~ /$datetime_regex/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1409 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # rewrite in proper order | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | return ($dt[5],$dt[4],$dt[3],$dt[1],$dt[0]-1,$dt[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1409 | return timegm($dt[5],$dt[4],$dt[3],$dt[1],$dt[0]-1,$dt[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | =head1 filter_datetime([start,end]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | Sets or reads the datetime filter for the get() method. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | get() will only retrieve lines that have a datetime between | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | "start" and "end" inclusive. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | Either one can be 'none' to signify that no filtering will be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | performed with respect to that time endpoint. No filtering is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | essentially ('none','none'). Or just do not call this method. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | The start or end value can be given either in the PBS datetime | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | format ( DD/MM/YYYY HH:MM:SS ) or in seconds from the epoch. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | It will return '1' if successful, else undef if some warning occurs. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | If no arguments are given then the method will return an array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | (start,end) where the values are in seconds since the epoch. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 96 | ▶ | sub filter_datetime { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter_datetime: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 96 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | carp __PACKAGE__.": filter_datetime $self(".join(',',@_).")\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 96 | ▶ | if ($debug || $self->{'-debug'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$debug or $self->{"-debug"}
MC/DC0%0/2
$debug or $self->{"-debug"}
$debug
$self->{"-debug"}
Truth table33%1/3
A or B
A= $debugB= $self->{"-debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 96 | my ($st,$et) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 96 | ▶ | return ($self->{'-start'}, $self->{'-end'}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | if (! defined $st); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 69 | ▶ | if (! defined $et) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 3 | carp __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | .": filter_datetime : received an undefined value"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 66 | ▶ | if ($st eq 'none') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 32 | $self->{'-start'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } elsif ($st =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 6 | $self->{'-start'} = $st; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } elsif ($st =~ /^$datetime_regex$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 22 | $self->{'-start'} = $self->datetime($st); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 6 | carp __PACKAGE__.": filter_datetime : bad start value = '" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | .$st."'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 6 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 60 | ▶ | if ($et eq 'none') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 26 | $self->{'-end'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } elsif ($et =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 6 | $self->{'-end'} = $et; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } elsif ($et =~ /^$datetime_regex$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 22 | $self->{'-end'} = $self->datetime($et); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 6 | carp __PACKAGE__.": filter_datetime : bad end value = '" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | .$et."'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 6 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 54 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 44 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||