MICROUPTIME(9)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– MICROUPTIME(9) β€” the manual page for getting time since boot, bestie! πŸ’–

Okay so listen, this is from the MICROUPTIME(9) manual β€” Kernel Developer's Manual, no cap. We're talking about the iconic functions that tell you how much time has passed since the system booted up. Periodt. Let's get into it.


✨ NAME ✨

binuptime, getbinuptime, microuptime, getmicrouptime, nanouptime, getnanouptime, sbinuptime, getsbinuptime β€” all of these give you the time elapsed since boot. Slay.


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/time.h>

void
binuptime(struct bintime *bt);

void
getbinuptime(struct bintime *bt);

void
microuptime(struct timeval *tv);

void
getmicrouptime(struct timeval *tv);

void
nanouptime(struct timespec *ts);

void
getnanouptime(struct timespec *tsp);

sbintime_t
sbinuptime(void);

sbintime_t
getsbinuptime(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

So the way this works, bestie: binuptime() and getbinuptime() are the OGs that store the time elapsed since boot as a struct bintime at the address you pass in bt. Iconic. Then microuptime() and getmicrouptime() do the same exact thing but they record it as a struct timeval instead. And nanouptime() and getnanouptime()? They store it as a struct timespec. Cute. Finally, sbinuptime() and getsbinuptime() just return the time elapsed since boot directly as an sbintime_t. No pointer needed, we love a direct return. πŸ’…

Now here's the tea: binuptime(), microuptime(), nanouptime(), and sbinuptime()? They always query the timecounter to give you the current time as precisely as possible. Highkey accurate. Whereas getbinuptime(), getmicrouptime(), getnanouptime(), and getsbinuptime() are abstractions that return a less precise but faster-to-obtain time. It's giving "speed over perfection" and honestly? Sometimes that's the vibe.

The whole intent of the get* versions is to enforce the user's preference for timer accuracy versus execution time. So like, you get to choose β€” do you want it fast or do you want it exact? The system respects your choice, fr fr.


🌈 SEE ALSO 🌈

Go check these out if you're obsessed with time functions like I am. πŸ’œ


πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Kelly Yancey <kbyanc@posi.net>. We stan a legend who documents kernel time functions. 🫢


This iconic page is from the MICROUPTIME(9) manual, Debian version, dated February 21, 2015. Stay precise, bestie! πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from