Skip to content

Commit

Permalink
[Cleanup] Make timing stats optional to reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er committed Nov 18, 2019
1 parent ae0143b commit 761dac1
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 159 deletions.
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ build_flags = ${debug_flags.build_flags} ${mqtt_flags.build_flags}
build_unflags = -DDEBUG_ESP_PORT
lib_deps = https://github.com/TD-er/ESPEasySerial.git
lib_ignore = ESP32_ping, ESP32WebServer, IRremoteESP8266, HeatpumpIR, SD(esp8266), SDFS
;lib_ignore = ESP32_ping, ESP32WebServer, IRremoteESP8266, HeatpumpIR
lib_ldf_mode = chain
lib_archive = false
upload_speed = 115200
Expand Down
71 changes: 71 additions & 0 deletions src/Controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,74 @@ void MQTTStatus(const String& status)
}
}
#endif //USES_MQTT



/*********************************************************************************************\
* send all sensordata
\*********************************************************************************************/
// void SensorSendAll()
// {
// for (taskIndex_t x = 0; x < TASKS_MAX; x++)
// {
// SensorSendTask(x);
// }
// }


/*********************************************************************************************\
* send specific sensor task data
\*********************************************************************************************/
void SensorSendTask(taskIndex_t TaskIndex)
{
if (!validTaskIndex(TaskIndex)) return;
checkRAM(F("SensorSendTask"));
if (Settings.TaskDeviceEnabled[TaskIndex])
{
byte varIndex = TaskIndex * VARS_PER_TASK;

bool success = false;
const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(TaskIndex);
if (!validDeviceIndex(DeviceIndex)) return;

LoadTaskSettings(TaskIndex);

struct EventStruct TempEvent;
TempEvent.TaskIndex = TaskIndex;
TempEvent.BaseVarIndex = varIndex;
// TempEvent.idx = Settings.TaskDeviceID[TaskIndex]; todo check
TempEvent.sensorType = Device[DeviceIndex].VType;

float preValue[VARS_PER_TASK]; // store values before change, in case we need it in the formula
for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
preValue[varNr] = UserVar[varIndex + varNr];

if(Settings.TaskDeviceDataFeed[TaskIndex] == 0) // only read local connected sensorsfeeds
{
String dummy;
success = PluginCall(PLUGIN_READ, &TempEvent, dummy);
}
else
success = true;

if (success)
{
START_TIMER;
for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
{
if (ExtraTaskSettings.TaskDeviceFormula[varNr][0] != 0)
{
String formula = ExtraTaskSettings.TaskDeviceFormula[varNr];
formula.replace(F("%pvalue%"), String(preValue[varNr]));
formula.replace(F("%value%"), String(UserVar[varIndex + varNr]));
float result = 0;
byte error = Calculate(formula.c_str(), &result);
if (error == 0)
UserVar[varIndex + varNr] = result;
}
}
STOP_TIMER(COMPUTE_FORMULA_STATS);
sendData(&TempEvent);
}
}
}
30 changes: 0 additions & 30 deletions src/ESPEasy-Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,36 +356,6 @@ extern boolean UseRTOSMultitasking;
// void (*MainLoopCall_ptr)(void); //FIXME TD-er: No idea what this does.


/*
String getLogLine(const TimingStats& stats) {
unsigned long minVal, maxVal;
unsigned int c = stats.getMinMax(minVal, maxVal);
String log;
log.reserve(64);
log += F("Count: ");
log += c;
log += F(" Avg/min/max ");
log += stats.getAvg();
log += '/';
log += minVal;
log += '/';
log += maxVal;
log += F(" usec");
return log;
}
*/














#include "src/DataStructs/DeviceModel.h"
Expand Down
70 changes: 2 additions & 68 deletions src/ESPEasy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ void updateLoopStats() {
return;
}
const long usecSince = usecPassedSince(lastLoopStart);
#ifdef USES_TIMING_STATS
miscStats[LOOP_STATS].add(usecSince);
#endif

loop_usec_duration_total += usecSince;
lastLoopStart = micros();
Expand Down Expand Up @@ -881,74 +883,6 @@ void runEach30Seconds()
}


/*********************************************************************************************\
* send all sensordata
\*********************************************************************************************/
// void SensorSendAll()
// {
// for (taskIndex_t x = 0; x < TASKS_MAX; x++)
// {
// SensorSendTask(x);
// }
// }


