lib/Lustre/Info.pm

filter: Statementstmt 31.8% 43 / 135 Branchbran 5.8% 4 / 68 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 14 / 24 Podpod 91.6% 11 / 12 totaltotal 29.5% 72 / 244 CC 39 SCAR 32.8
CC
39
Cov
23%
_parse_brw_file
72.0
get_export_list
42.0
_parse_stats_file
42.0
CRAP 26.6
« script/lustre-info.pl ↑ Summary lib/Lustre/Info/MDT.pm »
1 #
2 # Lutre::Info Mainclass
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;
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Lustre::Info::OST;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Lustre::Info::Export;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Lustre::Info::MDT;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 require Exporter;
19 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 @ISA = qw(Exporter);
22 1 @EXPORT = qw();
23 1 @EXPORT_OK = qw();
24 1 $VERSION = '0.02';
25  
26 1 ▶use constant PROCFS_LUSTRE => "/proc/fs/lustre";
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use constant PROCFS_OBDFILTER => "/proc/fs/lustre/obdfilter";
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use constant PROCFS_MDS => "/proc/fs/lustre/mds";
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 ##########################################################################
31 # Creates a new Spy Object
32 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
33 1 my($class,%args) = @_;
34 1 my $self = {};
35 1 bless($self,$class);
36 1 return $self;
37 }
38  
39 ##########################################################################
40 # Return (uncached) list of all OBD Objects
41 1 ▶sub get_ost_list {
Subroutine get_ost_list: called CC=5 SCAR=27.8
Pod documented
42 1 my($self) = @_;
43 1 my @list = ();
44 1 ▶ opendir(OBD, PROCFS_OBDFILTER) or return \@list;
Branch: 1 branch
BranchTrueFalseTotal
opendir OBD, "/proc/fs/lustre/obdfilter" or return \@list 0 1 1
45 0 ▶ while(defined(my $dirent = readdir(OBD))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dirent = readdir OBD)) 0 0 0
46 0 ▶ next if $dirent =~ /^\./; # dotfile
Branch: 1 branch
BranchTrueFalseTotal
if $dirent =~ /^\./ 0 0 0
47 0 ▶ next if ! -d join("/",PROCFS_OBDFILTER, $dirent);
Branch: 1 branch
BranchTrueFalseTotal
unless -d join("/", "/proc/fs/lustre/obdfilter", $dirent) 0 0 0
48 0 push(@list, $dirent);
49 }
50 0 closedir(OBD);
51 0 return \@list;
52 }
53  
54 ##########################################################################
55 # Returns (uncached) list of all exports known to all OSTs
56 0 ▶sub get_export_list {
Subroutine get_export_list: not called CC=6 SCAR=37.4
Pod documented
57 0 my($self) = @_;
58 0 my $list = {};
59 0 my @osts = $self->get_ost_list;
60
61 0 foreach my $this_ost (@{$self->get_ost_list}) {
62 0 my $export_dir = PROCFS_OBDFILTER."/$this_ost/exports/";
63 0 ▶ opendir(EXP, $export_dir) or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir EXP, $export_dir or next 0 0 0
64 0 ▶ while(defined(my $dirent = readdir(EXP))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dirent = readdir EXP)) 0 0 0
65 0 ▶ next if $dirent =~ /^\./; # dotfile;
Branch: 1 branch
BranchTrueFalseTotal
if $dirent =~ /^\./ 0 0 0
66 0 ▶ next if ! -d $export_dir.$dirent;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $export_dir . $dirent 0 0 0
67 0 $list->{$dirent}++;
68 }
69 0 closedir(EXP);
70 }
71 0 my @exports = keys(%$list);
72 0 return \@exports;
73 }
74  
75 ##########################################################################
76 # Return (unchaced) list of all MTD Objects
77 0 ▶sub get_mdt_list {
Subroutine get_mdt_list: not called CC=5 SCAR=34.0
Pod documented
78 0 my @list = ();
79 0 ▶ opendir(OBD, PROCFS_MDS) or return \@list;
Branch: 1 branch
BranchTrueFalseTotal
opendir OBD, "/proc/fs/lustre/mds" or return \@list 0 0 0
80 0 ▶ while(defined(my $dirent = readdir(OBD))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dirent = readdir OBD)) 0 0 0
81 0 ▶ next if $dirent =~ /^\./; # dotfile
Branch: 1 branch
BranchTrueFalseTotal
if $dirent =~ /^\./ 0 0 0
82 0 ▶ next if ! -d join("/",PROCFS_MDS, $dirent);
Branch: 1 branch
BranchTrueFalseTotal
unless -d join("/", "/proc/fs/lustre/mds", $dirent) 0 0 0
83 0 push(@list, $dirent);
84 }
85 0 closedir(OBD);
86 0 return \@list;
87 }
88  
89 ##########################################################################
90 # Returns TRUE if current host is acting as an OST
91 1 ▶sub is_ost {
Subroutine is_ost: called CC=2 SCAR=7.6
Pod documented
92 1 ▶ return ( -d PROCFS_LUSTRE."/ost" ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
-d '/proc/fs/lustre/ost' ? : 0 1 1
93 }
94  
95 ##########################################################################
96 # Returns TRUE if current host is acting as an MDS
97 1 ▶sub is_mds {
Subroutine is_mds: called CC=2 SCAR=7.6
Pod documented
98 1 ▶ return ( -d PROCFS_LUSTRE."/mds" ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
-d '/proc/fs/lustre/mds' ? : 0 1 1
99 }
100  
101 ##########################################################################
102 # Returns TRUE if current host is acting as an MDT
103 1 ▶sub is_mdt {
Subroutine is_mdt: called CC=2 SCAR=7.6
Pod documented
104 1 ▶ return ( -d PROCFS_LUSTRE."/mdt" ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
-d '/proc/fs/lustre/mdt' ? : 0 1 1
105 }
106  
107 ##########################################################################
108 # Return object to __PACKAGE__::OST Class
109 0 ▶sub get_ost {
Subroutine get_ost: not called CC=1 SCAR=6.9
Pod documented
110 0 my($self,$ostname) = @_;
111 0 return Lustre::Info::OST->new(super=>$self, ostname=>$ostname);
112 }
113  
114 ##########################################################################
115 # Returns object to __PACKAGE__::Export Class
116 0 ▶sub get_export {
Subroutine get_export: not called CC=1 SCAR=6.9
Pod documented
117 0 my($self, $expname) = @_;
118 0 return Lustre::Info::Export->new(super=>$self, export=>$expname);
119 }
120  
121 ##########################################################################
122 # Returns object to __PACKAGE__::MDT
123 0 ▶sub get_mdt {
Subroutine get_mdt: not called CC=1 SCAR=6.9
Pod documented
124 0 my($self, $mdtname) = @_;
125 0 return Lustre::Info::MDT->new(super=>$self, mdtname=>$mdtname);
126 }
127  
128 ##########################################################################
129 # Return current lustre version (undef if lustre is not loaded)
130 0 ▶sub get_lustre_version {
Subroutine get_lustre_version: not called CC=4 SCAR=30.0
Pod documented
131 0 my $ver = undef;
132 0 ▶ open(LF, PROCFS_LUSTRE."/version") or return $ver;
Branch: 1 branch
BranchTrueFalseTotal
open LF, "/proc/fs/lustre/version" or return $ver 0 0 0
133 0 ▶ while(<LF>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline LF)) 0 0 0
134 0 ▶ if($_ =~ /^lustre: (\d.+)$/) { $ver = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^lustre: (\d.+)$/) 0 0 0
135 }
136 0 close(LF);
137 0 return $ver;
138 }
139  
140  
141  
142  
143 ##########################################################################
144 # Try to parse a lustre statistics file created by lprocfs
145 0 ▶sub _parse_stats_file {
Subroutine _parse_stats_file: not called CC=6 SCAR=37.4
146 0 my($self,$fname) = @_;
147
148 0 my $data = {};
149 0 my $snap = 0;
150 0 ▶ open(P, $fname) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open P, $fname or return undef 0 0 0
151 0 ▶ while(<P>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline P)) 0 0 0
152 # req_waittime 21932809 samples [usec] 3 1047811 9446315012 4121280741355958 (<-- sqcount)
153 0 ▶ if(my($name,$samples,$format,$min,$max,$count) = $_ =~ /^(\S+)\s+(\d+) samples \[(.+)\]\s+(\d+)\s+(\d+)\s+(\d+)[^\d]/) { # note: sqcount is not used
Branch: 3 branches
BranchTrueFalseTotal
if (() = $_ =~ /^(\S+)\s+(\d+) samples \[(.+)\]\s+(\d+)\s+(\d+)\s+(\d+)[^\d]/) { } 0 0 0
elsif (() = $_ =~ /^(\S+)\s+(\d+) samples \[(.+)\]/) { } 0 0 0
elsif ($_ =~ /^snapshot_time\s+([0-9.]+) /) { } 0 0 0
154 0 $data->{$name} = { format=>$format, samples=>$samples, count=>$count };
155 }
156 elsif(my($rqname,$rqx,$rqformat) = $_ =~ /^(\S+)\s+(\d+) samples \[(.+)\]/) {
157 0 $data->{$rqname} = { format=>$rqformat, samples=>$rqx, count=>$rqx };
158 }
159 elsif($_ =~ /^snapshot_time\s+([0-9.]+) /) {
160 0 $snap = $1;
161 }
162 }
163 0 close(P);
164 0 return({ timestamp=>$snap, data=>$data });
165 }
166  
167 ##########################################################################
168 # Try to parse the per-export 'brw' statistics file
169 0 ▶sub _parse_brw_file {
Subroutine _parse_brw_file: not called CC=8 SCAR=42.8
170 0 my($self,$fname) = @_;
171
172 0 my $ctx = '';
173 0 my $r = {};
174 0 ▶ open(P, $fname) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open P, $fname or return undef 0 0 0
175 0 ▶ while(<P>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline P)) 0 0 0
176 0 ▶ if($_ =~ /^snapshot_time:\s+([0-9.]+) /) {
Branch: 4 branches
BranchTrueFalseTotal
if ($_ =~ /^snapshot_time:\s+([0-9.]+) /) { } 0 0 0
elsif ($_ =~ /([^:]+?)(\s+)ios .+ ios/) { } 0 0 0
elsif ($_ =~ /^$/) { } 0 0 0
elsif ($ctx and $_ =~ /^(.+):\s+(\d+)\s+\d+\s+\d+\s+\|\s*(\d+)\s+\d+/) { } 0 0 0
177 0 $r->{timestamp} = $1;
178 }
179 elsif($_ =~ /([^:]+?)(\s+)ios .+ ios/) {
180 0 $ctx = lc($1);
181 0 $ctx =~ tr/a-z0-9/_/c;
182 }
183 elsif($_ =~ /^$/) {
184 0 $ctx = '';
185 }
186 ▶ elsif($ctx && $_ =~ /^(.+):\s+(\d+)\s+\d+\s+\d+\s+\|\s*(\d+)\s+\d+/) {
Condition0%0/3
$ctx and $_ =~ /^(.+):\s+(\d+)\s+\d+\s+\d+\s+\|\s*(\d+)\s+\d+/
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx and $_ =~ /^(.+):\s+(\d+)\s+\d+\s+\d+\s+\|\s*(\d+)\s+\d+/
$ctx $_ =~ /^(.+):\s+(\d+)\s+\d+\s+\d+\s+\|\s*(\d+)\s+\d+/
Truth table0%0/3
A and B
A= $ctxB= $_ =~ /^(.+):\s+(\d+)\s+\d+\s+\d+\s+\|\s*(\d+)\s+\d+/
ABresult
0X0
100
111
187 0 $r->{data}->{$ctx}->{$1} = { read=>$2, write=>$3 };
188 }
189 }
190 0 close(P);
191 0 return $r;
192 }
193  
194  
195 ##########################################################################
196 # Quick'n'dirty 'generic' parser
197 0 ▶sub _parse_generic_file {
Subroutine _parse_generic_file: not called CC=5 SCAR=34.0
198 0 my($self,$fname) = @_;
199
200 0 my $r = {};
201 0 ▶ open(P, $fname) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
open P, $fname or return undef 0 0 0
202 0 ▶ while(<P>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline P)) 0 0 0
203 0 ▶ if(my($k,$v) = $_ =~ /^(\S+):\s+(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $_ =~ /^(\S+):\s+(.+)$/) 0 0 0
204 0 ▶ if($v =~ /^(\d+)\/(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ m[^(\d+)/(\d+)$]) 0 0 0
205 0 $v = [$1,$2];
206 }
207 0 $r->{$k} = $v;
208 }
209 }
210 0 close(P);
211 0 return $r;
212 }
213  
214 ##########################################################################
215 # Perform an addition on multiple deep hashrefs
216 # This could also be implemented by using recursion but perl is somewhat
217 # slow wehn it comes to call sub()'s, so eval should be faster for very
218 # 'deep' hashes.
219 0 ▶sub sum_up_deep {
Subroutine sum_up_deep: not called CC=4 SCAR=30.0
Pod undocumented
220 0 my($self, $size, @reflist) = @_;
221
222 0 my $to_eval_h = '';
223 0 my $to_eval_m = '';
224 0 my $to_eval_b = '';
225 0 my $eval_code = undef;
226 0 my $res = {};
227 0 foreach my $tnum (0..$size) {
228 0 my $nnum = $tnum+1;
229 0 my $xtab = ( " " x $tnum );
230 0 $to_eval_h .= "${xtab}foreach my \$l$nnum (keys(%{\$lroot$to_eval_m})) {\n";
231 0 $to_eval_b = "$xtab}\n$to_eval_b";
232 0 $to_eval_m .= "->{\$l$nnum}";
233 }
234
235 # Assemble perl-loop-code:
236 0 $eval_code = "$to_eval_h\t\t\$res$to_eval_m += \$lroot$to_eval_m\n".$to_eval_b;
237
238 #..and execute for each given hashref
239 0 foreach my $lroot (@reflist) {
240 0 eval $eval_code;
241 0 ▶ return undef if $@; # error? -> most likely caused by an invalid $size setting!
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
242 }
243 0 return $res;
244 }
245  
246  
247 1 1;
248 __END__
« script/lustre-info.pl ↑ Summary lib/Lustre/Info/MDT.pm »