Reduce debug logging
This commit is contained in:
@@ -10,7 +10,9 @@ void Activity::requestUpdate(bool immediate) { activityManager.requestUpdate(imm
|
||||
|
||||
void Activity::requestUpdateAndWait() { activityManager.requestUpdateAndWait(); }
|
||||
|
||||
void Activity::onGoHome() { activityManager.goHome(); }
|
||||
// "Up and out" — return to whichever parent launched this flow. If no return hint
|
||||
// is set (typical for activities launched via a plain goTo*()), falls back to Home.
|
||||
void Activity::onGoHome() { activityManager.returnFromChild(); }
|
||||
|
||||
void Activity::startActivityForResult(std::unique_ptr<Activity>&& activity, ActivityResultHandler resultHandler) {
|
||||
this->resultHandler = std::move(resultHandler);
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "util/FullScreenMessageActivity.h"
|
||||
#include "weather/WeatherActivity.h"
|
||||
|
||||
#ifndef DEBUG_MEMORY_CONSUMPTION
|
||||
#define DEBUG_MEMORY_CONSUMPTION 0
|
||||
#endif
|
||||
|
||||
void ActivityManager::begin() {
|
||||
xTaskCreate(&renderTaskTrampoline, "ActivityManagerRender",
|
||||
8192, // Stack size
|
||||
@@ -32,12 +36,16 @@ void ActivityManager::begin() {
|
||||
assert(renderTaskHandle != nullptr && "Failed to create render task");
|
||||
}
|
||||
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
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);
|
||||
}
|
||||
#else
|
||||
static inline void logActivityStackState(const char*, Activity*, size_t) {}
|
||||
#endif
|
||||
|
||||
void ActivityManager::renderTaskTrampoline(void* param) {
|
||||
auto* self = static_cast<ActivityManager*>(param);
|
||||
@@ -159,7 +167,9 @@ void ActivityManager::loop() {
|
||||
RenderLock lock;
|
||||
|
||||
if (pendingAction == PendingAction::Replace) {
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
logActivityStackState("replace_before", currentActivity.get(), stackActivities.size());
|
||||
#endif
|
||||
// Destroy the current activity
|
||||
exitActivity(lock);
|
||||
// Clear the stack
|
||||
@@ -167,13 +177,21 @@ void ActivityManager::loop() {
|
||||
stackActivities.back()->onExit();
|
||||
stackActivities.pop_back();
|
||||
}
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
logActivityStackState("replace_after_clear", nullptr, stackActivities.size());
|
||||
#endif
|
||||
} else if (pendingAction == PendingAction::Push) {
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
logActivityStackState("push_before", currentActivity.get(), stackActivities.size());
|
||||
#endif
|
||||
// Move current activity to stack
|
||||
stackActivities.push_back(std::move(currentActivity));
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
LOG_DBG("ACT", "Pushed to activity stack, new size = %zu", stackActivities.size());
|
||||
logActivityStackState("push_after", currentActivity.get(), stackActivities.size());
|
||||
#else
|
||||
LOG_DBG("ACT", "Pushed to activity stack, new size = %zu", stackActivities.size());
|
||||
#endif
|
||||
}
|
||||
pendingAction = PendingAction::None;
|
||||
currentActivity = std::move(pendingActivity);
|
||||
@@ -215,8 +233,10 @@ void ActivityManager::replaceActivity(std::unique_ptr<Activity>&& newActivity) {
|
||||
if (currentActivity) {
|
||||
// Defer launch if we're currently in an activity, to avoid deleting the current activity
|
||||
// leading to the "delete this" problem
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
LOG_DBG("ACT", "replaceActivity requested: current=%s stackSize=%zu", currentActivity->getName().c_str(),
|
||||
stackActivities.size());
|
||||
#endif
|
||||
pendingActivity = std::move(newActivity);
|
||||
pendingAction = PendingAction::Replace;
|
||||
} else {
|
||||
@@ -233,12 +253,10 @@ void ActivityManager::goToFileTransfer() {
|
||||
void ActivityManager::goToSettings() { replaceActivity(std::make_unique<SettingsActivity>(renderer, mappedInput)); }
|
||||
|
||||
void ActivityManager::goToFileBrowser(std::string path, std::string focusName) {
|
||||
hasReturnHint = false;
|
||||
replaceActivity(std::make_unique<FileBrowserActivity>(renderer, mappedInput, std::move(path), std::move(focusName)));
|
||||
}
|
||||
|
||||
void ActivityManager::goToRecentBooks(int focusIndex) {
|
||||
hasReturnHint = false;
|
||||
replaceActivity(std::make_unique<RecentBooksActivity>(renderer, mappedInput, focusIndex));
|
||||
}
|
||||
|
||||
@@ -303,7 +321,7 @@ void ActivityManager::returnFromChild() {
|
||||
break;
|
||||
case ReturnTo::Home:
|
||||
default:
|
||||
goHome(std::move(hint.selectName));
|
||||
goHome(std::move(hint.selectName), hint.selectIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -321,9 +339,9 @@ void ActivityManager::goToFullScreenMessage(std::string message, EpdFontFamily::
|
||||
|
||||
void ActivityManager::goToWeather() { replaceActivity(std::make_unique<WeatherActivity>(renderer, mappedInput)); }
|
||||
|
||||
void ActivityManager::goHome(std::string focusBookPath) {
|
||||
void ActivityManager::goHome(std::string focusBookPath, int focusSelectorIndex) {
|
||||
hasReturnHint = false;
|
||||
replaceActivity(std::make_unique<HomeActivity>(renderer, mappedInput, std::move(focusBookPath)));
|
||||
replaceActivity(std::make_unique<HomeActivity>(renderer, mappedInput, std::move(focusBookPath), focusSelectorIndex));
|
||||
}
|
||||
|
||||
void ActivityManager::pushActivity(std::unique_ptr<Activity>&& activity) {
|
||||
@@ -332,8 +350,10 @@ void ActivityManager::pushActivity(std::unique_ptr<Activity>&& activity) {
|
||||
LOG_ERR("ACT", "pendingActivity while pushActivity is not expected");
|
||||
pendingActivity.reset();
|
||||
}
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
LOG_DBG("ACT", "pushActivity requested: current=%s stackSize=%zu",
|
||||
currentActivity ? currentActivity->getName().c_str() : "<none>", stackActivities.size());
|
||||
#endif
|
||||
pendingActivity = std::move(activity);
|
||||
pendingAction = PendingAction::Push;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class ActivityManager {
|
||||
void goToBoot();
|
||||
void goToFullScreenMessage(std::string message, EpdFontFamily::Style style = EpdFontFamily::REGULAR);
|
||||
void goToWeather();
|
||||
void goHome(std::string focusBookPath = {});
|
||||
void goHome(std::string focusBookPath = {}, int focusSelectorIndex = -1);
|
||||
|
||||
// Replace-with-hint helpers: destroy the current activity before launching the new
|
||||
// one (freeing its memory) and record where to route control when the new activity
|
||||
@@ -130,6 +130,19 @@ class ActivityManager {
|
||||
// no hint is set, defaults to goHome().
|
||||
void returnFromChild();
|
||||
|
||||
// Record a ReturnHint before calling any plain goTo*() helper. Allows an activity
|
||||
// (e.g. Home) to declare "when this flow ends, come back here with this state" for
|
||||
// transitions where we don't want a dedicated replaceWith*() wrapper.
|
||||
// Cleared by returnFromChild() or by an explicit goHome()/replaceWith*() call.
|
||||
void setReturnHint(ReturnHint hint) {
|
||||
returnHint = std::move(hint);
|
||||
hasReturnHint = true;
|
||||
}
|
||||
void clearReturnHint() {
|
||||
returnHint = {};
|
||||
hasReturnHint = false;
|
||||
}
|
||||
|
||||
// This will move current activity to stack instead of deleting it
|
||||
void pushActivity(std::unique_ptr<Activity>&& activity);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <Utf8.h>
|
||||
#include <Xtc.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
@@ -211,15 +212,27 @@ void HomeActivity::onEnter() {
|
||||
recentsLoaded = true;
|
||||
}
|
||||
|
||||
// Apply focus: book path takes priority, else combined selector index (covers
|
||||
// "return to the menu entry I was on").
|
||||
bool focused = false;
|
||||
if (!focusBookPath.empty()) {
|
||||
for (size_t i = 0; i < recentBooks.size(); ++i) {
|
||||
if (recentBooks[i].path == focusBookPath) {
|
||||
selectorIndex = static_cast<int>(i);
|
||||
focused = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
focusBookPath.clear();
|
||||
}
|
||||
if (!focused && focusSelectorIndex >= 0) {
|
||||
rebuildMenuEntries(); // need menu count to clamp; rebuild is idempotent
|
||||
const int combinedSize = static_cast<int>(recentBooks.size() + menuEntries.size());
|
||||
if (combinedSize > 0) {
|
||||
selectorIndex = std::min(focusSelectorIndex, combinedSize - 1);
|
||||
}
|
||||
}
|
||||
focusSelectorIndex = -1;
|
||||
|
||||
// Trigger first update
|
||||
menuEntriesDirty = true;
|
||||
@@ -366,6 +379,13 @@ void HomeActivity::onSelectBook(const std::string& path) {
|
||||
}
|
||||
|
||||
void HomeActivity::dispatchMenuAction(MenuAction action) {
|
||||
// Record where the menu entry was focused so that when the launched activity exits
|
||||
// (via returnFromChild() or an empty-stack finish()), we come back to the same row.
|
||||
ReturnHint hint;
|
||||
hint.target = ReturnTo::Home;
|
||||
hint.selectIndex = selectorIndex;
|
||||
activityManager.setReturnHint(std::move(hint));
|
||||
|
||||
switch (action) {
|
||||
case MenuAction::FileBrowser:
|
||||
activityManager.goToFileBrowser();
|
||||
|
||||
@@ -44,7 +44,8 @@ class HomeActivity final : public Activity {
|
||||
std::vector<MenuEntry> menuEntries;
|
||||
bool menuEntriesDirty = true;
|
||||
|
||||
std::string focusBookPath; // book path to re-select on first render, if present in recents
|
||||
std::string focusBookPath; // book path to re-select on first render, if present in recents
|
||||
int focusSelectorIndex = -1; // fallback combined-selector index when focusBookPath doesn't match
|
||||
|
||||
void onSelectBook(const std::string& path);
|
||||
void dispatchMenuAction(MenuAction action);
|
||||
@@ -57,8 +58,11 @@ class HomeActivity final : public Activity {
|
||||
void loadRecentCovers(int coverHeight);
|
||||
|
||||
public:
|
||||
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string focusBookPath = {})
|
||||
: Activity("Home", renderer, mappedInput), focusBookPath(std::move(focusBookPath)) {}
|
||||
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string focusBookPath = {},
|
||||
int focusSelectorIndex = -1)
|
||||
: Activity("Home", renderer, mappedInput),
|
||||
focusBookPath(std::move(focusBookPath)),
|
||||
focusSelectorIndex(focusSelectorIndex) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#ifndef DEBUG_MEMORY_CONSUMPTION
|
||||
#define DEBUG_MEMORY_CONSUMPTION 0
|
||||
#endif
|
||||
|
||||
#include "EpubReaderActivity.h"
|
||||
|
||||
#include <Epub/Page.h>
|
||||
@@ -35,11 +39,15 @@ constexpr unsigned long skipChapterMs = 700;
|
||||
// pages per minute, first item is 1 to prevent division by zero if accessed
|
||||
constexpr int PAGE_TURN_LABELS[] = {1, 1, 3, 6, 12};
|
||||
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
void logReaderMemSnapshot(const char* stage) {
|
||||
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("ERS", "Reader mem[%s]: free=%lu contig=%lu", stage, freeHeap, contigHeap);
|
||||
}
|
||||
#else
|
||||
inline void logReaderMemSnapshot(const char*) {}
|
||||
#endif
|
||||
|
||||
bool writeReaderProgressCache(const std::string& cachePath, const int spineIndex, const int currentPage,
|
||||
const int pageCount) {
|
||||
|
||||
@@ -20,12 +20,20 @@
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
#ifndef DEBUG_MEMORY_CONSUMPTION
|
||||
#define DEBUG_MEMORY_CONSUMPTION 0
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
#if DEBUG_MEMORY_CONSUMPTION
|
||||
void logReaderLaunchMemSnapshot(const char* stage) {
|
||||
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("READER", "Reader mem[%s]: free=%lu contig=%lu", stage, freeHeap, contigHeap);
|
||||
}
|
||||
#else
|
||||
inline void logReaderLaunchMemSnapshot(const char*) {}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
std::string ReaderActivity::extractFolderPath(const std::string& filePath) {
|
||||
|
||||
Reference in New Issue
Block a user