script/pidstat

filter: Statementstmt 46.5% 27 / 58 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.5% 8 / 13 Podpod n/a totaltotal 36.8% 35 / 95 SCAR 36.7
CC
10
Cov
34%
cmd_exists
110.0
__ANON__
2.0
__ANON__
2.0
CRAP 39.1
« blib/lib/IPC/PidStat.pm ↑ Summary script/lockersh »
1 #!/usr/bin/perl -w
2 # See copyright, etc in below POD section.
3 ######################################################################
4  
5 2 require 5.004;
6 2 ▶use lib './blib/lib'; # testing
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use IPC::PidStat;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ######################################################################
13 # globals
14  
15 2 ▶use vars qw($Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 ######################################################################
18 # main
19  
20 2 my %opt_new_params = (
21 );
22 2 my %opt_req_params = (
23 host => "localhost",
24 );
25 2 my $opt_silent;
26 my @params;
27  
28 2 ▶if (!GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
unless (&GetOptions("help", \&main::usage, "debug", \&main::debug, "version", \&main::version, "port=i", sub { $opt_new_params{"port"} = $_[1]; } , "host=s", sub { $opt_req_params{"host"} = $_[1]; } , "silent!", \$opt_silent, "<>", sub { push @params, shift(); } )) 0 0 0
29 "help" => \&usage,
30 "debug" => \&debug,
31 "version" => \&version,
32 0 ▶ "port=i" => sub {$opt_new_params{port} = $_[1];},
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 ▶ "host=s" => sub {$opt_req_params{host} = $_[1];},
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 "silent!" => \$opt_silent,
35 0 ▶ "<>" => sub {push @params, shift;},
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 )) {
37 0 die "%Error: Bad usage, try 'pidstat --help'\n";
38 }
39  
40 {
41 0 my $cmd = shift @params;
42 0 ▶ $cmd or die "%Error: No command specified, see --help\n";
Branch: 1 branch
BranchTrueFalseTotal
$cmd or die "%Error: No command specified, see --help\n" 0 0 0
43 0 ▶ if ($cmd eq "exists") {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq 'exists') { } 0 0 0
44 0 cmd_exists(@params);
45 } else {
46 0 die "%Error: Unknown pidstat command: $cmd\n";
47 }
48 }
49 0 exit(0);
50  
51 ######################################################################
52  
53 sub usage {
54 1 ▶ print "Version: $IPC::PidStat::VERSION\n";
Subroutine usage: called CC=1 SCAR=0.4
55 1 pod2usage(-verbose=>2, -exitval=>2, -output=>\*STDOUT, -noperldoc=>1);
56 0 exit(1);
57 }
58  
59 sub version {
60 1 ▶ print "Version: $IPC::PidStat::VERSION\n";
Subroutine version: called CC=1 SCAR=0.0
61 1 exit (1);
62 }
63  
64 sub debug {
65 0 ▶ $Debug = 1;
Subroutine debug: not called CC=1 SCAR=6.9
66 0 $IPC::PidStat::Debug = 1;
67 }
68  
69 ######################################################################
70 # Commands
71  
72 sub cmd_exists {
73 0 ▶ my @params = @_;
Subroutine cmd_exists: not called CC=10 SCAR=47.0
74  
75 0 my $exister = new IPC::PidStat(%opt_new_params,);
76 0 my $exitvalue = 0;
77 0 foreach my $remotepid (@params) {
78 0 my $host = $opt_req_params{host};
79 0 my $pid;
80 0 ▶ if ($remotepid =~ /^(.*):([0-9]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remotepid =~ /^(.*):([0-9]+)$/) { } 0 0 0
81 0 ▶ $host = $1 || "localhost";
Condition0%0/2
$1 || 'localhost'
l!l
00
MC/DC0%0/1
$1 || 'localhost'
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
82 0 $pid = $2;
83 }
84 else {
85 0 $pid = $remotepid;
86 }
87 0 my ($statpid, $status) = $exister->pid_request_recv(host=>$host, pid=>$pid);
88 0 ▶ if (defined $statpid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $statpid) { } 0 0 0
89 0 ▶ print "$host:$pid ", ($status?"up":"down"), "\n" if (!$opt_silent);
Branch: 2 branches
BranchTrueFalseTotal
unless $opt_silent 0 0 0
$status ? : 0 0 0
90 0 ▶ $exitvalue ||= 1 if (!$status);
Branch: 1 branch
BranchTrueFalseTotal
unless $status 0 0 0
Condition0%0/2
$exitvalue ||= 1
l!l
00
MC/DC0%0/1
$exitvalue ||= 1
$exitvalue
Truth table0%0/2
A
A= $exitvalue
Aresult
11
00
91 }
92 else {
93 0 ▶ print "$host:$pid ", ("host_down"), "\n" if (!$opt_silent);
Branch: 1 branch
BranchTrueFalseTotal
unless $opt_silent 0 0 0
94 0 $exitvalue = 2;
95 }
96 }
97 0 exit ($exitvalue);
98 }
99  
100 ######################################################################
101 __END__
« blib/lib/IPC/PidStat.pm ↑ Summary script/lockersh »