]> arthur.barton.de Git - netdata.git/commit
FreeBSD has CLOCK_UPTIME feature for clock_gettime.
authorUser Sternix <sternix@phenomx3.amiral.com.tr>
Thu, 2 Mar 2017 18:31:21 +0000 (21:31 +0300)
committerUser Sternix <sternix@phenomx3.amiral.com.tr>
Thu, 2 Mar 2017 18:31:21 +0000 (21:31 +0300)
commit88037bf63132dd5d5b15b80647d65a75fcb82055
tree71b50d023f47308e6666e9d09c5fe57d13df35ba
parent360b3624052e7a2a94a32b003fc61284d6083162
FreeBSD has CLOCK_UPTIME feature for clock_gettime.

https://www.freebsd.org/cgi/man.cgi?query=clock_gettime&apropos=0&sektion=0&manpath=FreeBSD+10.0-RELEASE&arch=default&format=html

the functions below  make the same job,
but clock version is short, fast i think.

//------8<-----------------------------------------------------------

int64_t uptime_via_clock() {
        struct timespec ts;
        clock_gettime(CLOCK_UPTIME , &ts);
        return ts.tv_sec;
}

int64_t uptime_via_sysctl() {
        struct timespec cur_time , boot_time;
        size_t len = sizeof(struct timespec);

        sysctlbyname("kern.boottime" , &boot_time , &len , NULL , 0);
        clock_gettime(CLOCK_REALTIME , &cur_time);

        return (cur_time.tv_sec - boot_time.tv_sec);
}

int main() {
        printf("Uptime Via Clock: %ld\n",uptime_via_clock());
        printf("Uptime Via Sysctl: %ld\n",uptime_via_sysctl());
        return 0;
}

//------8<-----------------------------------------------------------
src/freebsd_sysctl.c