GCC Code Coverage Report


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

Line Branch Exec Source
1 /**
2 * @file
3 * @license BSD 3-clause
4 * @copyright Copyright (c) 2020, New York University and Max Planck
5 * Gesellschaft
6 */
7 /**
8 * @example demo_checkpoint_timer.cpp
9 * @brief Demo on how to use the CheckpointTimer.
10 *
11 * Note that when the statistics are printed like this, the printing is included
12 * in the time measurement of the total loop duration.
13 */
14
15 #include <real_time_tools/checkpoint_timer.hpp>
16 #include <real_time_tools/timer.hpp>
17
18 //! @brief Dummy function
19 void init()
20 {
21 real_time_tools::Timer::sleep_ms(3);
22 }
23 //! @brief Dummy function
24 void do_some_stuff()
25 {
26 real_time_tools::Timer::sleep_ms(20);
27 }
28 //! @brief Dummy function
29 void write_log()
30 {
31 real_time_tools::Timer::sleep_ms(6);
32 }
33
34 //! @brief Simple example on how to use the CheckpointTimer in a loop.
35 int main()
36 {
37 //! [Usage of CheckpointTimer]
38
39 // set second template argument to false to disable timer
40 real_time_tools::CheckpointTimer<3, true> timer;
41
42 for (int i = 0; i < 1000; i++)
43 {
44 timer.start();
45
46 init();
47 timer.checkpoint("initialize");
48
49 do_some_stuff();
50 timer.checkpoint("do some stuff");
51
52 write_log();
53 timer.checkpoint("logging");
54
55 // print the timing results every 100 iterations
56 if (i % 100 == 0 && i > 0)
57 {
58 timer.print_statistics();
59 }
60 }
61
62 //! [Usage of CheckpointTimer]
63 return 0;
64 }
65