GCC Code Coverage Report


Directory: ./
File: demos/demo_timing.cpp
Date: 2022-06-29 13:58:11
Exec Total Coverage
Lines: 0 13 0.0%
Branches: 0 22 0.0%

Line Branch Exec Source
1 /**
2 * @file demo_timing.cpp
3 * @author Maximilien Naveau (maximilien.naveau@gmail.com)
4 * license License BSD-3-Clause
5 * @copyright Copyright (c) 2019, New York University and Max Planck
6 * Gesellschaft.
7 * @date 2019-05-22
8 *
9 * @brief Demo of the Timer class usage.
10 */
11
12 #include "real_time_tools/realtime_check.hpp"
13 #include "real_time_tools/spinner.hpp"
14 #include "real_time_tools/thread.hpp"
15 #include "real_time_tools/timer.hpp"
16
17 /** @brief Real time thread presenting the use of the Timer class. */
18 THREAD_FUNCTION_RETURN_TYPE thread_function(void*)
19 {
20 double frequency = 1000;
21
22 real_time_tools::Spinner spinner;
23 spinner.set_frequency(frequency);
24
25 real_time_tools::Timer timer;
26
27 while (true)
28 {
29 for (int i = 0; i < frequency; i++)
30 {
31 spinner.spin();
32 timer.tac_tic();
33 }
34
35 timer.print_statistics();
36 }
37
38 return THREAD_FUNCTION_RETURN_VALUE;
39 }
40
41 /** @brief Launch a real time thread presenting the use of the Timer class. */
42 int main(int, char* [])
43 {
44 real_time_tools::RealTimeThread thread;
45 thread.create_realtime_thread(thread_function);
46 thread.join();
47 }
48
49 /**
50 * \example demo_timing.cpp
51 *
52 * This demos has for purpose to present the class real_time_tools::Timer.
53 * This class allows you to use the real time clocks. And measure durations
54 * and extract statistics on them.
55 *
56 * Inn this example we create a simple loop cadence by the
57 * real_time_tools::Spinner. And we measure the period of the loop.
58 *
59 * In order to do so one need to create a real_time_tools::Timer and call the
60 * real_time_tools::Timer::tac_tic() method which compute the duration between
61 * each call of this method.
62 *
63 * The demo displays the statistics of the measured time every milliseconds.
64 */
65