Skip to content

Commit

Permalink
[Memory] Allow to disable collecting timing stats to save RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Jul 2, 2021
1 parent 71fcf79 commit 64e3c4a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/src/CustomBuild/ESPEasyDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@
#ifndef DEFAULT_JSON_BOOL_WITHOUT_QUOTES
#define DEFAULT_JSON_BOOL_WITHOUT_QUOTES false
#endif
#ifndef DEFAULT_ENABLE_TIMING_STATS
#define DEFAULT_ENABLE_TIMING_STATS false
#endif



Expand Down
10 changes: 10 additions & 0 deletions src/src/DataStructs/SettingsStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ void SettingsStruct_tmpl<N_TASKS>::JSONBoolWithoutQuotes(bool value) {
bitWrite(VariousBits1, 16, value);
}

template<unsigned int N_TASKS>
bool SettingsStruct_tmpl<N_TASKS>::EnableTimingStats() const {
return bitRead(VariousBits1, 17);
}

template<unsigned int N_TASKS>
void SettingsStruct_tmpl<N_TASKS>::EnableTimingStats(bool value) {
bitWrite(VariousBits1, 17, value);
}

template<unsigned int N_TASKS>
bool SettingsStruct_tmpl<N_TASKS>::CombineTaskValues_SingleEvent(taskIndex_t taskIndex) const {
if (validTaskIndex(taskIndex)) {
Expand Down
4 changes: 4 additions & 0 deletions src/src/DataStructs/SettingsStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class SettingsStruct_tmpl
// When outputting JSON bools use quoted values (on, backward compatible) or use official JSON true/false unquoted
bool JSONBoolWithoutQuotes() const;
void JSONBoolWithoutQuotes(bool value);

// Enable timing statistics (may consume a few kB of RAM)
bool EnableTimingStats() const;
void EnableTimingStats(bool value);


// Flag indicating whether all task values should be sent in a single event or one event per task value (default behavior)
Expand Down
2 changes: 2 additions & 0 deletions src/src/DataStructs/TimingStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const __FlashStringHelper * getPluginFunctionName(int function) {
}

bool mustLogFunction(int function) {
if (!Settings.EnableTimingStats()) return false;
switch (function) {
case PLUGIN_INIT_ALL: return false;
case PLUGIN_INIT: return false;
Expand Down Expand Up @@ -163,6 +164,7 @@ const __FlashStringHelper * getCPluginCFunctionName(CPlugin::Function function)
}

bool mustLogCFunction(CPlugin::Function function) {
if (!Settings.EnableTimingStats()) return false;
switch (function) {
case CPlugin::Function::CPLUGIN_PROTOCOL_ADD: return false;
case CPlugin::Function::CPLUGIN_PROTOCOL_TEMPLATE: return false;
Expand Down
4 changes: 2 additions & 2 deletions src/src/DataStructs/TimingStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ extern unsigned long timingstats_last_reset;
if (mustLogCFunction(F)) controllerStats[(T) * 256 + static_cast<int>(F)].add(usecPassedSince(statisticsTimerStart));

// #define STOP_TIMER_LOADFILE miscStats[LOADFILE_STATS].add(usecPassedSince(statisticsTimerStart));
# define STOP_TIMER(L) miscStats[L].add(usecPassedSince(statisticsTimerStart));
# define STOP_TIMER(L) if (Settings.EnableTimingStats()) { miscStats[L].add(usecPassedSince(statisticsTimerStart)); }

// Add a timer statistic value in usec.
# define ADD_TIMER_STAT(L, T) miscStats[L].add(T);
# define ADD_TIMER_STAT(L, T) if (Settings.EnableTimingStats()) { miscStats[L].add(T); }

#else // ifdef USES_TIMING_STATS

Expand Down
1 change: 1 addition & 0 deletions src/src/Helpers/ESPEasyRTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../ESPEasyCore/ESPEasy_Log.h"
#include "../Globals/Plugins.h"
#include "../Globals/RuntimeData.h"
#include "../Globals/Settings.h"
#include "../Helpers/CRC_functions.h"
#include "../../ESPEasy_common.h"

Expand Down
1 change: 1 addition & 0 deletions src/src/Helpers/ESPEasy_FactoryDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void ResetFactory()
Settings.I2C_clockSpeed = DEFAULT_I2C_CLOCK_SPEED;

Settings.JSONBoolWithoutQuotes(DEFAULT_JSON_BOOL_WITHOUT_QUOTES);
Settings.EnableTimingStats(DEFAULT_ENABLE_TIMING_STATS);

#ifdef PLUGIN_DESCR
strcpy_P(Settings.Name, PSTR(PLUGIN_DESCR));
Expand Down
7 changes: 7 additions & 0 deletions src/src/Helpers/StringProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const __FlashStringHelper * getLabel(LabelType::Enum label) {
#endif // ESP32_ENABLE_PSRAM
#endif // ifdef ESP32

case LabelType::JSON_BOOL_QUOTES: return F("JSON bool output without quotes");
case LabelType::ENABLE_TIMING_STATISTICS: return F("Collect Timing Statistics");


case LabelType::BOOT_TYPE: return F("Last Boot Cause");
case LabelType::BOOT_COUNT: return F("Boot Count");
case LabelType::DEEP_SLEEP_ALTERNATIVE_CALL: return F("Deep Sleep Alternative");
Expand Down Expand Up @@ -241,6 +245,9 @@ String getValue(LabelType::Enum label) {
#endif // ifdef ESP32


case LabelType::JSON_BOOL_QUOTES: return jsonBool(Settings.JSONBoolWithoutQuotes());
case LabelType::ENABLE_TIMING_STATISTICS: return jsonBool(Settings.EnableTimingStats());

case LabelType::BOOT_TYPE: return getLastBootCauseString();
case LabelType::BOOT_COUNT: break;
case LabelType::DEEP_SLEEP_ALTERNATIVE_CALL: return jsonBool(Settings.UseAlternativeDeepSleep());
Expand Down
3 changes: 3 additions & 0 deletions src/src/Helpers/StringProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct LabelType {
#endif // ESP32_ENABLE_PSRAM
#endif // ifdef ESP32

JSON_BOOL_QUOTES,
ENABLE_TIMING_STATISTICS,

BOOT_TYPE, // Cold boot
BOOT_COUNT, // 0
RESET_REASON, // Software/System restart
Expand Down
8 changes: 6 additions & 2 deletions src/src/WebServer/AdvancedConfigPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void handle_advanced() {
Settings.NumberExtraWiFiScans = getFormItemInt(LabelType::WIFI_NR_EXTRA_SCANS);
Settings.PeriodicalScanWiFi(isFormItemChecked(LabelType::WIFI_PERIODICAL_SCAN));
Settings.UseLastWiFiFromRTC(isFormItemChecked(LabelType::WIFI_USE_LAST_CONN_FROM_RTC));
Settings.JSONBoolWithoutQuotes(isFormItemChecked(F("json_bool_with_quotes")));
Settings.JSONBoolWithoutQuotes(isFormItemChecked(LabelType::JSON_BOOL_QUOTES));
Settings.EnableTimingStats(isFormItemChecked(LabelType::ENABLE_TIMING_STATISTICS));
#ifdef ESP8266
Settings.UseAlternativeDeepSleep(isFormItemChecked(LabelType::DEEP_SLEEP_ALTERNATIVE_CALL));
#endif
Expand Down Expand Up @@ -202,7 +203,10 @@ void handle_advanced() {
addFormCheckBox_disabled(F("Enable RTOS Multitasking"), F("usertosmultitasking"), Settings.UseRTOSMultitasking);
#endif // if defined(ESP32)

addFormCheckBox(F("JSON bool output without quotes"), F("json_bool_with_quotes"), Settings.JSONBoolWithoutQuotes());
addFormCheckBox(LabelType::JSON_BOOL_QUOTES, Settings.JSONBoolWithoutQuotes());
#ifdef USES_TIMING_STATS
addFormCheckBox(LabelType::ENABLE_TIMING_STATISTICS, Settings.EnableTimingStats());
#endif
#ifdef ESP8266
addFormCheckBox(LabelType::DEEP_SLEEP_ALTERNATIVE_CALL, Settings.UseAlternativeDeepSleep());
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/src/WebServer/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ void writeDefaultCSS(void)
{
return; // TODO

#ifndef BUILD_NO_DEBUG
/*
#ifndef WEBSERVER_USE_CDN_JS_CSS
if (!fileExists(F("esp.css")))
{
Expand All @@ -785,7 +786,8 @@ void writeDefaultCSS(void)
f.close();
}
}
#endif // ifndef BUILD_NO_DEBUG
#endif
*/
}

// ********************************************************************************
Expand Down

0 comments on commit 64e3c4a

Please sign in to comment.