File Coverage

blib/lib/Lustre/Info/Export.pm
Criterion Covered Total %
statement 6 62 9.6
branch 0 16 0.0
condition 0 6 0.0
subroutine 2 10 20.0
pod 5 8 62.5
total 13 102 12.7


line stmt bran cond sub pod time code
1             #
2             # Lustre NID/export Subclass
3             #
4             # (C) 2010 Adrian Ulrich -
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::Export;
11 1     1   4 use strict;
  1         2  
  1         33  
12 1     1   5 use warnings;
  1         2  
  1         834  
13              
14              
15             ##########################################################################
16             # Returns a new Export Object
17             sub new {
18 0     0 0   my($classname, %args) = @_;
19 0           my $self = { super=>$args{super}, export=>$args{export}, export_stats=>{}, graph_stats=>[{},{}] };
20 0           bless($self,$classname);
21             }
22              
23             ##########################################################################
24             # Return name of this nid
25             sub get_name {
26 0     0 1   my($self) = @_;
27 0           return $self->{export};
28             }
29              
30             ##########################################################################
31             # AB(uses) the OST-Module to get statistics for this client
32             sub collect_export_stats {
33 0     0 1   my($self, $ostlist) = @_;
34            
35 0 0         $ostlist = $self->{super}->get_ost_list if !$ostlist;
36            
37 0           foreach my $ost (@$ostlist) {
38 0   0       $self->{export_stats}->{$ost} ||= $self->{super}->get_ost($ost); # Creates a new ost-object if empty
39 0           $self->{export_stats}->{$ost}->collect_client_stats([$self->get_name]); # collect stats for this-client only
40             }
41            
42 0           return undef;
43             }
44              
45             ##########################################################################
46             # Return per-ost statistics of this NID/EXPORT
47             sub get_export_stats {
48 0     0 1   my($self) = @_;
49            
50 0           my $es = $self->{export_stats};
51 0           my $r = {};
52 0           foreach my $ost_name (keys(%$es)) {
53 0           my $ost_ref = $es->{$ost_name};
54 0           my $stats = $ost_ref->get_client_stats;
55 0           $r->{$ost_name} = $stats->{$self->get_name};
56             }
57 0           return $r;
58             }
59              
60             ##########################################################################
61             # Undocumented alias for get_export_stats
62             sub get_client_stats {
63 0     0 0   my($self) = @_;
64 0           return $self->get_export_stats;
65             }
66              
67             ##########################################################################
68             # undocumented alias for collect_export_stats
69             sub collect_client_stats {
70 0     0 0   my($self) = @_;
71 0           return $self->collect_export_stats;
72             }
73              
74             sub collect_brw_stats {
75 0     0 1   my($self, $ostlist) = @_;
76            
77 0 0         $ostlist = $self->{super}->get_ost_list if !$ostlist;
78            
79 0           my $own_name = $self->get_name;
80 0           my $tstamp = 0;
81 0           my $junk = {};
82 0           foreach my $ost (@$ostlist) {
83 0           my $pfs_file = "/proc/fs/lustre/obdfilter/$ost/exports/$own_name/brw_stats";
84 0 0         next unless -f $pfs_file;
85 0           my $ref = $self->{super}->_parse_brw_file($pfs_file);
86 0   0       $tstamp ||= $ref->{timestamp};
87 0           $junk = $self->{super}->sum_up_deep(2, $ref->{data}, $junk);
88             }
89            
90 0           $junk->{timestamp} = $tstamp; # Add first timestamp to ref (as expected by get_*_stats)
91            
92 0           my $stats_ref = $self->{graph_stats};
93 0           shift(@$stats_ref);
94 0           push(@$stats_ref, $junk);
95 0           return $junk;
96             }
97              
98             sub get_brw_stats {
99 0     0 1   my($self) = @_;
100            
101 0           my $r1 = $self->{graph_stats}->[0];
102 0           my $r2 = $self->{graph_stats}->[1];
103 0 0         my $ts1 = $r1->{timestamp} or return undef;
104 0 0         my $ts2 = $r2->{timestamp} or return undef;
105 0           my $junk = {};
106            
107 0           foreach my $label (keys(%$r1)) {
108 0           my $rx = $r1->{$label};
109 0 0         next if ref($rx) ne 'HASH';
110 0 0         next if !exists($r2->{$label});
111            
112 0           foreach my $line (keys(%$rx)) {
113 0 0         next if !exists($r2->{$label}->{$line});
114 0           foreach my $action (keys(%{$rx->{$line}})) {
  0            
115 0           my $value = $r2->{$label}->{$line}->{$action} - $r1->{$label}->{$line}->{$action};
116 0           $junk->{$label}->{$line}->{$action} = $value;
117             }
118             }
119             }
120 0           return({_slice=>($ts2-$ts1), data=>$junk});
121             }
122              
123              
124             1;
125             __END__