SD_JOUR...IME_USEC(3)

πŸ’… SD_JOURNAL_GET_CUTOFF_REALTIME_USEC(3) & SD_JOURNAL_GET_CUTOFF_MONOTONIC_USEC(3) β€” the "when did this journal thing even start/end" girlies ✨

Okay bestie, so today we're talking about sd_journal_get_cutoff_realtime_usec and sd_journal_get_cutoff_monotonic_usec β€” two absolute icons from the sd_journal_get_cutoff_realtime_usec corner of the systemd universe. They read cut-off timestamps from the current journal entry, and honestly? Life-changing if you're into that. πŸŽ€


✨ SYNOPSIS ✨

Like, the vibes start here:

#include <systemd/sd-journal.h>

int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from,
                                        uint64_t *to);

int sd_journal_get_cutoff_monotonic_usec(sd_journal *j,
                                         sd_id128_t boot_id,
                                         uint64_t *from, uint64_t *to);

πŸ¦‹ DESCRIPTION πŸ¦‹

So sd_journal_get_cutoff_realtime_usec() is giving main character energy β€” it retrieves the realtime (wallclock) timestamps of the first and last entries accessible in the journal. Obsessed. πŸ’–

It takes three arguments, periodt:

  • the journal context object j
  • two pointers from and to pointing at 64-bit unsigned integers to store the timestamps in

The timestamps are in microseconds since the epoch, i.e. CLOCK_REALTIME. Either one of the two timestamp arguments may be passed as NULL in case the timestamp is not needed β€” but not both, bestie. πŸ™ˆ


Now sd_journal_get_cutoff_monotonic_usec() is the lowkey moody sibling. It retrieves the monotonic timestamps of the first and last entries accessible in the journal. Also three arguments:

  • the journal context object j
  • a 128-bit identifier for the boot boot_id
  • two pointers to 64-bit unsigned integers to store the timestamps, from and to

The timestamps are in microseconds since boot-up of the specific boot, i.e. CLOCK_MONOTONIC. And since the monotonic clock begins new with every reboot, it only defines a well-defined point in time when used together with an identifier identifying the boot β€” see sd_id128_get_boot(3) for more info, iykyk. πŸ‘‘

The function will return the timestamps for the boot identified by the passed boot ID. Either one of the two timestamp arguments may be passed as NULL in case the timestamp is not needed, but not both (yes, we're saying it again, it's important πŸ’…).


🌸 RETURN VALUE 🌸

Both sd_journal_get_cutoff_realtime_usec() and sd_journal_get_cutoff_monotonic_usec() return:

  • 1 on success πŸŽ‰
  • 0 if no suitable entries are in the journal
  • a negative errno-style error code (crying 😭)

Locations pointed to by parameters from and to will be set only if the return value is positive β€” and obviously, the parameters are non-null. Not me being like "conditional assignment, slay". ✨


🌈 NOTES 🌈

All functions listed here are thread-agnostic and only a single thread may operate on a given object at any given time. Different threads may access the same object at different times. Multiple independent objects may be used from different threads in parallel. So like, don't share the same sd_journal object across threads simultaneously, but you can have separate ones, bestie. 🧚

Functions described here are available as a shared library, which can be compiled against and linked to with the libsystemd pkg-config(1) file. Yes, pkg-config is still a thing. πŸ™ˆ


πŸ“ HISTORY πŸ“

sd_journal_get_cutoff_realtime_usec() and sd_journal_get_cutoff_monotonic_usec() were added in version 187. Ancient. Iconic. πŸ’€


πŸ’œ SEE ALSO πŸ’œ


okay that's the whole thing, bestie πŸ’– this page was brought to you by systemd 261.3 and the date line β€” you know the one. go forth and read your journal timestamps with confidence. 🫢✨

πŸ“¦ where this page comes from