Skip to main content

timings.h File

C++ header file with declarations for the µTest++ timing utilities. More...

Included Headers

#include <cstdint> #include <optional> #include <ctime> #include "inlines/timings-inlines.h"

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacedetail

Internal implementation details for the µTest++ framework. More...

Classes Index

classtimestamp

A single point-in-time measurement, wrapping a timespec value. More...

classtimestamps

A begin/end timestamp pair used to measure elapsed time. More...

Description

C++ header file with declarations for the µTest++ timing utilities.

This header provides two lightweight classes used to measure the elapsed time of test suites and test sessions within the µTest++ framework:

  • timestamp wraps a single timespec value and records one point in time. It is default-constructible and trivially copyable.
  • timestamps pairs a begin and an end timestamp (both stored as std::optional<timestamp>) and exposes methods for recording the start and finish of an operation, querying whether both timestamps are available, and computing the elapsed time in milliseconds and microseconds.

Timing support relies on clock_gettime(CLOCK_MONOTONIC_RAW, ...) when available; if the clock is not present (e.g. on bare-metal targets without an RTC) the timestamps are simply omitted and no timing information is reported.

All definitions reside within the micro_os_plus::micro_test_plus namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

This file is intended solely for internal use within the framework and should not be included directly by user code.

File Listing

The file content with the documentation metadata removed is:

1
2// ----------------------------------------------------------------------------
3/*
4 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
5 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose is hereby granted, under the terms of the MIT license.
9 *
10 * If a copy of the license was not distributed with this file, it can be
11 * obtained from https://opensource.org/licenses/mit.
12 */
13
14// ----------------------------------------------------------------------------
15
44
45#ifndef MICRO_TEST_PLUS_TIMINGS_H_
46#define MICRO_TEST_PLUS_TIMINGS_H_
47
48// ----------------------------------------------------------------------------
49
50#ifdef __cplusplus
51
52// ----------------------------------------------------------------------------
53
54#include <cstdint>
55#include <optional>
56#include <ctime>
57
58// ----------------------------------------------------------------------------
59
60#if defined(__GNUC__)
61#pragma GCC diagnostic push
62#if defined(__clang__)
63#pragma clang diagnostic ignored "-Wc++98-compat"
64#pragma clang diagnostic ignored "-Wpre-c++17-compat"
65#endif
66#endif
67
68// ============================================================================
69
71{
72 // --------------------------------------------------------------------------
73
74 namespace detail
75 {
76 // ========================================================================
77
94 {
95 public:
99 timestamp () noexcept;
100
106 timestamp (const timespec& ts) noexcept;
107
108 // `timespec` is trivially copyable, so copy and move are safe to
109 // default. Defaulting these operations allows `timestamp` to be used in
110 // contexts that require copyability or movability (e.g. containers,
111 // algorithms).
115 timestamp (const timestamp&) = default;
116
120 timestamp (timestamp&&) = default;
121
127 = default;
128
134 = default;
135
139 ~timestamp () = default;
140
149 bool
150 has_clock (void) const noexcept;
151
159 [[nodiscard]] timespec&
160 value () noexcept;
161
169 [[nodiscard]] const timespec&
170 value () const noexcept;
171
172 protected:
176 timespec value_{};
177 };
178
179 // ========================================================================
180
205 {
206 public:
210 timestamps () = default;
211
215 timestamps (const timestamps&) = delete;
216
220 timestamps (timestamps&&) = delete;
221
227 = delete;
228
234 = delete;
235
239 ~timestamps () = default;
240
249 void
250 timestamp_begin (void) noexcept;
251
259 void
260 timestamp_begin (const timespec& ts) noexcept;
261
270 void
271 timestamp_end (void) noexcept;
272
280 void
281 timestamp_end (const timespec& ts) noexcept;
282
291 bool
292 has_begin () const noexcept;
293
302 bool
303 has_end () const noexcept;
304
315 bool
316 has_timestamps (void) const noexcept;
317
325 void
326 compute_elapsed_time (uint32_t& milliseconds,
327 uint32_t& microseconds) const;
328
329 protected:
333 std::optional<timestamp> begin_time_;
334
338 std::optional<timestamp> end_time_;
339 };
340
341 // ------------------------------------------------------------------------
342 } // namespace detail
343 // ==========================================================================
344} // namespace micro_os_plus::micro_test_plus
345
346#if defined(__GNUC__)
347#pragma GCC diagnostic pop
348#endif
349
350// ----------------------------------------------------------------------------
351
352#endif // __cplusplus
353
354// ============================================================================
355// Templates & constexpr implementations.
356
358
359// ----------------------------------------------------------------------------
360
361#endif // MICRO_TEST_PLUS_TIMINGS_H_
362
363// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.