Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

geogod42
Copy link

Fixes #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.

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`.
@CZDanol CZDanol self-assigned this Jan 10, 2025
@@ -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();
Copy link
Contributor

@CZDanol CZDanol Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Adding a metric is a separate thing from adding a statistics item, it should be in a separate commit
  2. We use snake_case for functions as per https://github.com/prusa3d/Prusa-Firmware-Buddy/blob/master/doc/contributing.md
  3. 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What does this comment stand for?
  2. 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"
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. SetText takes string_view_utf8, you're providing char[]
  2. We have separate fields for "text" and for "value" - putting everything together is not acceptable
  3. This code does not take translations into account
  4. The label should at least also show minutes as well


ScreenMenuStatistics::ScreenMenuStatistics()
: ScreenMenuStatistics__(_(label)) {
EnableLongHoldScreenAction();
header.SetIcon(&img::info_16x16);
AddItem(&uptime_label);
Copy link
Contributor

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.

  1. The menu must be added to the ScreenMenu template as a parameter
  2. AddItem function is nowhere in the firmware
  3. 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);
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BFW-6579] [ENHANCEMENT] Add Uptime to Stats
2 participants