line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package System::Info::Darwin; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
592
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
97
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
16
|
use base "System::Info::BSD"; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2413
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.055"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
System::Info::Darwin - Object for specific Darwin info. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head2 $si->prepare_sysinfo |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Use os-specific tools to find out more about the system. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub prepare_sysinfo { |
23
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
24
|
3
|
|
|
|
|
25
|
$self->System::Info::Base::prepare_sysinfo (); |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
7
|
$self->{__os} .= " (Mac OS X)"; |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
8
|
my $scl = __get_sysctl (); |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
|
|
|
30
|
my $system_profiler = __get_system_profiler () or |
31
|
|
|
|
|
|
|
return $self->SUPER::prepare_sysinfo (); |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
16
|
$self->{__system_profiler} = $system_profiler; |
34
|
3
|
50
|
|
|
|
29
|
if (my $kv = $system_profiler->{"system version"}) { |
35
|
0
|
|
|
|
|
0
|
$self->{__os} =~ s{\)$}{ - $kv)}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $model = $system_profiler->{"machine name"} || |
39
|
3
|
|
33
|
|
|
15
|
$system_profiler->{"machine model"}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $ncpu = # $scl->{"hw.ncpu"} || |
42
|
3
|
|
|
|
|
23
|
$system_profiler->{"number of cpus"}; |
43
|
3
|
100
|
|
|
|
30
|
$system_profiler->{"total number of cores"} and |
44
|
|
|
|
|
|
|
$ncpu .= " [$system_profiler->{'total number of cores'} cores]"; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{__cpu_type} = $system_profiler->{"cpu type"} |
47
|
3
|
50
|
|
|
|
14
|
if $system_profiler->{"cpu type"}; |
48
|
|
|
|
|
|
|
$self->{__cpu} = # $scl->{"machdep.cpu.brand_string"} || |
49
|
3
|
|
|
|
|
12
|
"$model ($system_profiler->{'cpu speed'})"; |
50
|
3
|
|
|
|
|
22
|
$self->{__cpu_count} = $ncpu; |
51
|
|
|
|
|
|
|
$scl->{"machdep.cpu.core_count"} and |
52
|
3
|
50
|
|
|
|
15
|
$self->{_ncore} = $scl->{"machdep.cpu.core_count"}; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
50
|
|
|
5
|
my $osv = do { |
55
|
|
|
|
|
|
|
local $^W = 0; |
56
|
|
|
|
|
|
|
`sw_vers -productVersion 2>/dev/null`; |
57
|
|
|
|
|
|
|
} || ""; |
58
|
3
|
|
|
|
|
13984
|
chomp ($self->{__osvers} = $osv); |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
43
|
$self->{__memsize} = $scl->{"hw.memsize"}; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
1263
|
return $self; |
63
|
|
|
|
|
|
|
} # prepare_sysinfo |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# System::Info::BSD.pm only uses hw |
66
|
|
|
|
|
|
|
sub __get_sysctl { |
67
|
3
|
50
|
|
3
|
|
136
|
my $sysctl_cmd = -x "/sbin/sysctl" ? "/sbin/sysctl" : "sysctl"; |
68
|
3
|
|
|
|
|
10
|
chomp (my @sysctl = do { |
69
|
3
|
|
|
|
|
14
|
local $^W = 0; |
70
|
3
|
|
|
|
|
24
|
`$sysctl_cmd -a 2>/dev/null`; |
71
|
|
|
|
|
|
|
}); |
72
|
3
|
|
|
|
|
160397
|
my %sysctl = map { split m/\s*[:=]\s*/, $_, 2 } grep m/[:=]/ => @sysctl; |
|
3048
|
|
|
|
|
11925
|
|
73
|
3
|
|
|
|
|
503
|
return \%sysctl; |
74
|
|
|
|
|
|
|
} # __get_sysctl |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub __get_system_profiler { |
77
|
3
|
50
|
|
3
|
|
8
|
my $system_profiler_output = do { |
78
|
3
|
|
|
|
|
46
|
local $^W = 0; |
79
|
3
|
|
|
|
|
31
|
`/usr/sbin/system_profiler -detailLevel mini SPHardwareDataType SPSoftwareDataType 2>&1`; |
80
|
|
|
|
|
|
|
} or return; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# From RT#97441 |
83
|
|
|
|
|
|
|
# In Yosemite the system_profiler started emitting these warnings: |
84
|
|
|
|
|
|
|
# 2015-07-24 06:54:06.842 system_profiler[59780:1318389] platformPluginDictionary: Can\'t get X86PlatformPlugin, return value 0 |
85
|
|
|
|
|
|
|
# They seem to be harmless, but annoying. |
86
|
|
|
|
|
|
|
# Clean them out, but then warn about others from system_profiler. |
87
|
3
|
|
|
|
|
131
|
$system_profiler_output =~ s/^\d{4}-\d\d-\d\d .+ system_profiler\[.+?\] platformPluginDictionary: Can't get X86PlatformPlugin, return value 0$//mg; |
88
|
3
|
|
|
|
|
55
|
warn "Unexpected warning from system_profiler:\n$1\n" |
89
|
|
|
|
|
|
|
while $system_profiler_output =~ /^(.+system_profiler.+)/mg; |
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
12
|
my %system_profiler; |
92
|
3
|
|
|
|
|
365
|
$system_profiler{lc $1} = $2 |
93
|
|
|
|
|
|
|
while $system_profiler_output =~ m/^\s*([\w ]+):\s+(.+)$/gm; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# convert newer output from Intel core duo |
96
|
3
|
|
|
|
|
35
|
my %keymap = ( |
97
|
|
|
|
|
|
|
"processor name" => "cpu type", |
98
|
|
|
|
|
|
|
"processor speed" => "cpu speed", |
99
|
|
|
|
|
|
|
"model name" => "machine name", |
100
|
|
|
|
|
|
|
"model identifier" => "machine model", |
101
|
|
|
|
|
|
|
"number of processors" => "number of cpus", |
102
|
|
|
|
|
|
|
"number of processors" => "number of cpus", |
103
|
|
|
|
|
|
|
"total number of cores" => "total number of cores", |
104
|
|
|
|
|
|
|
); |
105
|
3
|
|
|
|
|
35
|
for my $newkey (keys %keymap) { |
106
|
18
|
|
|
|
|
45
|
my $oldkey = $keymap{$newkey}; |
107
|
|
|
|
|
|
|
exists $system_profiler{$newkey} and |
108
|
18
|
100
|
|
|
|
144
|
$system_profiler{$oldkey} = delete $system_profiler{$newkey}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
3
|
|
33
|
|
|
24
|
chomp ($system_profiler{"cpu type"} ||= `uname -m`); |
112
|
3
|
|
50
|
|
|
16
|
$system_profiler{"cpu type"} ||= "Unknown"; |
113
|
3
|
|
|
|
|
24
|
$system_profiler{"cpu type"} =~ s/PowerPC\s*(\w+).*/macppc$1/; |
114
|
3
|
|
50
|
|
|
26
|
$system_profiler{"cpu speed"} ||= 0; # Mac M1 does not show CPU speed |
115
|
3
|
|
|
|
|
28
|
$system_profiler{"cpu speed"} =~ |
116
|
0
|
|
|
|
|
0
|
s/(0(?:\.\d+)?)\s*GHz/sprintf "%d MHz", $1 * 1000/e; |
117
|
|
|
|
|
|
|
|
118
|
3
|
|
|
|
|
41
|
return \%system_profiler; |
119
|
|
|
|
|
|
|
} # __get_system_profiler |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |