RedisTop/Perform.pm

filter: Statementstmt 13.8% 14 / 101 Branchbran 25.0% 1 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 23.0% 3 / 13 Podpod 0.0% 0 / 10 totaltotal 13.1% 18 / 137 CC 12 SCAR 23.6
CC
12
Cov
14%
build_body
30.0
run
12.0
build_header
6.0
CRAP 10.6
« RedisTop/Component.pm ↑ Summary RedisTop/Component/Save.pm »
1 package App::RedisTop::Perform;
2 1 ▶use Term::ANSIColor qw/colored/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use List::Util qw/max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use App::RedisTop::Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 my $version = eval {
7 1 require App::RedisTop;
8 1 $App::RedisTop::VERSION;
9 };
10 0 ▶if($@) { $version = '?' }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
11  
12 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my $class = shift;
14  
15 0 my $self = bless {
16 groups => [],
17 instances => [],
18 width => 20,
19 summary => {},
20 prev_stats => {},
21 @_,
22 }, $class;
23 0 my $max_len = max (map { length($_) } @{$self->{instances}});
24 0 $self->{width} = $max_len;
25 0 $self;
26 }
27  
28 0 ▶sub separator { colored("|", "blue") }
Subroutine separator: not called CC=1 SCAR=6.9
Pod undocumented
29  
30 0 ▶sub build_title {
Subroutine build_title: not called CC=1 SCAR=6.9
Pod undocumented
31 0 my @lines;
32 0 push @lines, "\033[2J\n";
33 0 push @lines, colored(sprintf("redis-top v%s\n\n", $version), "bold");
34 0 return @lines;
35 }
36  
37 0 ▶sub build_header {
Subroutine build_header: not called CC=2 SCAR=17.9
Pod undocumented
38 0 my ($self) = @_;
39 0 my $out_str = sprintf("%s ", ' ' x $self->{width});
40 0 for my $group (@{$self->{groups}}) {
41 0 $out_str .= $group->header;
42 }
43 0 return ("$out_str\n");
44 }
45  
46 0 ▶sub build_sub_header {
Subroutine build_sub_header: not called CC=2 SCAR=17.9
Pod undocumented
47 0 my ($self) = @_;
48 0 my $format = "%" . $self->{width} . "s%s";
49 0 my $out_str = colored(sprintf($format, 'INSTANCE', $self->separator), "bold");
50 0 for my $group (@{$self->{groups}}) {
51 0 $out_str .= $group->sub_header;
52 }
53 0 return ("$out_str\n");
54 }
55  
56 0 ▶sub build_line {
Subroutine build_line: not called CC=2 SCAR=17.9
Pod undocumented
57 0 my ($self, $spt) = @_;
58 0 my $out_str = colored(sprintf("%s ", $spt x $self->{width}), "blue");
59 0 for my $group (@{$self->{groups}}) {
60 0 $out_str .= $group->line($spt);
61 }
62 0 return ("$out_str\n");
63 }
64  
65 0 ▶sub build_body {
Subroutine build_body: not called CC=5 SCAR=34.0
Pod undocumented
66 0 my ($self, $instance, $stats, $prev_stats, $redis_config) = @_;
67 0 my $format = "%" . $self->{width} . "s%s";
68 0 my $out_str = sprintf($format, $instance, $self->separator);
69 0 for my $group (@{$self->{groups}}) {
70 0 $group->redis_config($redis_config);
71 0 $out_str .= $group->body($stats, $prev_stats);
72  
73 # stash total count
74 0 my @values = $group->stat_values($stats, $prev_stats);
75 0 my $key = $group->{group};
76 0 ▶ my $total_values = $self->{summary}->{$key} || [];
Condition0%0/2
$self->{'summary'}{$key} || []
l!l
00
MC/DC0%0/1
$self->{'summary'}{$key} || []
$self->{'summary'}{$key}
Truth table0%0/2
A
A= $self->{'summary'}{$key}
Aresult
11
00
77 0 ▶ for (my $i = 0; $i < scalar @values; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @values) 0 0 0
78 0 ▶ $total_values->[$i] ||= 0;
Condition0%0/2
$total_values->[$i] ||= 0
l!l
00
MC/DC0%0/1
$total_values->[$i] ||= 0
$total_values->[$i]
Truth table0%0/2
A
A= $total_values->[$i]
Aresult
11
00
79 0 $total_values->[$i] += $values[$i];
80 }
81 0 $self->{summary}->{$key} = $total_values;
82 }
83 0 return ("$out_str\n");
84 }
85  
86 0 ▶sub build_average {
Subroutine build_average: not called CC=2 SCAR=17.9
Pod undocumented
87 0 my ($self) = @_;
88 0 my $instance_count = scalar @{$self->{instances}};
89  
90 0 my $format = "%" . $self->{width} . "s%s";
91 0 my $out_str = colored(sprintf($format, 'AVERAGE', $self->separator), "bold");
92 0 for my $group (@{$self->{groups}}) {
93 0 my $key = $group->{group};
94 0 $out_str .= $group->average($self->{summary}->{$key}, $instance_count);
95 }
96 0 return ("$out_str\n");
97 }
98  
99 0 ▶sub build_total {
Subroutine build_total: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my ($self) = @_;
101 0 my $format = "%" . $self->{width} . "s%s";
102 0 my $out_str = colored(sprintf($format, 'TOTAL', $self->separator), "bold");
103 0 for my $group (@{$self->{groups}}) {
104 0 my $key = $group->{group};
105 0 $out_str .= $group->total($self->{summary}->{$key});
106 }
107 0 return ("$out_str\n");
108 }
109  
110 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod undocumented
111 0 my ($self) = @_;
112  
113 # init total
114 0 $self->{summary} = {};
115  
116 0 my @lines;
117 # build header
118 0 push @lines, $self->build_title;
119 0 push @lines, $self->build_header;
120 0 push @lines, $self->build_sub_header;
121 0 push @lines, $self->build_line('-');
122  
123 # instances loop
124 0 foreach my $instance (@{$self->{instances}}) {
125 0 my ($host, $port) = split(/:/, $instance);
126  
127 0 my $redis = App::RedisTop::Redis->new(host => $host, port => $port);
128 0 my $config = $redis->config();
129 0 my $stats = $redis->info();
130 0 my $slowlog = $redis->slowlog();
131 # add slowlog len into stats
132 0 $stats->{slowlog_len} = $slowlog;
133  
134 push @lines, $self->build_body(
135 $instance,
136 $stats,
137 0 ▶ $self->{prev_stats}->{$instance} || {},
Condition0%0/2
$self->{'prev_stats'}{$instance} || {}
l!l
00
MC/DC0%0/1
$self->{'prev_stats'}{$instance} || {}
$self->{'prev_stats'}{$instance}
Truth table0%0/2
A
A= $self->{'prev_stats'}{$instance}
Aresult
11
00
138 $config,
139 );
140 0 $self->{prev_stats}->{$instance} = $stats;
141 }
142  
143 # average
144 0 push @lines, $self->build_line(' ');
145 0 push @lines, $self->build_average();
146 # total
147 0 push @lines, $self->build_line(' ');
148 0 push @lines, $self->build_total();
149  
150 0 print join('', @lines);
151 }
152  
153 1 1;
« RedisTop/Component.pm ↑ Summary RedisTop/Component/Save.pm »