From 03cb3c2145603c3c4795014739bf5f2974bae7c3 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 12 Jun 2020 16:37:03 -0700 Subject: [PATCH] basic stack debugging - we are okay for now --- src/WorkerThread.cpp | 12 ++++++++++-- src/WorkerThread.h | 2 ++ src/main.cpp | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/WorkerThread.cpp b/src/WorkerThread.cpp index f84d83be..bf38a926 100644 --- a/src/WorkerThread.cpp +++ b/src/WorkerThread.cpp @@ -1,4 +1,5 @@ #include "WorkerThread.h" +#include "debug.h" #include void Thread::start(const char *name, size_t stackSize, uint32_t priority) @@ -16,6 +17,15 @@ void WorkerThread::doRun() { while (!wantExit) { block(); + +#ifdef DEBUG_STACK + static uint32_t lastPrint = 0; + if (millis() - lastPrint > 10 * 1000L) { + lastPrint = millis(); + meshtastic::printThreadInfo("net"); + } +#endif + loop(); } } @@ -28,8 +38,6 @@ void NotifiedWorkerThread::notify(uint32_t v, eNotifyAction action) xTaskNotify(taskHandle, v, action); } - - void NotifiedWorkerThread::block() { xTaskNotifyWait(0, // don't clear notification on entry diff --git a/src/WorkerThread.h b/src/WorkerThread.h index 86ec08e1..655e316f 100644 --- a/src/WorkerThread.h +++ b/src/WorkerThread.h @@ -15,6 +15,8 @@ class Thread virtual ~Thread() { vTaskDelete(taskHandle); } + uint32_t getStackHighwaterMark() { return uxTaskGetStackHighWaterMark(taskHandle); } + protected: /** * The method that will be called when start is called. diff --git a/src/main.cpp b/src/main.cpp index d7fb21bd..0c9fe5ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ #include "power.h" // #include "rom/rtc.h" #include "DSRRouter.h" +#include "debug.h" #include "main.h" #include "screen.h" #include "sleep.h" @@ -314,6 +315,14 @@ void loop() showingBootScreen = false; } +#ifdef DEBUG_STACK + static uint32_t lastPrint = 0; + if (millis() - lastPrint > 10 * 1000L) { + lastPrint = millis(); + meshtastic::printThreadInfo("main"); + } +#endif + // Update the screen last, after we've figured out what to show. screen.debug()->setNodeNumbersStatus(nodeDB.getNumOnlineNodes(), nodeDB.getNumNodes()); screen.debug()->setChannelNameStatus(channelSettings.name);