#include <pthread.h>
#include <stdint.h>
#include <unistd.h>
#include <qb/qbdefs.h>
These are some convience functions used throughout libqb.
- Author
- Angus Salkeld asalk.nosp@m.eld@.nosp@m.redha.nosp@m.t.co.nosp@m.m
- Locking
-
- Time functions
-
- Basic Stopwatch
uint64_t elapsed1;
uint64_t elapsed2;
usleep(sometime);
usleep(somemoretime);
- Stopwatch with splits
- Setup a stopwatch with space for 3 splits.
uint64_t split;
usleep(sometime);
usleep(somemoretime);
usleep(somemoretime);
do {
qb_log(LOG_INFO,
"split %d is %"PRIu64
"", last, split);
idx--;
} while (split > 0);
qb_log(LOG_INFO,
"time between second and third split is %"PRIu64
"", split);
◆ QB_UTIL_SW_OVERWRITE
#define QB_UTIL_SW_OVERWRITE 0x01 |
◆ qb_thread_lock_t
◆ qb_util_log_fn_t
typedef void(* qb_util_log_fn_t) (const char *file_name, int32_t file_line, int32_t severity, const char *msg) |
◆ qb_util_stopwatch_t
◆ qb_thread_lock_type_t
QB_THREAD_LOCK_SHORT is a short term lock (spinlock if available on your system) QB_THREAD_LOCK_LONG is a mutex
Enumerator |
---|
QB_THREAD_LOCK_SHORT | |
QB_THREAD_LOCK_LONG | |
◆ qb_strerror_r()
char* qb_strerror_r |
( |
int |
errnum, |
|
|
char * |
buf, |
|
|
size_t |
buflen |
|
) |
| |
◆ qb_thread_lock()
Calls either pthread_mutex_lock() or pthread_spin_lock().
◆ qb_thread_lock_create()
Create a new lock of the given type.
- Parameters
-
type | QB_THREAD_LOCK_SHORT == spinlock (where available, else mutex) QB_THREAD_LOCK_LONG == mutex |
- Returns
- pointer to qb_thread_lock_type_t or NULL on error.
◆ qb_thread_lock_destroy()
Calls either pthread_mutex_destro() or pthread_spin_destroy().
◆ qb_thread_trylock()
Calls either pthread_mutex_trylock() or pthread_spin_trylock().
◆ qb_thread_unlock()
Calls either pthread_mutex_unlock() or pthread_spin_unlock.
◆ qb_timespec_add_ms()
void qb_timespec_add_ms |
( |
struct timespec * |
ts, |
|
|
int32_t |
ms |
|
) |
| |
Add milliseconds onto the timespec.
- Parameters
-
ts | the ts to add to |
ms | the amount of milliseconds to increment ts |
◆ qb_util_nano_current_get()
uint64_t qb_util_nano_current_get |
( |
void |
| ) |
|
Get the current number of nano secounds produced by the systems incrementing clock (CLOCK_MONOTOMIC if available).
◆ qb_util_nano_from_epoch_get()
uint64_t qb_util_nano_from_epoch_get |
( |
void |
| ) |
|
Get the time in nano seconds since epoch.
◆ qb_util_nano_monotonic_hz()
uint64_t qb_util_nano_monotonic_hz |
( |
void |
| ) |
|
◆ qb_util_set_log_function()
Use this function to output libqb internal log message as you wish.
◆ qb_util_stopwatch_create()
Create a Stopwatch (to time operations)
- Examples
- ipcclient.c.
◆ qb_util_stopwatch_free()
◆ qb_util_stopwatch_sec_elapsed_get()
Get the elapsed time in seconds.
(it must have been started and stopped).
- Examples
- ipcclient.c.
◆ qb_util_stopwatch_split()
Create a new time split (or lap time)
- Parameters
-
- Return values
-
the | relative split time in micro seconds |
0 | if no more splits available |
◆ qb_util_stopwatch_split_ctl()
int32_t qb_util_stopwatch_split_ctl |
( |
qb_util_stopwatch_t * |
sw, |
|
|
uint32_t |
max_splits, |
|
|
uint32_t |
options |
|
) |
| |
- Parameters
-
sw | the stopwatch |
max_splits | maximum number of time splits |
options | (0 or QB_UTIL_SW_OVERWRITE ) |
- Return values
-
0 | on success |
-errno | on failure |
◆ qb_util_stopwatch_split_last()
◆ qb_util_stopwatch_start()
Start the stopwatch.
This also acts as a reset. Essentially it sets the starting time and clears the splits.
- Examples
- ipcclient.c.
◆ qb_util_stopwatch_stop()
Stop the stopwatch.
This just allows you to get the elapsed time. So you can call this multiple times. Do not call qb_util_stopwatch_start() unless you want to reset the stopwatch.
- Examples
- ipcclient.c.
◆ qb_util_stopwatch_time_split_get()
uint64_t qb_util_stopwatch_time_split_get |
( |
qb_util_stopwatch_t * |
sw, |
|
|
uint32_t |
receint, |
|
|
uint32_t |
older |
|
) |
| |
Read the time split (in us) from "receint" to "older".
If older == receint then the cumulated split will be returned (from the stopwatch start).
- Parameters
-
sw | the stopwatch |
receint | split |
older | split |
- Return values
-
the | split time in micro seconds |
0 | if not a valid split |
◆ qb_util_stopwatch_us_elapsed_get()
Get the elapsed time in micro seconds.
(it must have been started and stopped).
◆ qb_util_timespec_from_epoch_get()
void qb_util_timespec_from_epoch_get |
( |
struct timespec * |
ts | ) |
|
Get the time in timespec since epoch.
- Parameters
-
- Returns
- status (0 == ok, -errno on error)
◆ qb_ver
◆ qb_ver_str
const char* const qb_ver_str |
Complete library versioning info as a string.
uint64_t qb_util_stopwatch_time_split_get(qb_util_stopwatch_t *sw, uint32_t receint, uint32_t older)
Read the time split (in us) from "receint" to "older".
#define qb_log(priority, fmt, args...)
This is the main function to generate a log message.
Definition: qblog.h:501