line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::Tracert::Statistics; |
2
|
|
|
|
|
|
|
$Win32::Tracert::Statistics::VERSION = '0.011'; |
3
|
2
|
|
|
2
|
|
38290
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1049
|
use Object::Tiny qw (input); |
|
2
|
|
|
|
|
704
|
|
|
2
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Permit access to some statistics from determined Win32::Tracert path |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#redefine constuctor |
11
|
|
|
|
|
|
|
sub new { |
12
|
3
|
|
|
3
|
0
|
525
|
my $class = shift; |
13
|
3
|
|
|
|
|
17
|
my $self = $class->SUPER::new( @_ ); |
14
|
|
|
|
|
|
|
# Extra checking and such |
15
|
3
|
100
|
|
|
|
100
|
die "You must define [input] attribute" if (! defined $self->input); |
16
|
1
|
50
|
|
|
|
32
|
die "Attending HASH REF and got something else ! \n" unless ref($self->input) eq "HASH"; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
7
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub average_responsetime_for{ |
22
|
9
|
|
|
9
|
1
|
1570
|
my ($self,$packet_sample)=@_; |
23
|
9
|
|
|
|
|
12
|
my $average_responsetime; |
24
|
|
|
|
|
|
|
my $number_of_excluded_values; |
25
|
|
|
|
|
|
|
|
26
|
9
|
|
|
|
|
10
|
foreach my $ipaddress (keys %{$self->input}){ |
|
9
|
|
|
|
|
264
|
|
27
|
9
|
|
|
|
|
51
|
my %responsetime_sample=map {$_->{HOPID} => _rounding_value_to_1($_->{$packet_sample})} @{$self->input->{$ipaddress}{HOPS}}; |
|
252
|
|
|
|
|
477
|
|
|
9
|
|
|
|
|
196
|
|
28
|
9
|
|
|
|
|
47
|
my @initial_responsetime_values=_list_responsetime_values(\%responsetime_sample); |
29
|
9
|
|
|
|
|
27
|
my @filtered_responsetime_values=_exclude_star_value(@initial_responsetime_values); |
30
|
9
|
|
|
|
|
23
|
my $sum_responsetime=0; |
31
|
9
|
|
|
|
|
12
|
map { $sum_responsetime+=$_ } @filtered_responsetime_values; |
|
243
|
|
|
|
|
307
|
|
32
|
9
|
|
|
|
|
20
|
$average_responsetime=_average_responsetime($sum_responsetime,scalar @filtered_responsetime_values); |
33
|
9
|
|
|
|
|
15
|
$number_of_excluded_values=_responsetime_values_excluded(scalar @initial_responsetime_values, scalar @filtered_responsetime_values); |
34
|
|
|
|
|
|
|
} |
35
|
9
|
|
|
|
|
28
|
return $average_responsetime, $number_of_excluded_values; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub average_responsetime_global{ |
39
|
1
|
|
|
1
|
1
|
476
|
my ($self)=@_; |
40
|
1
|
|
|
|
|
2
|
my %result; |
41
|
1
|
|
|
|
|
4
|
foreach my $packetsmp ($self->list_packet_samples){ |
42
|
3
|
|
|
|
|
11
|
my ($result,$number_of_excluded_values)=$self->average_responsetime_for("$packetsmp"); |
43
|
3
|
|
|
|
|
10
|
$result{$packetsmp}=[$result,$number_of_excluded_values]; |
44
|
|
|
|
|
|
|
} |
45
|
1
|
|
|
|
|
3
|
my $total_sample=scalar $self->list_packet_samples; |
46
|
1
|
|
|
|
|
3
|
my $sum_responsetime=0; |
47
|
1
|
|
|
|
|
2
|
my $sum_of_excluded_values=0; |
48
|
1
|
|
|
|
|
3
|
map { $sum_responsetime+=$_->[0] ; $sum_of_excluded_values+=$_->[1] } values %result; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
5
|
|
49
|
1
|
|
|
|
|
4
|
my $average_responsetime=_average_responsetime($sum_responsetime,$total_sample); |
50
|
1
|
|
|
|
|
3
|
my $average_number_of_excluded_values=$sum_of_excluded_values / $total_sample; |
51
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
5
|
return $average_responsetime, $average_number_of_excluded_values; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub list_packet_samples{ |
56
|
3
|
|
|
3
|
1
|
544
|
my ($self)=@_; |
57
|
3
|
|
|
|
|
6
|
my ($ipaddress) = keys %{$self->input}; |
|
3
|
|
|
|
|
96
|
|
58
|
3
|
|
|
|
|
19
|
my @packetsmp_list=grep {$_ =~ /PACKET/} keys %{$self->input->{$ipaddress}{HOPS}[0]}; |
|
18
|
|
|
|
|
61
|
|
|
3
|
|
|
|
|
74
|
|
59
|
3
|
|
|
|
|
10
|
return @packetsmp_list; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _list_responsetime_values{ |
63
|
9
|
|
|
9
|
|
11
|
my $responsetime_hashref=shift; |
64
|
9
|
|
|
|
|
107
|
return values %$responsetime_hashref; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _exclude_star_value{ |
68
|
9
|
|
|
9
|
|
54
|
my @values_to_check=@_; |
69
|
9
|
|
|
|
|
16
|
return grep {$_ ne '*'} @values_to_check; |
|
252
|
|
|
|
|
453
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _rounding_value_to_1{ |
73
|
252
|
|
|
252
|
|
267
|
my $value=shift; |
74
|
252
|
100
|
|
|
|
391
|
my $rounded_value = $value eq '<1' ? 1 : $value; |
75
|
252
|
|
|
|
|
625
|
return $rounded_value; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _average_responsetime{ |
79
|
10
|
|
|
10
|
|
11
|
my ($sum_of_values,$number_of_values)=@_; |
80
|
10
|
|
|
|
|
21
|
return $sum_of_values / $number_of_values; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _responsetime_values_excluded{ |
84
|
9
|
|
|
9
|
|
11
|
my ($initial_values,$filtered_values)=@_; |
85
|
9
|
|
|
|
|
102
|
return $initial_values - $filtered_values; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |