mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
time works
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP8266
|
||||
#include <TZ.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
void Time_Init();
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* Получение текущего времени
|
||||
*/
|
||||
String getTime();
|
||||
|
||||
/*
|
||||
* Получаем время в формате linux gmt
|
||||
*/
|
||||
@@ -36,11 +34,15 @@ int timeToMin(String Time);
|
||||
const String prettyMillis(unsigned long time_ms = millis());
|
||||
|
||||
/*
|
||||
* Время (мс) прошедщее с @simce
|
||||
* Время (мс) прошедщее с @since
|
||||
*/
|
||||
unsigned long millis_since(unsigned long sinse);
|
||||
|
||||
/*
|
||||
* Интерввал времени (мс) между @start и @fimish
|
||||
* Интерввал времени (мс) между @start и @finish
|
||||
*/
|
||||
unsigned long millis_passed(unsigned long start, unsigned long finish);
|
||||
unsigned long millis_passed(unsigned long start, unsigned long finish);
|
||||
|
||||
int getOffsetInSeconds(int timezone);
|
||||
|
||||
int getOffsetInMinutes(int timezone);
|
||||
|
||||
71
include/Utils/Timings.h
Normal file
71
include/Utils/Timings.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
enum Timings_t { MT_ONE,
|
||||
MT_TWO,
|
||||
NUM_TIMINGS };
|
||||
|
||||
struct Timing {
|
||||
unsigned long _total_mu;
|
||||
unsigned long _min_mu;
|
||||
unsigned long _max_mu;
|
||||
|
||||
Timing() : _total_mu{0}, _min_mu{999999}, _max_mu{0} {};
|
||||
|
||||
void reset() {
|
||||
_total_mu = 0;
|
||||
_min_mu = 999999;
|
||||
_max_mu = 0;
|
||||
}
|
||||
|
||||
void add(unsigned long time_mu) {
|
||||
if (time_mu == 0) return;
|
||||
|
||||
_total_mu += time_mu;
|
||||
|
||||
if (_min_mu > time_mu) {
|
||||
_min_mu = time_mu;
|
||||
}
|
||||
|
||||
if (_max_mu < time_mu) {
|
||||
_max_mu = time_mu;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const char* module_name[NUM_TIMINGS] = {"strings", "boolean"};
|
||||
|
||||
struct Timings {
|
||||
Timing mu[NUM_TIMINGS];
|
||||
|
||||
unsigned long _counter;
|
||||
unsigned long _start;
|
||||
unsigned long long _total;
|
||||
|
||||
Timings() : _counter{0}, _start{0} {};
|
||||
|
||||
void add(size_t module, unsigned long now = micros()) {
|
||||
unsigned long time = now - _start;
|
||||
_total += time;
|
||||
mu[module].add(time);
|
||||
_start = now;
|
||||
}
|
||||
|
||||
void count() {
|
||||
_counter++;
|
||||
_start = micros();
|
||||
}
|
||||
|
||||
void print() {
|
||||
if (!_counter) {
|
||||
return;
|
||||
};
|
||||
Serial.printf("lp/ms: %llu ", _counter / _total);
|
||||
for (size_t i = 0; i < NUM_TIMINGS; i++) {
|
||||
Serial.printf("%s: %.2f%% ", module_name[i], ((float)mu[i]._total_mu / _total) * 100);
|
||||
mu[i].reset();
|
||||
}
|
||||
Serial.println();
|
||||
_counter = 0;
|
||||
_total = 0;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user