lib/Lustre/Info/OST.pm

filter: Statementstmt 13.5% 11 / 81 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 17.6% 3 / 17 Podpod 84.6% 11 / 13 totaltotal 16.0% 25 / 156 CC 23 SCAR 33.3
CC
23
Cov
9%
get_client_stats
56.0
get_ost_stats
42.0
get_exports
42.0
CRAP 27.9
« lib/Lustre/Info/Export.pm ↑ Summary script/lustre-info.pl »
1 #
2 # Lustre OST/OSS subclass
3 #
4 # (C) 2010 Adrian Ulrich - <adrian.ulrich@id.ethz.ch>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the same terms as Perl itself.
8 #
9 #
10 package Lustre::Info::OST;
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use constant PROCFS_OBDFILTER => '/proc/fs/lustre/obdfilter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 my @TRACK_FIELDS = qw(write_bytes read_bytes create destroy setattr ping preprw);
16  
17 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my($classname, %args) = @_;
19 0 my $self = { super=>$args{super}, ostname=>$args{ostname}, procpath=>PROCFS_OBDFILTER."/$args{ostname}", ost_stats=> [ {}, {} ], client_stats=>{} };
20 0 bless($self,$classname);
21 0 ▶ return ( -d $self->{procpath} ? $self : undef );
Branch: 1 branch
BranchTrueFalseTotal
-d $self->{'procpath'} ? : 0 0 0
22 }
23  
24  
25 ##########################################################################
26 # Return name of OST
27 0 ▶sub get_name {
Subroutine get_name: not called CC=1 SCAR=6.9
Pod documented
28 0 my($self) = @_;
29 0 return $self->{ostname};
30 }
31  
32 ##########################################################################
33 # Return the size of this OST
34 0 ▶sub get_kbytes_total { return $_[0]->_rint('kbytestotal'); }
Subroutine get_kbytes_total: not called CC=1 SCAR=6.9
Pod documented
35  
36 ##########################################################################
37 # Return how much space is free
38 0 ▶sub get_kbytes_free { return $_[0]->_rint('kbytesfree'); }
Subroutine get_kbytes_free: not called CC=1 SCAR=6.9
Pod documented
39  
40 ##########################################################################
41 # # of pre-allocated inodes (at mkfs.lustre runtime)
42 0 ▶sub get_files_total { return $_[0]->_rint('filestotal'); }
Subroutine get_files_total: not called CC=1 SCAR=6.9
Pod documented
43  
44 ##########################################################################
45 # How many files/inodes are free
46 0 ▶sub get_files_free { return $_[0]->_rint('filesfree'); }
Subroutine get_files_free: not called CC=1 SCAR=6.9
Pod documented
47  
48 ##########################################################################
49 # Returns the name of the hosting blockdevice
50 0 ▶sub get_blockdevice { return $_[0]->_rint('mntdev'); }
Subroutine get_blockdevice: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 ##########################################################################
53 # Parse and return information about the last recovery procedure
54 0 ▶sub get_recovery_info {
Subroutine get_recovery_info: not called CC=1 SCAR=6.9
Pod documented
55 0 my($self) = @_;
56 0 return $self->{super}->_parse_generic_file($self->{procpath}."/recovery_status");
57 }
58  
59 ##########################################################################
60 # Update stats of this OST
61 0 ▶sub collect_ost_stats {
Subroutine collect_ost_stats: not called CC=1 SCAR=6.9
Pod documented
62 0 my($self) = @_;
63 0 my $data = $self->{super}->_parse_stats_file($self->{procpath}."/stats");
64 0 my $stats = $self->{ost_stats};
65 0 shift(@$stats);
66 0 push(@{$stats}, $data);
67 0 return $stats;
68 }
69  
70 ##########################################################################
71 # Return stats for this OST
72 0 ▶sub get_ost_stats {
Subroutine get_ost_stats: not called CC=6 SCAR=37.4
Pod documented
73 0 my($self) = @_;
74
75 0 my $a = $self->{ost_stats}->[0];
76 0 my $b = $self->{ost_stats}->[1];
77 0 my $r = {};
78 0 ▶ return undef if !exists($a->{data}); # not enough data
Branch: 1 branch
BranchTrueFalseTotal
unless exists $a->{"data"} 0 0 0
79 0 ▶ return undef if !exists($b->{data});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $b->{"data"} 0 0 0
80
81 0 $r->{_slice} = $b->{timestamp} - $a->{timestamp};
82 0 foreach my $k (@TRACK_FIELDS) {
83 $r->{$k} = $b->{data}->{$k}->{count} - $a->{data}->{$k}->{count} if
84 0 ▶ exists($a->{data}->{$k}) && exists($b->{data}->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $a->{"data"}{$k} and exists $b->{"data"}{$k} 0 0 0
Condition0%0/3
exists $a->{"data"}{$k} and exists $b->{"data"}{$k}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $a->{"data"}{$k} and exists $b->{"data"}{$k}
exists $a->{"data"}{$k} exists $b->{"data"}{$k}
Truth table0%0/3
A and B
A= exists $a->{"data"}{$k}B= exists $b->{"data"}{$k}
ABresult
0X0
100
111
85 }
86 0 return $r;
87 }
88  
89  
90 ##########################################################################
91 # Collect statistics for ALL connected clients of this OST. This is expensive!
92 0 ▶sub collect_client_stats {
Subroutine collect_client_stats: not called CC=5 SCAR=34.0
Pod documented
93 0 my($self, $clist) = @_;
94
95 0 ▶ $clist = $self->get_exports if !$clist;
Branch: 1 branch
BranchTrueFalseTotal
unless $clist 0 0 0
96
97 0 foreach my $eid (@$clist) {
98 0 ▶ my $data = $self->{super}->_parse_stats_file($self->{procpath}."/exports/$eid/stats") or next;
Branch: 1 branch
BranchTrueFalseTotal
my $data = $self->{"super"}->_parse_stats_file($self->{"procpath"} . "/exports/$eid/stats") or next 0 0 0
99 0 ▶ if(!exists($self->{client_stats}->{$eid})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"client_stats"}{$eid}) 0 0 0
100 0 $self->{client_stats}->{$eid} = [ {}, {} ]; # init empty struct on first run
101 }
102
103 0 my $ref = $self->{client_stats}->{$eid};
104 0 shift(@$ref);
105 0 push(@$ref, $data);
106 }
107 0 return $self->{client_stats}; # return most recent entry.
108 }
109  
110 ##########################################################################
111 # Returns statistics for all clients on this OST
112 0 ▶sub get_client_stats {
Subroutine get_client_stats: not called CC=7 SCAR=40.3
Pod documented
113 0 my($self) = @_;
114
115 0 my $r = {};
116 0 foreach my $eid (keys(%{$self->{client_stats}})) {
117 0 my $this_ref = $self->{client_stats}->{$eid}; # holds: [ {timestamp=>0, data=>{}}, {timestamp=>0, data=>{}} ]
118 0 my $a = $this_ref->[0];
119 0 my $b = $this_ref->[1];
120 0 ▶ next if !exists($a->{data}) or !exists($b->{data}); # all zero or not enough data;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $a->{"data"} and exists $b->{"data"} 0 0 0
Condition0%0/3
exists $a->{"data"} and exists $b->{"data"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $a->{"data"} and exists $b->{"data"}
exists $a->{"data"} exists $b->{"data"}
Truth table0%0/3
A and B
A= exists $a->{"data"}B= exists $b->{"data"}
ABresult
0X0
100
111
121
122 0 $r->{$eid}->{_slice} = $b->{timestamp} - $a->{timestamp};
123 0 map { $r->{$eid}->{$_} = 0 } @TRACK_FIELDS;
124
125 0 foreach my $k (@TRACK_FIELDS) {
126 $r->{$eid}->{$k} = $b->{data}->{$k}->{count} - $a->{data}->{$k}->{count} if
127 0 ▶ exists($a->{data}->{$k}) && exists($b->{data}->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $a->{"data"}{$k} and exists $b->{"data"}{$k} 0 0 0
Condition0%0/3
exists $a->{"data"}{$k} and exists $b->{"data"}{$k}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $a->{"data"}{$k} and exists $b->{"data"}{$k}
exists $a->{"data"}{$k} exists $b->{"data"}{$k}
Truth table0%0/3
A and B
A= exists $a->{"data"}{$k}B= exists $b->{"data"}{$k}
ABresult
0X0
100
111
128 }
129 }
130 0 return $r;
131 }
132  
133 ##########################################################################
134 # Returns a list to all 'known' exports of this OST
135 0 ▶sub get_exports {
Subroutine get_exports: not called CC=6 SCAR=37.4
Pod documented
136 0 my($self) = @_;
137
138 0 my @list = ();
139 0 ▶ opendir(PD, $self->{procpath}."/exports/") or return \@list;
Branch: 1 branch
BranchTrueFalseTotal
opendir PD, $self->{"procpath"} . '/exports/' or return \@list 0 0 0
140 0 ▶ while(defined(my $dirent = readdir(PD))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dirent = readdir PD)) 0 0 0
141 0 ▶ next if $dirent eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $dirent eq "." 0 0 0
142 0 ▶ next if $dirent eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $dirent eq ".." 0 0 0
143 0 ▶ next unless -d $self->{procpath}."/exports/$dirent";
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->{"procpath"} . "/exports/$dirent" 0 0 0
144 0 push(@list,$dirent);
145 }
146 0 closedir(PD);
147 0 return \@list;
148 }
149  
150  
151  
152 ##########################################################################
153 # Return an integer
154 0 ▶sub _rint {
Subroutine _rint: not called CC=2 SCAR=17.9
155 0 my($self,$procfile) = @_;
156 0 ▶ open(PF, $self->{procpath}."/$procfile") or return -1;
Branch: 1 branch
BranchTrueFalseTotal
open PF, $self->{"procpath"} . "/$procfile" or return -1 0 0 0
157 0 my $num = <PF>; chomp($num);
158 0 close(PF);
159 0 return $num;
160 }
161  
162  
163 1 1;
164 __END__
« lib/Lustre/Info/Export.pm ↑ Summary script/lustre-info.pl »