QBUTIL.H(3)
π QBUTIL.H(3) π
okay bestie, gather round β this is a page from the libqb Programmer's Manual, and it's all about qbutil.h, the header full of little convenience functions that libqb sprinkles everywhere. π§
β¨ NAME β¨
qbutil.h β these are some convience functions used throughout libqb. π
(yes that's the original spelling, we do not touch the spelling, we respect the spelling π«Ά)
πΈ SYNOPSIS πΈ
#include <qb/qbutil.h>
π¦ DESCRIPTION π¦
π Locking
Locking stuff lives here. That's the whole vibe of this bit. π
β° Time functions
Time functions live here too. Clocks, nanosecond math, all of it. β±οΈ
π Basic Stopwatch
Okay so this is the cute one β you can time stuff with a stopwatch. Look at this:
uint64_t elapsed1;
uint64_t elapsed2;
qb_util_stopwatch_t *sw = qb_util_stopwatch_create();
qb_util_stopwatch_start(sw);
usleep(sometime);
qb_util_stopwatch_stop(sw);
elapsed1 = qb_util_stopwatch_us_elapsed_get(sw);
usleep(somemoretime);
qb_util_stopwatch_stop(sw);
elapsed2 = qb_util_stopwatch_us_elapsed_get(sw);
qb_util_stopwatch_free(sw);
create β start β stop β grab the elapsed microseconds β free. That's it, that's the whole loop, and honestly? It ate. π β¨
π Stopwatch with splits
Now the fancy version π β you set up a stopwatch with space for 3 splits:
uint64_t split;
qb_util_stopwatch_t *sw = qb_util_stopwatch_create();
qb_util_stopwatch_split_ctl(sw, 3, 0);
qb_util_stopwatch_start(sw);
usleep(sometime);
qb_util_stopwatch_split(sw);
usleep(somemoretime);
qb_util_stopwatch_split(sw);
usleep(somemoretime);
qb_util_stopwatch_split(sw);
idx = qb_util_stopwatch_split_last(sw);
do {
split = qb_util_stopwatch_time_split_get(sw, idx, idx);
qb_log(LOG_INFO, "split %d is %"PRIu64"", last, split);
idx--;
} while (split > 0);
split = qb_util_stopwatch_time_split_get(sw, 2, 1);
qb_log(LOG_INFO, "time between second and third split is %"PRIu64"", split);
qb_util_stopwatch_free(sw);
So like: qb_util_stopwatch_split_ctl(sw, 3, 0) preps room for three splits, then every qb_util_stopwatch_split(sw) marks one, and qb_util_stopwatch_split_last(sw) tells you which index is the last one. Then you walk backwards grabbing each split with qb_util_stopwatch_time_split_get(sw, idx, idx), and if you want the time between two splits you pass two indices like qb_util_stopwatch_time_split_get(sw, 2, 1). Iconic. π§π
π SEE ALSO π
Literally all of these, bestie, go read them:
qb_util_nano_current_get(3)qb_util_stopwatch_stop(3)qb_util_stopwatch_split(3)qb_util_stopwatch_split_ctl(3)qb_thread_unlock(3)qb_strerror_r(3)qb_util_stopwatch_time_split_get(3)qb_util_set_log_function(3)qb_util_timespec_from_epoch_get(3)qb_thread_lock_destroy(3)qb_thread_trylock(3)qb_util_nano_monotonic_hz(3)qb_util_nano_from_epoch_get(3)qb_util_stopwatch_create(3)qb_util_stopwatch_split_last(3)qb_thread_lock(3)qb_util_stopwatch_free(3)qb_thread_lock_create(3)qb_timespec_add_ms(3)qb_util_stopwatch_start(3)qb_util_stopwatch_us_elapsed_get(3)qb_util_stopwatch_sec_elapsed_get(3)
π COPYRIGHT π
Copyright (C) 2010-2020 Red Hat, Inc.
π cute sign-off time: this whole page is from LIBQB, dated 2025-09-16, and it's filed under QBUTIL.H(3). bye bestie, go time something! β±οΈπ
π¦ where this page comes from
- fedora 44: libqb-devel 2.0.9-2.fc44 Β· LGPL-2.1-or-later
- fedora 44: libqb-devel 2.0.9-2.fc44 Β· LGPL-2.1-or-later
- ubuntu resolute: libqb-dev 2.0.9-1ubuntu1 Β· LGPL-2.1-or-later
- ubuntu stonking: libqb-dev 2.0.9-1ubuntu1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms