Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory detection warnings on Solaris #1629

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Revision history for Rex
[BUG FIXES]
- Fix precedence warning after perl-5.41.4
- Fix missing argument warnings from Text::Wrap
- Fix memory detection warnings on Solaris

[DOCUMENTATION]

Expand Down
38 changes: 24 additions & 14 deletions lib/Rex/Hardware/Memory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use warnings;

our $VERSION = '9999.99.99_99'; # VERSION

use English qw(-no_match_vars);
use Rex::Hardware::Host;
use Rex::Commands::Run;
use Rex::Helper::Run;
Expand Down Expand Up @@ -54,25 +55,34 @@ sub get {
elsif ( $os eq "SunOS" ) {
my @data = i_run "echo ::memstat | mdb -k", fail_ok => 1;

my ($free_cache) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data;
my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data;
my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data;
if ( $CHILD_ERROR == 0 ) {
my ($free_cache) =
map { /\D+\d+\s+(\d+)/ } grep { /^Free \(cache/ } @data;
my ($free_list) = map { /\D+\d+\s+(\d+)/ } grep { /^Free \(freel/ } @data;
my ($page_cache) = map { /\s+\d+\s+(\d+)/ } grep { /^Page cache/ } @data;

my $free = $free_cache + $free_list;
my $free = $free_cache + $free_list;

#my ($total, $total_e) = grep { $_=$1 if /^Memory Size: (\d+) ([a-z])/i } i_run "prtconf";
my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data;
my ($total) = map { /\s+\d+\s+(\d+)/ } grep { /^Total/ } @data;

&$convert( $free, "M" );
&$convert( $total, "M" );
my $used = $total - $free;

$data = {
used => $used,
total => $total,
free => $free,
};
&$convert( $free, "M" );
&$convert( $total, "M" );
my $used = $total - $free;

$data = {
used => $used,
total => $total,
free => $free,
};
}
else {
$data = {
used => 0,
total => 0,
free => 0,
};
}
}
elsif ( $os eq "OpenBSD" ) {
my $mem_str = i_run "top -d1 | grep Memory:", fail_ok => 1;
Expand Down