From d298c3c6727ac4c39267ccebe6e733c1dcfafc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 9 Mar 2017 15:38:52 +0100 Subject: [PATCH] Apply analysis throttle only every n lines Default n = 100, configurable via config.yaml. Should make analysis a bit faster while still giving the Pi air to breathe. --- src/octoprint/filemanager/analysis.py | 7 +++++-- src/octoprint/settings.py | 3 ++- src/octoprint/util/gcodeInterpreter.py | 10 +++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/octoprint/filemanager/analysis.py b/src/octoprint/filemanager/analysis.py index f0c515b2..a774cc37 100644 --- a/src/octoprint/filemanager/analysis.py +++ b/src/octoprint/filemanager/analysis.py @@ -308,9 +308,12 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue): def _do_analysis(self, high_priority=False): try: throttle = settings().getFloat(["gcodeAnalysis", "throttle_highprio"]) if high_priority else settings().getFloat(["gcodeAnalysis", "throttle_normalprio"]) + throttle_lines = settings().getInt(["gcodeAnalysis", "throttle_lines"]) if throttle > 0: - def throttle_callback(): - time.sleep(throttle) + def throttle_callback(filePos, readBytes): + if filePos % throttle_lines == 0: + # only apply throttle every 100 lines + time.sleep(throttle) else: throttle_callback = None diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 6640bbc1..57c3f49d 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -179,7 +179,8 @@ default_settings = { "gcodeAnalysis": { "maxExtruders": 10, "throttle_normalprio": 0.01, - "throttle_highprio": 0.0 + "throttle_highprio": 0.0, + "throttle_lines": 100 }, "feature": { "temperatureGraph": True, diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index f0548159..ac10954d 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -221,7 +221,7 @@ class gcode(object): self._reenqueue = reenqueue def _load(self, gcodeFile, printer_profile, throttle=None): - filePos = 0 + lineNo = 0 readBytes = 0 pos = Vector3D(0.0, 0.0, 0.0) posOffset = Vector3D(0.0, 0.0, 0.0) @@ -245,18 +245,18 @@ class gcode(object): for line in gcodeFile: if self._abort: raise AnalysisAborted(reenqueue=self._reenqueue) - filePos += 1 + lineNo += 1 readBytes += len(line) if isinstance(gcodeFile, (file)): percentage = float(readBytes) / float(self._fileSize) elif isinstance(gcodeFile, (list)): - percentage = float(filePos) / float(len(gcodeFile)) + percentage = float(lineNo) / float(len(gcodeFile)) else: percentage = None try: - if self.progressCallback is not None and (filePos % 1000 == 0) and percentage is not None: + if self.progressCallback is not None and (lineNo % 1000 == 0) and percentage is not None: self.progressCallback(percentage) except: pass @@ -444,7 +444,7 @@ class gcode(object): totalExtrusion.append(0.0) if throttle is not None: - throttle() + throttle(lineNo, readBytes) if self.progressCallback is not None: self.progressCallback(100.0)