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