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:


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