/*********************************************************************************************\
* send specific sensor task data
\*********************************************************************************************/
void SensorSendTask(taskIndex_t TaskIndex)
{
if (!validTaskIndex(TaskIndex)) return;
checkRAM(F("SensorSendTask"));
if (Settings.TaskDeviceEnabled[TaskIndex])
{
byte varIndex = TaskIndex * VARS_PER_TASK;

bool success = false;
const deviceIndex_t DeviceIndex = getDeviceIndex_from_TaskIndex(TaskIndex);
if (!validDeviceIndex(DeviceIndex)) return;

LoadTaskSettings(TaskIndex);

struct EventStruct TempEvent;
TempEvent.TaskIndex = TaskIndex;
TempEvent.BaseVarIndex = varIndex;
// TempEvent.idx = Settings.TaskDeviceID[TaskIndex]; todo check
TempEvent.sensorType = Device[DeviceIndex].VType;

float preValue[VARS_PER_TASK]; // store values before change, in case we need it in the formula
for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
preValue[varNr] = UserVar[varIndex + varNr];

if(Settings.TaskDeviceDataFeed[TaskIndex] == 0) // only read local connected sensorsfeeds
{
String dummy;
success = PluginCall(PLUGIN_READ, &TempEvent, dummy);
}
else
success = true;

if (success)
{
START_TIMER;
for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
{
if (ExtraTaskSettings.TaskDeviceFormula[varNr][0] != 0)
{
String formula = ExtraTaskSettings.TaskDeviceFormula[varNr];
formula.replace(F("%pvalue%"), String(preValue[varNr]));
formula.replace(F("%value%"), String(UserVar[varIndex + varNr]));
float result = 0;
byte error = Calculate(formula.c_str(), &result);
if (error == 0)
UserVar[varIndex + varNr] = result;
}
}
STOP_TIMER(COMPUTE_FORMULA_STATS);
sendData(&TempEvent);
}
}
}


/*********************************************************************************************\
Expand Down
7 changes: 7 additions & 0 deletions src/ESPEasyStatistics.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "define_plugin_sets.h"

#ifdef USES_TIMING_STATS

/*
void logStatistics(byte loglevel, bool clearStats) {
if (loglevelActiveFor(loglevel)) {
Expand Down Expand Up @@ -91,3 +95,6 @@ void jsonStatistics(bool clearStats) {
stream_json_end_object_element(true); // end "plugin" object
stream_json_end_array_element(true); // end "plugin" array
}


#endif
2 changes: 2 additions & 0 deletions src/WebServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,12 @@ void sendHeadandTail(const String& tmplName, boolean Tail = false, boolean reboo
// This function is called twice per serving a web page.
// So it must keep track of the timer longer than the scope of this function.
// Therefore use a local static variable.
#ifdef USES_TIMING_STATS
static unsigned statisticsTimerStart = 0;
if (!Tail) {
statisticsTimerStart = micros();
}
#endif

String pageTemplate = "";
String fileName = tmplName;
Expand Down
2 changes: 2 additions & 0 deletions src/WebServer_JSON.ino
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ void stream_json_end_object_element(bool isLast) {
void handle_timingstats_json() {
TXBuffer.startJsonStream();
TXBuffer += '{';
#ifdef USES_TIMING_STATS
jsonStatistics(false);
#endif
TXBuffer += '}';
TXBuffer.endStream();
}
Expand Down
21 changes: 21 additions & 0 deletions src/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ To create/register a plugin, you have to :
#ifndef USES_SSDP
#define USES_SSDP
#endif
#ifndef USES_TIMING_STATS
#define USES_TIMING_STATS
#endif
#endif



#ifdef MEMORY_ANALYSIS
#ifdef MQTT_ONLY
#define USES_C002 // Domoticz MQTT
Expand Down Expand Up @@ -237,6 +242,9 @@ To create/register a plugin, you have to :
#undef USE_SETTINGS_ARCHIVE
#endif // USE_SETTINGS_ARCHIVE

#ifdef USES_TIMING_STATS
#undef USES_TIMING_STATS
#endif

#ifndef USES_P001
#define USES_P001 // switch
Expand Down Expand Up @@ -981,4 +989,17 @@ To create/register a plugin, you have to :
#endif
#endif



// Timing stats page needs timing stats
#if defined(WEBSERVER_TIMINGSTATS) && !defined(USES_TIMING_STATS)
#define USES_TIMING_STATS
#endif

// If timing stats page is not included, there is no need in collecting the stats
#if !defined(WEBSERVER_TIMINGSTATS) && defined(USES_TIMING_STATS)
#undef USES_TIMING_STATS
#endif


#endif // DEFINE_PLUGIN_SETS_H
3 changes: 3 additions & 0 deletions src/src/DataStructs/TimingStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../../ESPEasy_plugindefs.h"
#include "../../_CPlugin_Helper.h"

#ifdef USES_TIMING_STATS


std::map<int, TimingStats> pluginStats;
Expand Down Expand Up @@ -225,3 +226,5 @@ String getMiscStatsName(int stat) {
}
return getUnknownString();
}

#endif
Loading

0 comments on commit 761dac1

Please sign in to comment.