diff --git a/src/components/modbus_component.py b/src/components/modbus_component.py index 20618f3..55b89fe 100644 --- a/src/components/modbus_component.py +++ b/src/components/modbus_component.py @@ -14,12 +14,6 @@ else: from .component import Component -# from pymodbus.client.sync import ModbusSerialClient as ModbusClient -# import serial -# client = ModbusClient(method="rtu", port="COM3", stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, baudrate=115200, timeout=1, strict=False) -# client.connect() -# client.read_holding_registers(1, count=1) - class ModbusComponent(Component): def __init__(self, config=None, name=None, period=1, lazy=True, paused=False, threaded=True, registers=None): diff --git a/src/components/tecna_marposs_provaset_t3_registers.py b/src/components/tecna_marposs_provaset_t3_registers.py index 3b66ed3..08d22f5 100644 --- a/src/components/tecna_marposs_provaset_t3_registers.py +++ b/src/components/tecna_marposs_provaset_t3_registers.py @@ -81,7 +81,7 @@ registers = { 2: "BLOCKAGE TEST", 3: "LEAK TEST WITH VOLUME CHECK", 4: "BURST TEST", - },}], + }, }], "Testing in progress: progressive sequence index": [48, {"dt": "16bit_uint", }], "Testing in progress: graphical sampling rate": [49, {"dt": "16bit_uint", }], "Testing in progress: number of samples of the graph": [50, {"dt": "16bit_uint", }], diff --git a/src/main.py b/src/main.py index d2efd41..4fec119 100644 --- a/src/main.py +++ b/src/main.py @@ -12,6 +12,7 @@ from pathlib import Path app = None + def quit_app(signalnum=None, handler=None): logging.info(f"quitting app. signal: {signalnum!r}, handler: {handler!r}") global app @@ -51,10 +52,9 @@ logging.basicConfig( try: # IMPORT PROJECT ONLY AFTER SETTING UP SIGNAL, FAULTHANDLER AND LOGGHING - from components import (ArchiveSynchronizer, NeoPixels, - Os_Label_Printer, RemoteAPI, - TecnaMarpossProvasetT3, TestComponent, Vision, - VisionSaver) + from components import (ArchiveSynchronizer, NeoPixels, Os_Label_Printer, + RemoteAPI, TecnaMarpossProvasetT3, TestComponent, + Vision, VisionSaver) from lib.db import Users from lib.helpers import ConfigReader from PyQt5.QtCore import QObject, QThread, pyqtSignal diff --git a/src/test/chart_memory_usage.py b/src/test/chart_memory_usage.py new file mode 100755 index 0000000..1d53d92 --- /dev/null +++ b/src/test/chart_memory_usage.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +import sys +import traceback +from time import perf_counter + +import pyqtgraph as pg +from pyqtgraph.Qt.QtCore import QTimer +from pyqtgraph.Qt.QtWidgets import QApplication, QGridLayout, QWidget + +interval_ms = 250 +statm_index = 0 # use 5 to limit showing size of data + stack + + +class App(QWidget): + def __init__(self): + super().__init__() + # GUI SETUP + self.layout = QGridLayout() + self.setLayout(self.layout) + # CHART SETUP + self.plot_widget = pg.PlotWidget() + self.plot_widget.enableAutoRange() + self.layout.addWidget(self.plot_widget) + self.plot_data = {"time": [], "size": []} + self.plot = self.plot_widget.plot(*self.plot_data.values()) + # print(self.plot) + # self.plot_widget.addItem(self.plot) + # DATA SETUP + self.pid = sys.argv[1] + self.statm_file = f"/proc/{self.pid}/statm" + # PERIODIC SETUP + self.timer = QTimer() + # self.timer.setSingleShot(True) + self.timer.setInterval(interval_ms) + self.timer.timeout.connect(self.add_data) + self.start = perf_counter() + self.timer.start() + + def add_data(self): + try: + with open(self.statm_file, "r") as f: + statm = f.read() + self.plot_data["time"].append(perf_counter() - self.start) + statm = statm.split() + self.plot_data["size"].append(int(statm[statm_index])) + self.plot.setData(*self.plot_data.values()) + except Exception: + traceback.print_exc() + self.timer.start() + + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = App() + window.show() + sys.exit(app.exec_())