ifw-fnd 1.0.0
Loading...
Searching...
No Matches
tools.hpp
Go to the documentation of this file.
1
14#ifndef IFW_FND_TOOLS_HPP_H_
15#define IFW_FND_TOOLS_HPP_H_
16
17#include <array>
18#include <execinfo.h>
19#include <iomanip>
20#include <iostream>
21#include <iostream>
22#include <string>
23#include <thread>
24#include <vector>
25#include <queue>
26
27#include <fmt/format.h>
28
29
31#include <ifw/fnd/defs/base.hpp>
32
33
34namespace ifw::fnd::tools {
35
41 inline std::string GetLoggersAsStrList() {
42 LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
43 std::string reply;
44 for (auto it : log4cplus::Logger::getCurrentLoggers()) {
45 std::string log_level = log4cplus::getLogLevelManager().toString(it.getLogLevel());
46 reply += ", " + fmt::format("{}: {}", it.getName(), log_level);
47 }
48 return reply.substr(1);
49 }
50
53 public:
59 explicit LoopFrequencyCalculator(size_t window_size = 100);
60
61 void SetWindowSize(const size_t window_size);
62
63 // Method to mark the current time (called at each loop iteration)
64 void Tick();
65
66 // Method to get the current calculated frequency in Hz
67 double GetFrequency() const;
68
69 // Reset internal buffers to start over measurement.
70 void Reset();
71
72 private:
73 size_t m_window_size; // Number of samples in the window
74 std::queue<std::chrono::high_resolution_clock::time_point> m_timestamps; // Timestamps queue
75 std::queue<long long> m_durations; // Durations queue (in milliseconds)
76 long long m_sum_durations; // Sum of the durations in the current window
77 };
78}
79
80#endif
Class to calculate the frequency of a loop using a moving average window.
Definition tools.hpp:52
void Reset()
Definition tools.cpp:53
double GetFrequency() const
Definition tools.cpp:45
void SetWindowSize(const size_t window_size)
Definition tools.cpp:21
LoopFrequencyCalculator(size_t window_size=100)
Definition tools.cpp:18
void Tick()
Definition tools.cpp:26
Header file for the IFW Foundation Tools library.
Definition tools.hpp:34
std::string GetLoggersAsStrList()
Definition tools.hpp:41
log4cplus::Logger & Logger()
Definition defs.cpp:18