blib/lib/Unix/Uptime/FreeBSD.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.0
CC
2
Cov
0%
uptime_hires
6.0
uptime
2.0
load_hires
2.0
CRAP 3.0
1 package Unix::Uptime::FreeBSD;
2  
3 use warnings;
4 use strict;
5  
6 our $VERSION='0.36';
7 $VERSION = eval $VERSION;
8  
9 sub uptime {
10 my $class = shift;
11
12 local $ENV{PATH} .= ':/usr/local/sbin:/usr/sbin:/sbin';
13 my $boottime = `sysctl kern.boottime`;
14 my ($boot_seconds,$boot_useconds) = $boottime =~ /\s+sec\s+=\s+(\d+),\s+[un]sec\s+=\s+(\d+)/;
15 return time() - $boot_seconds;
16 }
17  
18 sub uptime_hires {
19 my $class = shift;
20  
21 unless ($class->want_hires()) {
22 die "uptime_hires: you need to import Unix::Uptime with ':hires'";
23 }
24  
25 local $ENV{PATH} .= ':/usr/local/sbin:/usr/sbin:/sbin';
26 my $boottime = `sysctl kern.boottime`;
27 my ($boot_seconds,$boot_useconds) = $boottime =~ /\s+sec\s+=\s+(\d+),\s+[un]sec\s+=\s+(\d+)/;
28 my $time = Time::HiRes::gettimeofday();
29 # this isn't strictly correct on dfly. but i don't think it actually
30 # uses a real nsec value, so that's ok.
31 my $boot_time = $boot_seconds + ($boot_useconds * (10.0**-6));
32 return $time - $boot_time;
33 }
34  
35 sub load_hires {
36 my $class = shift;
37  
38 require Time::HiRes;
39 }
40  
41 use base 'Unix::Uptime::BSD::Load';
42  
43 1;
44  
45 __END__