| 1 | package System::Info; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | our $VERSION = "0.069"; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use base "Exporter"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | our @EXPORT_OK = qw( &sysinfo &sysinfo_hash &si_uname ); | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use System::Info::AIX; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use System::Info::BSD; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use System::Info::Cygwin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 2 | ▶ | use System::Info::Darwin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 2 | ▶ | use System::Info::Generic; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use System::Info::Haiku; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 2 | ▶ | use System::Info::HPUX; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 2 | ▶ | use System::Info::Irix; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 2 | ▶ | use System::Info::Linux; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 2 | ▶ | use System::Info::Solaris; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 2 | ▶ | use System::Info::VMS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 2 | ▶ | use System::Info::Windows; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | System::Info - Factory for system specific information objects | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | use System::Info; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | my $si = System::Info->new; | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | printf "Hostname: %s\n", $si->host; | ||||||||||||||||||||
| 35 | printf "Number of CPU's: %s\n", $si->ncpu; | ||||||||||||||||||||
| 36 | printf "Processor type: %s\n", $si->cpu_type; # short | ||||||||||||||||||||
| 37 | printf "Processor description: %s\n", $si->cpu; # long | ||||||||||||||||||||
| 38 | printf "OS and version: %s\n", $si->os; | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | or | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | use System::Info qw( sysinfo ); | ||||||||||||||||||||
| 43 | printf "[%s]\n", sysinfo (); | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | or | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | $ perl -MSystem::Info=si_uname -le print+si_uname | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =head1 DESCRIPTION | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | System::Info tries to present system-related information, like number of CPU's, | ||||||||||||||||||||
| 52 | architecture, OS and release related information in a system-independent way. | ||||||||||||||||||||
| 53 | This releases the user of this module of the need to know if the information | ||||||||||||||||||||
| 54 | comes from Windows, Linux, HP-UX, AIX, Solaris, Irix, or VMS, and if the | ||||||||||||||||||||
| 55 | architecture is i386, x64, pa-risc2, or arm. | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =head1 METHODS | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =head2 System::Info->new | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | Factory method, with fallback to the information in C<< POSIX::uname () >>. | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 127 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=27.3
Pod
documented
| |||||||||||||||||||||
| 66 | 127 | my $factory = shift; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 127 | ▶ | $^O =~ m/aix/i and return System::Info::AIX->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 127 | ▶ | $^O =~ m/bsd|dragonfly/i and return System::Info::BSD->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 127 | ▶ | $^O =~ m/cygwin/i and return System::Info::Cygwin->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 127 | ▶ | $^O =~ m/darwin/i and return System::Info::Darwin->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 127 | ▶ | $^O =~ m/haiku/ and return System::Info::Haiku->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 127 | ▶ | $^O =~ m/hp-?ux/i and return System::Info::HPUX->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 127 | ▶ | $^O =~ m/irix/i and return System::Info::Irix->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 127 | ▶ | $^O =~ m/linux|android/i and return System::Info::Linux->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 1 | ▶ | $^O =~ m/solaris|sunos|osf/i and return System::Info::Solaris->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 1 | ▶ | $^O =~ m/VMS/ and return System::Info::VMS->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 1 | ▶ | $^O =~ m/mswin32|windows/i and return System::Info::Windows->new; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 1 | return System::Info::Generic->new; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head2 sysinfo | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | C<sysinfo> returns a string with C<host>, C<os> and C<cpu_type>. | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 1 | ▶ | sub sysinfo { | ||||||||||||||||||
|
Subroutine
sysinfo: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 90 | 1 | my $si = System::Info->new; | |||||||||||||||||||
| 91 | 1 | ▶ | my @fields = $_[0] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | ? qw( host os cpu ncpu cpu_type ) | ||||||||||||||||||||
| 93 | : qw( host os cpu_type ); | ||||||||||||||||||||
| 94 | 1 | return join " ", @{ $si }{ map "_$_" => @fields }; | |||||||||||||||||||
| 95 | } # sysinfo | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head2 sysinfo_hash | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | C<sysinfo_hash> returns a hash reference with basic system information, like: | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | { cpu => 'Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz (GenuineIntel 2700MHz)', | ||||||||||||||||||||
| 102 | cpu_count => '1 [8 cores]', | ||||||||||||||||||||
| 103 | cpu_cores => 8, | ||||||||||||||||||||
| 104 | cpu_type => 'x86_64', | ||||||||||||||||||||
| 105 | distro => 'openSUSE Tumbleweed 20171030', | ||||||||||||||||||||
| 106 | hostname => 'foobar', | ||||||||||||||||||||
| 107 | os => 'linux - 4.13.10-1-default [openSUSE Tumbleweed 20171030]', | ||||||||||||||||||||
| 108 | osname => 'Linux', | ||||||||||||||||||||
| 109 | osvers => '4.13.10-1-default' | ||||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | The C<cpu_cores> count refers to logical cores. On MacOS there is also a | ||||||||||||||||||||
| 113 | C<physical_cores> count, which will be the same as C<cpu_cores> for Apple Silicon, | ||||||||||||||||||||
| 114 | but not for an Intel Mac with SMT enabled: | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | { cpu => 'Quad-Core Intel Core i7 (2 GHz)', | ||||||||||||||||||||
| 117 | cpu_count => '1 [4 cores]', | ||||||||||||||||||||
| 118 | cpu_cores => '8', | ||||||||||||||||||||
| 119 | physical_cores => '4', | ||||||||||||||||||||
| 120 | cpu_type => 'x86_64', | ||||||||||||||||||||
| 121 | distro => 'Darwin 11.7.10', | ||||||||||||||||||||
| 122 | hostname => '192.168.1.6', | ||||||||||||||||||||
| 123 | os => 'darwin - 20.6.0 (Mac OS X - macOS 11.7.10 (20G1427))', | ||||||||||||||||||||
| 124 | osname => 'Darwin', | ||||||||||||||||||||
| 125 | osvers => '11.7.10' | ||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 1 | ▶ | sub sysinfo_hash { | ||||||||||||||||||
|
Subroutine
sysinfo_hash: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 131 | 1 | my $si = System::Info->new; | |||||||||||||||||||
| 132 | 1 | ▶ | my %phys = $si->{_phys_core} ? (physical_cores => $si->{_phys_core}) : (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | return { | ||||||||||||||||||||
| 134 | %phys, | ||||||||||||||||||||
| 135 | hostname => $si->{_host}, | ||||||||||||||||||||
| 136 | cpu => $si->{_cpu}, | ||||||||||||||||||||
| 137 | cpu_type => $si->{_cpu_type}, | ||||||||||||||||||||
| 138 | cpu_count => $si->{_ncpu}, | ||||||||||||||||||||
| 139 | cpu_cores => $si->{_ncore}, | ||||||||||||||||||||
| 140 | os => $si->{_os}, | ||||||||||||||||||||
| 141 | osname => $si->{__osname}, | ||||||||||||||||||||
| 142 | osvers => $si->{__osvers}, | ||||||||||||||||||||
| 143 | distro => $si->{__distro} | ||||||||||||||||||||
| 144 | || join " " => $si->{__osname}, $si->{__osvers}, | ||||||||||||||||||||
| 145 | 1 | ▶ | }; | ||||||||||||||||||
|
Condition33%1/3
$si->{'__distro'} || join(' ', $si->{'__osname'}, $si->{'__osvers'})
MC/DC0%0/2
$si->{'__distro'} || join(' ', $si->{'__osname'}, $si->{'__osvers'})
$si->{'__distro'}
join(' ', $si->{'__osname'}, $si->{'__osvers'})
Truth table33%1/3
A || B
A= $si->{'__distro'}B= join(' ', $si->{'__osname'}, $si->{'__osvers'})
| |||||||||||||||||||||
| 146 | } # sysinfo | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =head2 si_uname (@args) | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | This class gathers most of the C<uname(1)> info, make a comparable | ||||||||||||||||||||
| 151 | version. Takes almost the same arguments: | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | a for all (can be omitted) | ||||||||||||||||||||
| 154 | n for nodename | ||||||||||||||||||||
| 155 | s for os name and version | ||||||||||||||||||||
| 156 | m for cpu name | ||||||||||||||||||||
| 157 | c for cpu count | ||||||||||||||||||||
| 158 | p for cpu_type | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 1 | ▶ | sub si_uname { | ||||||||||||||||||
|
Subroutine
si_uname: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 163 | 1 | my $si = System::Info->new; | |||||||||||||||||||
| 164 | 1 | return $si->si_uname (@_); | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 2 | 1; | |||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||