Add more logging
This commit is contained in:
@@ -27,6 +27,7 @@ class Activity {
|
|||||||
explicit Activity(std::string name, GfxRenderer& renderer, MappedInputManager& mappedInput)
|
explicit Activity(std::string name, GfxRenderer& renderer, MappedInputManager& mappedInput)
|
||||||
: name(std::move(name)), renderer(renderer), mappedInput(mappedInput) {}
|
: name(std::move(name)), renderer(renderer), mappedInput(mappedInput) {}
|
||||||
virtual ~Activity() = default;
|
virtual ~Activity() = default;
|
||||||
|
const std::string& getName() const { return name; }
|
||||||
virtual void onEnter();
|
virtual void onEnter();
|
||||||
virtual void onExit();
|
virtual void onExit();
|
||||||
virtual void loop() {}
|
virtual void loop() {}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <HalClock.h>
|
#include <HalClock.h>
|
||||||
#include <HalPowerManager.h>
|
#include <HalPowerManager.h>
|
||||||
|
#include <Logging.h>
|
||||||
|
#include <esp_heap_caps.h>
|
||||||
|
#include <esp_system.h>
|
||||||
|
|
||||||
#include "CrossPointState.h"
|
#include "CrossPointState.h"
|
||||||
#include "boot_sleep/BootActivity.h"
|
#include "boot_sleep/BootActivity.h"
|
||||||
@@ -29,6 +32,17 @@ void ActivityManager::begin() {
|
|||||||
assert(renderTaskHandle != nullptr && "Failed to create render task");
|
assert(renderTaskHandle != nullptr && "Failed to create render task");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void logActivityStackState(const char* stage, Activity* currentActivity, size_t stackSize) {
|
||||||
|
const uint32_t freeHeap = esp_get_free_heap_size();
|
||||||
|
const uint32_t contigHeap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT);
|
||||||
|
LOG_DBG("ACT", "%s: current=%s stackSize=%zu free=%lu contig=%lu",
|
||||||
|
stage,
|
||||||
|
currentActivity ? currentActivity->getName().c_str() : "<none>",
|
||||||
|
stackSize,
|
||||||
|
freeHeap,
|
||||||
|
contigHeap);
|
||||||
|
}
|
||||||
|
|
||||||
void ActivityManager::renderTaskTrampoline(void* param) {
|
void ActivityManager::renderTaskTrampoline(void* param) {
|
||||||
auto* self = static_cast<ActivityManager*>(param);
|
auto* self = static_cast<ActivityManager*>(param);
|
||||||
self->renderTaskLoop();
|
self->renderTaskLoop();
|
||||||
@@ -149,6 +163,7 @@ void ActivityManager::loop() {
|
|||||||
RenderLock lock;
|
RenderLock lock;
|
||||||
|
|
||||||
if (pendingAction == PendingAction::Replace) {
|
if (pendingAction == PendingAction::Replace) {
|
||||||
|
logActivityStackState("replace_before", currentActivity.get(), stackActivities.size());
|
||||||
// Destroy the current activity
|
// Destroy the current activity
|
||||||
exitActivity(lock);
|
exitActivity(lock);
|
||||||
// Clear the stack
|
// Clear the stack
|
||||||
@@ -156,10 +171,13 @@ void ActivityManager::loop() {
|
|||||||
stackActivities.back()->onExit();
|
stackActivities.back()->onExit();
|
||||||
stackActivities.pop_back();
|
stackActivities.pop_back();
|
||||||
}
|
}
|
||||||
|
logActivityStackState("replace_after_clear", nullptr, stackActivities.size());
|
||||||
} else if (pendingAction == PendingAction::Push) {
|
} else if (pendingAction == PendingAction::Push) {
|
||||||
|
logActivityStackState("push_before", currentActivity.get(), stackActivities.size());
|
||||||
// Move current activity to stack
|
// Move current activity to stack
|
||||||
stackActivities.push_back(std::move(currentActivity));
|
stackActivities.push_back(std::move(currentActivity));
|
||||||
LOG_DBG("ACT", "Pushed to activity stack, new size = %zu", stackActivities.size());
|
LOG_DBG("ACT", "Pushed to activity stack, new size = %zu", stackActivities.size());
|
||||||
|
logActivityStackState("push_after", currentActivity.get(), stackActivities.size());
|
||||||
}
|
}
|
||||||
pendingAction = PendingAction::None;
|
pendingAction = PendingAction::None;
|
||||||
currentActivity = std::move(pendingActivity);
|
currentActivity = std::move(pendingActivity);
|
||||||
@@ -201,6 +219,8 @@ void ActivityManager::replaceActivity(std::unique_ptr<Activity>&& newActivity) {
|
|||||||
if (currentActivity) {
|
if (currentActivity) {
|
||||||
// Defer launch if we're currently in an activity, to avoid deleting the current activity
|
// Defer launch if we're currently in an activity, to avoid deleting the current activity
|
||||||
// leading to the "delete this" problem
|
// leading to the "delete this" problem
|
||||||
|
LOG_DBG("ACT", "replaceActivity requested: current=%s stackSize=%zu",
|
||||||
|
currentActivity->getName().c_str(), stackActivities.size());
|
||||||
pendingActivity = std::move(newActivity);
|
pendingActivity = std::move(newActivity);
|
||||||
pendingAction = PendingAction::Replace;
|
pendingAction = PendingAction::Replace;
|
||||||
} else {
|
} else {
|
||||||
@@ -274,6 +294,8 @@ void ActivityManager::pushActivity(std::unique_ptr<Activity>&& activity) {
|
|||||||
LOG_ERR("ACT", "pendingActivity while pushActivity is not expected");
|
LOG_ERR("ACT", "pendingActivity while pushActivity is not expected");
|
||||||
pendingActivity.reset();
|
pendingActivity.reset();
|
||||||
}
|
}
|
||||||
|
LOG_DBG("ACT", "pushActivity requested: current=%s stackSize=%zu",
|
||||||
|
currentActivity ? currentActivity->getName().c_str() : "<none>", stackActivities.size());
|
||||||
pendingActivity = std::move(activity);
|
pendingActivity = std::move(activity);
|
||||||
pendingAction = PendingAction::Push;
|
pendingAction = PendingAction::Push;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user