Merge pull request #4431 from andrethomas/patch-1

Add main loop load average
This commit is contained in:
Theo Arends 2018-11-24 17:16:59 +01:00 committed by GitHub
commit b061f8d135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -125,6 +125,7 @@ int wifi_state_flag = WIFI_RESTART; // Wifi state flag
int tele_period = 1; // Tele period timer int tele_period = 1; // Tele period timer
int blinks = 201; // Number of LED blinks int blinks = 201; // Number of LED blinks
uint32_t uptime = 0; // Counting every second until 4294967295 = 130 year uint32_t uptime = 0; // Counting every second until 4294967295 = 130 year
uint32_t loop_load_avg = 0; // Indicative loop load average
uint32_t global_update = 0; // Timestamp of last global temperature and humidity update uint32_t global_update = 0; // Timestamp of last global temperature and humidity update
float global_temperature = 0; // Provide a global temperature to be used by some sensors float global_temperature = 0; // Provide a global temperature to be used by some sensors
float global_humidity = 0; // Provide a global humidity to be used by some sensors float global_humidity = 0; // Provide a global humidity to be used by some sensors
@ -191,6 +192,7 @@ char log_data[LOGSZ]; // Logging
char web_log[WEB_LOG_SIZE] = {'\0'}; // Web log buffer char web_log[WEB_LOG_SIZE] = {'\0'}; // Web log buffer
String backlog[MAX_BACKLOG]; // Command backlog String backlog[MAX_BACKLOG]; // Command backlog
/********************************************************************************************/ /********************************************************************************************/
char* Format(char* output, const char* input, int size) char* Format(char* output, const char* input, int size)
@ -1575,6 +1577,8 @@ void MqttShowState(void)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1);
#endif #endif
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"LoadAvg\":%u"), mqtt_data, loop_load_avg);
for (byte i = 0; i < devices_present; i++) { for (byte i = 0; i < devices_present; i++) {
if (i == light_device -1) { if (i == light_device -1) {
LightState(1); LightState(1);
@ -2579,6 +2583,15 @@ void GpioInit(void)
XdrvCall(FUNC_PRE_INIT); XdrvCall(FUNC_PRE_INIT);
} }
void update_loop_load_avg(uint32_t loop_activity)
{
uint32_t loops_per_second = 1000 / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]; // We need to keep track of this many loops per second
uint32_t this_cycle_ratio = 100 * loop_activity / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY];
uint32_t new_load_avg = loop_load_avg-(loop_load_avg/loops_per_second); // Take away one loop average
new_load_avg = new_load_avg + this_cycle_ratio;
loop_load_avg = new_load_avg;
}
extern "C" { extern "C" {
extern struct rst_info resetInfo; extern struct rst_info resetInfo;
@ -2785,4 +2798,9 @@ void loop(void)
delay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period delay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period
} }
} }
if (my_activity < (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]) {
update_loop_load_avg(my_activity);
} else {
update_loop_load_avg((uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]); // Assume 100% loop cycle ratio
}
} }