line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPi::SysInfo; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
58084
|
use strict; |
|
9
|
|
|
|
|
54
|
|
|
9
|
|
|
|
|
223
|
|
4
|
9
|
|
|
9
|
|
39
|
use warnings; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
206
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
37
|
use Carp qw(croak); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
934
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require XSLoader; |
11
|
|
|
|
|
|
|
XSLoader::load('RPi::SysInfo', $VERSION); |
12
|
|
|
|
|
|
|
|
13
|
9
|
|
|
9
|
|
57
|
use Exporter qw(import); |
|
9
|
|
|
|
|
32
|
|
|
9
|
|
|
|
|
5689
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
16
|
|
|
|
|
|
|
core_temp |
17
|
|
|
|
|
|
|
cpu_percent |
18
|
|
|
|
|
|
|
mem_percent |
19
|
|
|
|
|
|
|
gpio_info |
20
|
|
|
|
|
|
|
raspi_config |
21
|
|
|
|
|
|
|
network_info |
22
|
|
|
|
|
|
|
file_system |
23
|
|
|
|
|
|
|
pi_details |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our %EXPORT_TAGS; |
27
|
|
|
|
|
|
|
$EXPORT_TAGS{all} = [@EXPORT_OK]; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
0
|
|
|
0
|
1
|
|
return bless {}, shift; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
sub core_temp { |
33
|
0
|
0
|
|
0
|
1
|
|
shift if ref $_[0] eq 'RPi::SysInfo'; |
34
|
0
|
|
|
|
|
|
my ($degree) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
0
|
|
|
|
$degree //= 'c'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub { |
39
|
0
|
|
|
0
|
|
|
my $warning = shift; |
40
|
0
|
0
|
|
|
|
|
if ($warning !~ /Can't exec "vcgencmd"/){ |
41
|
0
|
|
|
|
|
|
warn $warning; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $temp = `vcgencmd measure_temp`; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if (! defined $temp){ |
48
|
0
|
|
|
|
|
|
croak "issue executing the core temp command, can't continue...\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$temp =~ s/(temp=)//; |
52
|
0
|
|
|
|
|
|
$temp =~ s/'.*//; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
|
if ($degree eq 'f' || $degree eq 'F'){ |
55
|
0
|
|
|
|
|
|
$temp = ($temp * 1.8) + 32; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $temp; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub cpu_percent { |
61
|
0
|
|
|
0
|
1
|
|
return _format(cpuPercent()); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
sub gpio_info { |
64
|
0
|
0
|
|
0
|
1
|
|
shift if ref $_[0] eq 'RPi::SysInfo'; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my ($pins) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
$pins = ! defined $pins |
69
|
|
|
|
|
|
|
? '' |
70
|
|
|
|
|
|
|
: join ",", @$pins; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return `raspi-gpio get $pins`; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
sub mem_percent { |
75
|
0
|
|
|
0
|
1
|
|
return _format(memPercent()); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
sub network_info { |
78
|
0
|
|
|
0
|
1
|
|
return `ifconfig`; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
sub raspi_config { |
81
|
0
|
|
|
0
|
1
|
|
my $config = `vcgencmd get_config int`; |
82
|
0
|
|
|
|
|
|
$config .= `vcgencmd get_config str`; |
83
|
0
|
|
|
|
|
|
my $cmd = 'cat /boot/config.txt | egrep -v "^\s*(#|^$)"'; |
84
|
0
|
|
|
|
|
|
$config .= `$cmd`; |
85
|
0
|
|
|
|
|
|
return $config; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
sub file_system { |
88
|
0
|
|
|
0
|
1
|
|
my $fs_info = `df` . "\n"; |
89
|
0
|
|
|
|
|
|
$fs_info .= `cat /proc/swaps`; |
90
|
0
|
|
|
|
|
|
return $fs_info; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
sub pi_details { |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
|
my $details; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$details = "\n" |
97
|
|
|
|
|
|
|
. `cat /sys/firmware/devicetree/base/model` |
98
|
|
|
|
|
|
|
. "\n\n" |
99
|
|
|
|
|
|
|
. `cat /etc/os-release | head -4` |
100
|
|
|
|
|
|
|
. "\n" |
101
|
|
|
|
|
|
|
. `uname -a` |
102
|
|
|
|
|
|
|
. "\n" |
103
|
|
|
|
|
|
|
. `cat /proc/cpuinfo | tail -3` |
104
|
|
|
|
|
|
|
. "Throttled flag : " . `vcgencmd get_throttled` |
105
|
|
|
|
|
|
|
. "Camera : " . `vcgencmd get_camera`; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $details; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
sub _format { |
110
|
0
|
0
|
|
0
|
|
|
croak "_format() requires a float/double sent in\n" if ! defined $_[0]; |
111
|
0
|
|
|
|
|
|
return sprintf("%.2f", $_[0]); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
__END__ |