✨ Resend ratio tracking & warning

Implements #3672
This commit is contained in:
Gina Häußge committed 2020-11-05 12:56:05 +01:00
1 parent cb9e5b401f
commit ca62d15aac
10 files changed
+163 -2

No files matched your search

+3
View File
@@ -806,6 +806,9 @@ Use the following settings to configure the serial connection to the printer:
# the response skips on the ok)
triggerOkForM29: true
# Percentage of resend requests among all sent lines that should be considered critical
resendRatioThreshold: 10
capabilities:
# Whether to enable temperature autoreport in the firmware if its support is detected
+45 -2
View File
@@ -144,6 +144,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
on_add_log=self._sendAddLogCallbacks,
on_add_message=self._sendAddMessageCallbacks,
on_get_progress=self._updateProgressDataCallback,
on_get_resends=self._updateResendDataCallback,
)
self._stateMonitor.reset(
state=self._dict(text=self.get_state_string(), flags=self._getStateFlags()),
@@ -163,6 +164,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
),
current_z=None,
offsets=self._dict(),
resends=self._dict(count=0, ratio=0),
)
eventManager().subscribe(
@@ -1145,6 +1147,14 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
printTimeLeftOrigin=printTimeLeftOrigin,
)
def _updateResendDataCallback(self):
if not self._comm:
return self._dict(count=0, ratio=0)
return self._dict(
count=self._comm.received_resends,
ratio=int(self._comm.resend_ratio * 100.0),
)
def _addTemperatureData(self, tools=None, bed=None, chamber=None, custom=None):
if tools is None:
tools = {}
@@ -1586,7 +1596,9 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
eventManager().fire(Events.PRINT_DONE, payload)
self._logger_job.info(
"Print job done - origin: {}, path: {}, owner: {}".format(
payload.get("origin"), payload.get("path"), payload.get("owner")
payload.get("origin"),
payload.get("path"),
payload.get("owner"),
)
)
@@ -1847,6 +1859,7 @@ class StateMonitor(object):
on_add_log=None,
on_add_message=None,
on_get_progress=None,
on_get_resends=None,
):
self._interval = interval
self._update_callback = on_update
@@ -1854,18 +1867,22 @@ class StateMonitor(object):
self._on_add_log = on_add_log
self._on_add_message = on_add_message
self._on_get_progress = on_get_progress
self._on_get_resends = on_get_resends
self._state = None
self._job_data = None
self._current_z = None
self._offsets = {}
self._progress = None
self._resends = None
self._progress_dirty = False
self._resends_dirty = False
self._change_event = threading.Event()
self._state_lock = threading.Lock()
self._progress_lock = threading.Lock()
self._resends_lock = threading.Lock()
self._last_update = monotonic_time()
self._worker = threading.Thread(target=self._work)
@@ -1877,14 +1894,26 @@ class StateMonitor(object):
return self._on_get_progress()
return self._progress
def _get_current_resends(self):
if callable(self._on_get_resends):
return self._on_get_resends()
return self._resends
def reset(
self, state=None, job_data=None, progress=None, current_z=None, offsets=None
self,
state=None,
job_data=None,
progress=None,
current_z=None,
offsets=None,
resends=None,
):
self.set_state(state)
self.set_job_data(job_data)
self.set_progress(progress)
self.set_current_z(current_z)
self.set_temp_offsets(offsets)
self.set_resends(resends)
def add_temperature(self, temperature):
self._on_add_temperature(temperature)
@@ -1892,6 +1921,8 @@ class StateMonitor(object):
def add_log(self, log):
self._on_add_log(log)
with self._resends_lock:
self._resends_dirty = True
self._change_event.set()
def add_message(self, message):
@@ -1922,6 +1953,12 @@ class StateMonitor(object):
self._progress = progress
self._change_event.set()
def set_resends(self, resend_ratio):
with self._resends_lock:
self._resends_dirty = False
self._resends = resend_ratio
self._change_event.set()
def set_temp_offsets(self, offsets):
if offsets is None:
offsets = {}
@@ -1957,12 +1994,18 @@ class StateMonitor(object):
self._progress = self._get_current_progress()
self._progress_dirty = False
with self._resends_lock:
if self._resends_dirty:
self._resends = self._get_current_resends()
self._resends_dirty = False
return {
"state": self._state,
"job": self._job_data,
"currentZ": self._current_z,
"progress": self._progress,
"offsets": self._offsets,
"resends": self._resends,
}
+5
View File
@@ -242,6 +242,7 @@ def getSettings():
"capEmergencyParser": s.getBoolean(
["serial", "capabilities", "emergency_parser"]
),
"resendRatioThreshold": s.getInt(["serial", "resendRatioThreshold"]),
},
"folder": {
"uploads": s.getBaseFolder("uploads"),
@@ -866,6 +867,10 @@ def _saveSettings(data):
["serial", "capabilities", "emergency_parser"],
data["serial"]["capEmergencyParser"],
)
if "resendRatioThreshold" in data["serial"]:
s.setInt(
["serial", "resendRatioThreshold"], data["serial"]["resendRatioThreshold"]
)
oldLog = s.getBoolean(["serial", "log"])
if "log" in data["serial"]:
+1
View File
@@ -168,6 +168,7 @@ default_settings = {
"busy_protocol": True,
"emergency_parser": True,
},
"resendRatioThreshold": 10,
# command specific flags
"triggerOkForM29": True,
},
+7
View File
@@ -428,6 +428,13 @@ function formatSize(bytes) {
return _.sprintf("%.1f%s", bytes, "TB");
}
function formatHuman(number) {
if (number === undefined) return "-";
if (number < 1000) return number;
return _.sprintf("%.1fK", number / 1000);
}
function bytesFromSize(size) {
if (size === undefined || size.trim() === "") return undefined;
@@ -7,6 +7,15 @@ $(function () {
self.access = parameters[2];
self.stateString = ko.observable(undefined);
self.resendCount = ko.observable(0);
self.resendTotalTransmitted = ko.observable(0);
self.resendRatio = ko.observable(0);
self.resendRatioCritical = ko.pureComputed(function () {
return self.resendRatio() >= self.settings.serial_resendRatioThreshold();
});
self.resendRatioNotification = undefined;
self.isErrorOrClosed = ko.observable(undefined);
self.isOperational = ko.observable(undefined);
self.isPrinting = ko.observable(undefined);
@@ -270,6 +279,9 @@ $(function () {
self._processProgressData(data.progress);
self._processZData(data.currentZ);
self._processBusyFiles(data.busyFiles);
self._processResends(data.resends);
self._checkResendRatioCriticality();
};
self._processStateData = function (data) {
@@ -373,6 +385,38 @@ $(function () {
self.busyFiles(busyFiles);
};
self._processResends = function (data) {
self.resendCount(data.count);
self.resendRatio(data.ratio);
};
self._checkResendRatioCriticality = function () {
if (self.resendRatioCritical()) {
if (self.resendRatioNotification === undefined) {
var message = gettext(
"<p>%(ratio)d%% of transmitted lines have triggered resend " +
"requests. The communication with the printer is unreliable " +
"and this will cause print artefacts and failures.</p><p>Please " +
"see <a href='%(url)s' target='_blank'>this FAQ entry</a> " +
"on tips on how to solve this.</p>"
);
message = _.sprintf(message, {
ratio: self.resendRatio(),
url: "https://faq.octoprint.org/communication-errors"
});
self.resendRatioNotification = new PNotify({
title: gettext("Critical resend ratio!"),
text: message,
type: "error",
hide: false
});
}
} else if (self.resendRatioNotification !== undefined) {
self.resendRatioNotification.remove();
self.resendRatioNotification = undefined;
}
};
self.print = function () {
if (self.isPaused()) {
showConfirmationDialog({
@@ -234,6 +234,7 @@ $(function () {
self.serial_sendM112OnError = ko.observable(undefined);
self.serial_disableSdPrintingDetection = ko.observable(undefined);
self.serial_ackMax = ko.observable(undefined);
self.serial_resendRatioThreshold = ko.observable(100);
self.folder_uploads = ko.observable(undefined);
self.folder_timelapse = ko.observable(undefined);
@@ -515,6 +515,18 @@
</div>
</div>
</fieldset>
<fieldset>
<legend>{{ _('Resend Tracking') }}</legend>
<div class="control-group" title="{{ _('Resend ratio threshold. Percentage of resend requests among all sent lines to consider critical.')|edq }}">
<label class="control-label" for="settings-serialResendRatioThreshold">{{ _('Critical resend ratio') }}</label>
<div class="controls">
<div class="input-append">
<input type="number" min="0" max="100" step="1" class="input-mini text-right" id="settings-serialResendRatioThreshold" data-bind="value: serial_resendRatioThreshold">
<span class="add-on">%</span>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</form>
@@ -1,4 +1,5 @@
<span title="{{ _('Current printer state')|edq }}">{{ _('State') }}</span>: <strong data-test-id="state-string" data-bind="text: stateString"></strong><br>
<span data-bind="visible: isOperational"><span title="{{ _('Count of resend requests and resend ratio')|edq }}">{{ _('Resend requests') }}</span>: <strong data-bind="css: {'text-error': resendRatioCritical}"><span title="{{ _('resend requests') | edq }}" data-bind="text: formatHuman(resendCount())"></span> (<span data-bind="text: resendRatio"></span>%) <a href="https://faq.octoprint.org/communication-errors" target="_blank" class="text-error" data-bind="visible: resendRatioCritical"><i class="fas fa-question-circle"></i></a></strong><br></span>
<hr>
<span title="{{ _('Name of file currently selected for printing')|edq }}">{{ _('File') }}</span>: <strong data-bind="text: filedisplay, attr: {title: filepath}"></strong>&nbsp;<strong data-bind="visible: sd">(SD)</strong><br>
<span title="{{ _('Upload date of the file currently selected or printing')|edq }}">{{ _('Uploaded') }}</span>: <strong data-bind="text: dateString"></strong><br>
+44
View File
@@ -662,6 +662,13 @@ class MachineCom(object):
self._job_queue = JobQueue()
self._transmitted_lines = 0
self._received_resend_requests = 0
self._resend_ratio_threshold = (
settings().getInt(["serial", "resendRatioThreshold"]) / 100.0
)
self._resend_ratio_reported = False
# hooks
self._pluginManager = octoprint.plugin.plugin_manager()
@@ -799,6 +806,38 @@ class MachineCom(object):
cap, False
) and self._firmware_capabilities.get(cap, False)
@property
def received_resends(self):
return self._received_resend_requests
@property
def transmitted_lines(self):
return self._transmitted_lines
@property
def resend_ratio(self):
if self._transmitted_lines:
return self._received_resend_requests / self._transmitted_lines
else:
return 0.0
def _reevaluate_resend_ratio(self):
resend_ratio = self.resend_ratio
if (
resend_ratio >= self._resend_ratio_threshold
and not self._resend_ratio_reported
):
message = (
"Over {}% of transmitted lines have triggered resend requests "
"({:.2f}%). The communication with the printers is unreliable. "
"Please see https://faq.octoprint.org/communication-errors.".format(
self._resend_ratio_threshold, resend_ratio
)
)
self._log(message)
self._logger.warning(message)
self._resend_ratio_reported = True
##~~ internal state management
def _changeState(self, newState):
@@ -3929,6 +3968,9 @@ class MachineCom(object):
return False
def _handle_resend_request(self, line):
self._received_resend_requests += 1
self._reevaluate_resend_ratio()
try:
lineToResend = parse_resend_line(line)
if lineToResend is None:
@@ -4707,6 +4749,8 @@ class MachineCom(object):
if passes > 1:
time.sleep((passes - 1) / 10.0)
self._transmitted_lines += 1
##~~ command handlers
## gcode