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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
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

}

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);
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.

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
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?

}
}

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"
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?


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

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);
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

}
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;
};