diff --git a/src/calng/base_calcat.py b/src/calng/base_calcat.py index 40965e9cdec7744bee23270bb7baa6b62fc1218d..09fce8d3a78f3c971988b9afbea7bfdb6d23915b 100644 --- a/src/calng/base_calcat.py +++ b/src/calng/base_calcat.py @@ -23,6 +23,7 @@ from karabo.bound import ( STRING_ELEMENT, UINT32_ELEMENT, VECTOR_UINT32_ELEMENT, + Unit, ) from . import utils @@ -185,6 +186,15 @@ def add_status_schema_from_enum(schema, enum_class): .reconfigurable() .commit(), + DOUBLE_ELEMENT(schema) + .key(f"{constant_node}.constantLoadingTime") + .displayedName("FS load time") + .unit(Unit.SECOND) + .description("How long it took loading this constant from the file system") + .readOnly() + .initialValue(0) + .commit(), + SLOT_ELEMENT(schema) .key(f"{constant_node}.overrideConstantFromFile") .displayedName("Override from file") @@ -567,9 +577,11 @@ class BaseCalcatFriend: self._set_status(constant, "dataFilePath", str(file_path)) self._set_status(constant, "dataSetName", resp["data"]["data_set_name"]) - constant_data = _read_dataset_externally( - file_path, resp["data"]["data_set_name"] - ) + with utils.Stopwatch() as stopwatch: + constant_data = _read_dataset_externally( + file_path, resp["data"]["data_set_name"] + ) + self._set_status(constant, "constantLoadingTime", stopwatch.elapsed) with self.cached_constants_lock: self.cached_constants[constant] = constant_data @@ -594,9 +606,13 @@ class BaseCalcatFriend: ) self._set_status(constant, "dataFilePath", str(file_path)) self._set_status(constant, "dataSetName", resp["data"]["data_set_name"]) - constant_data = _read_dataset_externally( - file_path, resp["data"]["data_set_name"] - ) + + with utils.Stopwatch() as stopwatch: + constant_data = _read_dataset_externally( + file_path, resp["data"]["data_set_name"] + ) + self._set_status(constant, "constantLoadingTime", stopwatch.elapsed) + with self.cached_constants_lock: self.cached_constants[constant] = constant_data self._set_status(constant, "beginValidityAt", resp["data"]["begin_at"]) @@ -608,10 +624,13 @@ class BaseCalcatFriend: return constant_data def get_constant_from_file(self, constant): - constant_data = _read_dataset_externally( - self.device.get(f"foundConstants.{constant.name}.dataFilePath"), - self.device.get(f"foundConstants.{constant.name}.dataSetName"), - ) + with utils.Stopwatch() as stopwatch: + constant_data = _read_dataset_externally( + self.device.get(f"foundConstants.{constant.name}.dataFilePath"), + self.device.get(f"foundConstants.{constant.name}.dataSetName"), + ) + self._set_status(constant, "constantLoadingTime", stopwatch.elapsed) + with self.cached_constants_lock: self.cached_constants[constant] = constant_data self._set_status(constant, "beginValidityAt", "manual override")