Berry tasmota.loglevel() and tasmota.rtc_utc() for faster performance (#19152)

This commit is contained in:
s-hadinger 2023-07-19 20:58:50 +02:00 committed by GitHub
parent 91f15d228b
commit 2a3690b866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 1 deletions

View File

@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Berry `_class` can be used in `static var` initialization code (#19088)
- Berry add `energy.update_total()` to call `EnergyUpdateTotal()` from energy driver
- Berry add metrics for memory allocation/deallocation/reallocation
- Berry `tasmota.loglevel()` and `tasmota.rtc_utc()` for faster performance
### Breaking Changed

View File

@ -21,6 +21,7 @@ extern int l_getoption(bvm *vm);
extern int l_millis(bvm *vm);
extern int l_timereached(bvm *vm);
extern int l_rtc(bvm *vm);
extern int l_rtc_utc(bvm *vm);
extern int l_time_dump(bvm *vm);
extern int l_strftime(bvm *vm);
extern int l_strptime(bvm *vm);
@ -33,6 +34,7 @@ extern int l_delay(bvm *vm);
extern int l_delay_microseconds(bvm *vm);
extern int l_scaleuint(bvm *vm);
extern int l_logInfo(bvm *vm);
extern int l_loglevel(bvm *vm);
extern int l_save(bvm *vm);
extern int t_random_byte(bvm *vm);
extern int l_locale(bvm *vm);
@ -99,6 +101,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
millis, func(l_millis)
time_reached, func(l_timereached)
rtc, func(l_rtc)
rtc_utc, func(l_rtc_utc)
time_dump, func(l_time_dump)
strftime, func(l_strftime)
strptime, func(l_strptime)
@ -111,6 +114,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
delay_microseconds, func(l_delay_microseconds)
scale_uint, func(l_scaleuint)
log, func(l_logInfo)
loglevel, func(l_loglevel)
save, func(l_save)
locale, func(l_locale)

View File

@ -2478,13 +2478,18 @@ void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_pa
}
}
void AddLog(uint32_t loglevel, PGM_P formatP, ...) {
uint32_t HighestLogLevel() {
uint32_t highest_loglevel = TasmotaGlobal.seriallog_level;
if (Settings->weblog_level > highest_loglevel) { highest_loglevel = Settings->weblog_level; }
if (Settings->mqttlog_level > highest_loglevel) { highest_loglevel = Settings->mqttlog_level; }
if (TasmotaGlobal.syslog_level > highest_loglevel) { highest_loglevel = TasmotaGlobal.syslog_level; }
if (TasmotaGlobal.templog_level > highest_loglevel) { highest_loglevel = TasmotaGlobal.templog_level; }
if (TasmotaGlobal.uptime < 3) { highest_loglevel = LOG_LEVEL_DEBUG_MORE; } // Log all before setup correct log level
return highest_loglevel;
}
void AddLog(uint32_t loglevel, PGM_P formatP, ...) {
uint32_t highest_loglevel = HighestLogLevel();
// If no logging is requested then do not access heap to fight fragmentation
if ((loglevel <= highest_loglevel) && (TasmotaGlobal.masterlog_level <= highest_loglevel)) {

View File

@ -183,6 +183,14 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}
// Berry: tasmota.rtc_utc() -> int
//
int32_t l_rtc_utc(struct bvm *vm);
int32_t l_rtc_utc(struct bvm *vm) {
be_pushint(vm, Rtc.utc_time);
be_return(vm);
}
// Berry: tasmota.memory() -> map
//
int32_t l_memory(struct bvm *vm);
@ -790,6 +798,23 @@ extern "C" {
*
\*********************************************************************************************/
extern "C" {
// Berry: `loglevel() -> int`
// or
// Berry: `loglevel(int) -> bool`
// return the highest log level currently in place
int32_t l_loglevel(struct bvm *vm);
int32_t l_loglevel(struct bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
uint32_t highest_loglevel = HighestLogLevel();
if (top >= 2 && be_isint(vm, 2)) {
int32_t log_level = be_toint(vm, 2);
be_pushbool(vm, log_level <= highest_loglevel);
} else {
be_pushint(vm, HighestLogLevel());
}
be_return(vm);
}
// Berry: `log(msg:string [,log_level:int]) ->nil`
// Logs the string at LOG_LEVEL_INFO (loglevel=2)
// We allow this function to be called as a method or a direct function