77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
/**
|
|
* @file debugTimes.h
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief Inherits a class to measure times of functions.
|
|
* @version 0.1
|
|
* @date 2021-12-13
|
|
*
|
|
* @copyright Copyright (c) 2021
|
|
*
|
|
*/
|
|
|
|
#ifndef DEBUG_TIMES_H
|
|
#define DEBUG_TIMES_H
|
|
|
|
#include <list>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
|
|
#include <Arduino.h>
|
|
|
|
/**
|
|
* @brief A class to measure times of functions.
|
|
*
|
|
* This simple class only save the value of the millis()
|
|
* function when you call the constructor or restart().
|
|
* To get the elapsed time call stop() or stopConsol().
|
|
*
|
|
* @warning This class is not very accurate
|
|
* It only give you the time in milliseconds.
|
|
*/
|
|
class DebugTimes {
|
|
public:
|
|
/**
|
|
* @brief Construct a new Debug Times object
|
|
* Starts to count milliseconds
|
|
*/
|
|
|
|
DebugTimes();
|
|
/**
|
|
* @brief Set the counter to 0
|
|
*/
|
|
|
|
void restart();
|
|
|
|
/**
|
|
* @brief Give the elapsed time
|
|
*
|
|
* @return uint16_t elapsed milliseconds
|
|
*/
|
|
uint16_t stop();
|
|
|
|
/**
|
|
* @brief Print the elapsed time to consol
|
|
*
|
|
* @param name Functionname to print
|
|
* @param minTime A minimum time before printing
|
|
*
|
|
* @return uint16_t elapsed milliseconds
|
|
*/
|
|
uint16_t stopConsol(const char* name, uint16_t minTime = 0);
|
|
|
|
/**
|
|
* @brief Sets if the result should be printed.
|
|
*
|
|
* @param enable
|
|
*/
|
|
static void setConsolOutput(bool enable);
|
|
|
|
private:
|
|
uint64_t startTime;
|
|
|
|
static bool print;
|
|
static bool printWarning;
|
|
};
|
|
|
|
#endif //DEBUG_TIMES_H
|