| 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__ |