-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add uptime to statistics menu #4397
base: master
Are you sure you want to change the base?
Conversation
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`.
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Adding a metric is a separate thing from adding a statistics item, it should be in a separate commit
- We use
snake_case
for functions as per https://github.com/prusa3d/Prusa-Firmware-Buddy/blob/master/doc/contributing.md - No other metric in the RecordRuntimeStats has a dedicated record function - don't see why this one should
@@ -233,6 +233,7 @@ void app_run(void) { | |||
loop(); | |||
} | |||
marlin_server::loop(); | |||
buddy::metrics::RecordUptime(); // Pa465 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- What does this comment stand for?
- Why do we need to call this function from two places?
@@ -4,11 +4,14 @@ | |||
#include "screen_menu_statistics.hpp" | |||
#include "DialogMoveZ.hpp" | |||
#include "img_resources.hpp" | |||
#include "app_metrics.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we including app_metrics here?
void ScreenMenuStatistics::updateUptime() { | ||
char buffer[32]; | ||
snprintf(buffer, sizeof(buffer), "Uptime: %lu hours", ticks_s() / 3600); | ||
uptime_label.SetText(buffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- SetText takes
string_view_utf8
, you're providing char[] - We have separate fields for "text" and for "value" - putting everything together is not acceptable
- This code does not take translations into account
- The label should at least also show minutes as well
|
||
ScreenMenuStatistics::ScreenMenuStatistics() | ||
: ScreenMenuStatistics__(_(label)) { | ||
EnableLongHoldScreenAction(); | ||
header.SetIcon(&img::info_16x16); | ||
AddItem(&uptime_label); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a valid code for adding menu items in the menu.
- The menu must be added to the
ScreenMenu
template as a parameter - AddItem function is nowhere in the firmware
- Use
MenuItemAutoUpdatingLabel
for an automatically updating label
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "1000" there means that we would be sending the metric every second. I would say that is a bit wasteful.
Fixes #4392
Add uptime to the statistics menu.
RecordUptime
insrc/common/app_metrics.cpp
to record the uptime in hours.RecordRuntimeStats
insrc/common/app_metrics.cpp
to callRecordUptime
.src/common/appmain.cpp
to callRecordUptime
in theapp_run
function.src/gui/screen_menu_statistics.cpp
.src/gui/screen_menu_statistics.hpp
.