libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_timer.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblTimer simple system timer/stopwatch API
3 * \ingroup utils
4 *
5 * This file contains GblTimer and its respective API.
6 * GblTimer is a nanosecond-resolution stopwatch-style
7 * API for measuring the amount of time elapsed between
8 * two points in time.
9 *
10 * \todo
11 * - make profiler out of a stack of these
12 *
13 * \author 2023 Falco Girgis
14 * \copyright MIT License
15 */
16#ifndef GIMBAL_TIMER_H
17#define GIMBAL_TIMER_H
18
20
21/*! \name Initialization
22 * \brief Macros used for initializing a timer
23 * @{
24 */
25#define GBL_TIMER_INIT { 0, 0, 0 } //!< Value to assign to a GblTimer during initialization
26#define GBL_TIMER(name) name = GBL_TIMER_INIT //!< Declares a GblTimer with the given name and initializes it
27//! @}
28
29#define GBL_SELF_TYPE GblTimer
30
32
33/*! Represents a stopwatch-like nanosecond timer
34 * \ingroup utils
35 *
36 * GblTimer is a nanosecond-resolution stopwatch-like
37 * timing API which is used for measuring elapsed time
38 * between a start and stop point.
39 */
40typedef struct GblTimer {
41 GblTimeSpec startTime; //!< Initial starting timestamp
42 GblTimeSpec stopTime; //!< Ending or stopping timestamp
43 GblTimeSpec elapsedTime; //!< Calculated elapsed time
44 GblBool active; //!< Whether the timer is active or not
45} GblTimer;
46
47/*! \name Capturing
48 * \relatesalso GblTimer
49 * \brief Methods used for capturing timing data
50 * @{
51 */
52//! Starts the timer, which will continue running until GblTimer_stop() is called
54//! Stops the timer, recording the amount of time elapsed within GblTimer::elapsedTime
56//! Continues the timer, recording elapsed time where it left off
58//! @}
59
60/*! \name Elapsed Time
61 * \relatesalso GblTimer
62 * \brief Methods for measuring elapsed time
63 * @{
64 */
65//! Returns GBL_TRUE if the timer contains a valid elapsed time measurement
67//! Returns the amount of time elapsed in seconds
69//! Returns the amount of time elapsed in milliseconds
71//! Returns the amount of time elapsed in microseconds
73//! Returns the amount of time elapsed in nanoseconds
75//! @}
76
78
79#undef GBL_SELF_TYPE
80
81#endif // GIMBAL_TIMER_H
#define GBL_NOEXCEPT
struct timespec GblTimeSpec
Represents the difference between two GblTime instances.
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_TIMER_INIT
Value to assign to a GblTimer during initialization.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
Represents a stopwatch-like nanosecond timer.
void GblTimer_stop(GblTimer *pSelf)
Stops the timer, recording the amount of time elapsed within GblTimer::elapsedTime.
double GblTimer_elapsedSecs(const GblTimer *pSelf)
Returns the amount of time elapsed in seconds.
void GblTimer_start(GblTimer *pSelf)
Starts the timer, which will continue running until GblTimer_stop() is called.
GblBool active
Whether the timer is active or not.
double GblTimer_elapsedMs(const GblTimer *pSelf)
Returns the amount of time elapsed in milliseconds.
void GblTimer_continue(GblTimer *pSelf)
Continues the timer, recording elapsed time where it left off.
GblTimeSpec stopTime
Ending or stopping timestamp.
GblTimeSpec startTime
Initial starting timestamp.
double GblTimer_elapsedUs(const GblTimer *pSelf)
Returns the amount of time elapsed in microseconds.
GblTimeSpec elapsedTime
Calculated elapsed time.
uint64_t GblTimer_elapsedNs(const GblTimer *pSelf)
Returns the amount of time elapsed in nanoseconds.
GblBool GblTimer_isValid(const GblTimer *pSelf)
Returns GBL_TRUE if the timer contains a valid elapsed time measurement.