~aleteoryx/muditaos

ref: 09761da170faa207c5d899d2132a3cc67dad5a31 muditaos/module-utils/time/ScopedTime.hpp -rw-r--r-- 1.1 KiB
09761da1 — DariuszSabala [BH-369] Fixed UTF8 unit test CI run 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <FreeRTOS.h>
#include <log.hpp>
#include <string>
#include <ticks.hpp>

namespace utils
{
    namespace time
    {
        class Scoped
        {
            TickType_t timestamp;
            std::string text;

          public:
            /// scoped timer usage:
            /// auto time = Scoped("lol");
            /// will log how much time elapsed in form 'lol time: 123'
            /// auto time is important - othervise item will be created and removed instantly
            Scoped(const std::string &text)
            {
#if DEBUG_SCOPED_TIMINGS == 1
                this->text = text;
                timestamp  = cpp_freertos::Ticks::GetTicks();
#endif
            }
            ~Scoped()
            {
#if DEBUG_SCOPED_TIMINGS == 1
                LOG_DEBUG("%s time: %" PRIu32, text.c_str(), cpp_freertos::Ticks::GetTicks() - timestamp);
#endif
            }
        };

    }; // namespace time
};     // namespace utils