Skip to content

Commit

Permalink
Add uptime to statistics menu
Browse files Browse the repository at this point in the history
Fixes prusa3d#4392

Add uptime to the statistics menu.

* Add a new function `RecordUptime` in `src/common/app_metrics.cpp` to record the uptime in hours.
* Modify `RecordRuntimeStats` in `src/common/app_metrics.cpp` to call `RecordUptime`.
* Update `src/common/appmain.cpp` to call `RecordUptime` in the `app_run` function.
* Add a new line to display the uptime in hours in the statistics menu in `src/gui/screen_menu_statistics.cpp`.
* Add a new member variable to store the uptime and a new method to update the uptime in `src/gui/screen_menu_statistics.hpp`.
  • Loading branch information
geogod42 committed Jan 10, 2025
1 parent 8978fe1 commit 7f288c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/common/app_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ void buddy::metrics::RecordRuntimeStats() {

METRIC_DEF(heap, "heap", METRIC_VALUE_CUSTOM, 503, METRIC_HANDLER_ENABLE_ALL);
metric_record_custom(&heap, " free=%zui,total=%zui", xPortGetFreeHeapSize(), static_cast<size_t>(heap_total_size));

RecordUptime();
}

void buddy::metrics::RecordMarlinVariables() {
Expand Down Expand Up @@ -352,4 +354,9 @@ void buddy::metrics::record_dwarf_internal_temperatures() {
}
}
}

void buddy::metrics::RecordUptime() {
METRIC_DEF(uptime, "uptime", METRIC_VALUE_INTEGER, 1000, METRIC_HANDLER_ENABLE_ALL);
metric_record_integer(&uptime, ticks_s() / 3600);
}
#endif
1 change: 1 addition & 0 deletions src/common/appmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void app_run(void) {
loop();
}
marlin_server::loop();
buddy::metrics::RecordUptime(); // Pa465
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/gui/screen_menu_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
#include "screen_menu_statistics.hpp"
#include "DialogMoveZ.hpp"
#include "img_resources.hpp"
#include "app_metrics.h"

ScreenMenuStatistics::ScreenMenuStatistics()
: ScreenMenuStatistics__(_(label)) {
EnableLongHoldScreenAction();
header.SetIcon(&img::info_16x16);
AddItem(&uptime_label);
updateUptime();
}

void ScreenMenuStatistics::windowEvent(window_t *sender, GUI_event_t event, void *param) {
Expand All @@ -19,3 +22,9 @@ void ScreenMenuStatistics::windowEvent(window_t *sender, GUI_event_t event, void

ScreenMenu::windowEvent(sender, event, param);
}

void ScreenMenuStatistics::updateUptime() {
char buffer[32];
snprintf(buffer, sizeof(buffer), "Uptime: %lu hours", ticks_s() / 3600);
uptime_label.SetText(buffer);
}
2 changes: 2 additions & 0 deletions src/gui/screen_menu_statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ class ScreenMenuStatistics : public ScreenMenuStatistics__ {

private:
virtual void windowEvent(window_t *sender, GUI_event_t event, void *param) override;
void updateUptime();
IWindowMenuItem uptime_label;
};

0 comments on commit 7f288c0

Please sign in to comment.