figments: mainloop: add debugging tool that records last task prior to reset
This commit is contained in:
parent
1426b1524b
commit
de5d3e836a
@ -13,31 +13,48 @@ MainLoop::dispatch(const InputEvent& evt)
|
|||||||
m_eventBuf.insert(evt);
|
m_eventBuf.insert(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#ifdef BOARD_ESP32
|
||||||
|
__NOINIT_ATTR const char* s_lastTaskName;
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
MainLoop::dispatchSync(const InputEvent& evt)
|
||||||
|
{
|
||||||
|
if (evt.intent == InputEvent::StartThing || evt.intent == InputEvent::StopThing) {
|
||||||
|
const bool jobState = (evt.intent == InputEvent::StartThing);
|
||||||
|
for(auto figmentJob: scheduler.tasks) {
|
||||||
|
if (!strcmp(figmentJob->name, evt.asString())) {
|
||||||
|
if (jobState) {
|
||||||
|
Log.trace("** Starting %s", figmentJob->name);
|
||||||
|
figmentJob->start();
|
||||||
|
} else {
|
||||||
|
Log.trace("** Stopping %s", figmentJob->name);
|
||||||
|
figmentJob->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Task* task : scheduler) {
|
||||||
|
Log.verbose("** Eventing %s", task->name);
|
||||||
|
s_lastTaskName = task->name;
|
||||||
|
task->handleEvent(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
MainLoop::lastTaskName()
|
||||||
|
{
|
||||||
|
return s_lastTaskName;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MainLoop::loop()
|
MainLoop::loop()
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
InputEvent evt;
|
InputEvent evt;
|
||||||
while (m_eventBuf.take(evt)) {
|
while (m_eventBuf.take(evt)) {
|
||||||
if (evt.intent == InputEvent::StartThing || evt.intent == InputEvent::StopThing) {
|
dispatchSync(evt);
|
||||||
const bool jobState = (evt.intent == InputEvent::StartThing);
|
|
||||||
for(auto figmentJob: scheduler.tasks) {
|
|
||||||
if (!strcmp(figmentJob->name, evt.asString())) {
|
|
||||||
if (jobState) {
|
|
||||||
Log.trace("** Starting %s", figmentJob->name);
|
|
||||||
figmentJob->start();
|
|
||||||
} else {
|
|
||||||
Log.trace("** Stopping %s", figmentJob->name);
|
|
||||||
figmentJob->stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Task* task : scheduler) {
|
|
||||||
Log.verbose("** Eventing %s", task->name);
|
|
||||||
task->handleEvent(evt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unsigned int slowest = 0;
|
unsigned int slowest = 0;
|
||||||
unsigned int frameSpeed = 0;
|
unsigned int frameSpeed = 0;
|
||||||
@ -52,6 +69,7 @@ MainLoop::loop()
|
|||||||
unsigned int start = millis();
|
unsigned int start = millis();
|
||||||
#endif
|
#endif
|
||||||
Log.verbose("Running %s", task->name);
|
Log.verbose("Running %s", task->name);
|
||||||
|
s_lastTaskName = task->name;
|
||||||
task->loop();
|
task->loop();
|
||||||
#if defined(BOARD_ESP32) or defined(BOARD_ESP8266)
|
#if defined(BOARD_ESP32) or defined(BOARD_ESP8266)
|
||||||
unsigned int runtime = (ESP.getCycleCount() - start) / 160000;
|
unsigned int runtime = (ESP.getCycleCount() - start) / 160000;
|
||||||
@ -66,7 +84,7 @@ MainLoop::loop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
frameSpeed = millis() - frameStart;
|
frameSpeed = millis() - frameStart;
|
||||||
if (frameSpeed >= 23) {
|
if (frameSpeed >= 23) { // TODO: Configure max frame time at build
|
||||||
const char* slowestName = (slowestTask->name ? slowestTask->name : "(Unnamed)");
|
const char* slowestName = (slowestTask->name ? slowestTask->name : "(Unnamed)");
|
||||||
Log.warning("Slow frame: %dms, %d tasks, longest task %s was %dms", frameSpeed, taskCount, slowestTask->name, slowest);
|
Log.warning("Slow frame: %dms, %d tasks, longest task %s was %dms", frameSpeed, taskCount, slowestTask->name, slowest);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,9 @@ struct MainLoop {
|
|||||||
void start();
|
void start();
|
||||||
void loop();
|
void loop();
|
||||||
void dispatch(const InputEvent& event);
|
void dispatch(const InputEvent& event);
|
||||||
|
void dispatchSync(const InputEvent& event);
|
||||||
static MainLoop* instance() { return s_instance; }
|
static MainLoop* instance() { return s_instance; }
|
||||||
|
static const char* lastTaskName();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ringbuf<InputEvent, 32> m_eventBuf;
|
Ringbuf<InputEvent, 32> m_eventBuf;
|
||||||
|
Loading…
Reference in New Issue
Block a user