line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPi::SysInfo; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
69188
|
use strict; |
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
113
|
|
4
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
108
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
18
|
use Carp qw(croak); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
461
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require XSLoader; |
11
|
|
|
|
|
|
|
XSLoader::load('RPi::SysInfo', $VERSION); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
27
|
use Exporter qw(import); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1594
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
16
|
|
|
|
|
|
|
core_temp |
17
|
|
|
|
|
|
|
cpu_percent |
18
|
|
|
|
|
|
|
mem_percent |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our %EXPORT_TAGS; |
22
|
|
|
|
|
|
|
$EXPORT_TAGS{all} = [@EXPORT_OK]; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
1
|
|
return bless {}, shift; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
sub core_temp { |
28
|
0
|
|
|
0
|
1
|
|
my ($degree) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
0
|
|
|
|
$degree //= 'c'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub { |
33
|
0
|
|
|
0
|
|
|
my $warning = shift; |
34
|
0
|
0
|
|
|
|
|
if ($warning !~ /Can't exec "vcgencmd"/){ |
35
|
0
|
|
|
|
|
|
warn $warning; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $temp = `vcgencmd measure_temp`; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if (! defined $temp){ |
42
|
0
|
|
|
|
|
|
croak "issue executing the core temp command, can't continue...\n"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$temp =~ s/(temp=)//; |
46
|
0
|
|
|
|
|
|
$temp =~ s/'.*//; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
if ($degree eq 'f' || $degree eq 'F'){ |
49
|
0
|
|
|
|
|
|
$temp = ($temp * 1.8) + 32; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $temp; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
sub cpu_percent { |
55
|
0
|
|
|
0
|
1
|
|
return _format(cpuPercent()); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
sub mem_percent { |
58
|
0
|
|
|
0
|
1
|
|
return _format(memPercent()); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub _format { |
61
|
0
|
0
|
|
0
|
|
|
croak "_format() requires a float/double sent in\n" if ! defined $_[0]; |
62
|
0
|
|
|
|
|
|
return sprintf("%.2f", $_[0]); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |