from . import CustomInstruction class IncrementCustomMetric(CustomInstruction): """ IncrementCustomMetric() increments a custom metric params for the equivalent function call: - custom metric id """ def __init__(self, call_operation): super().__init__(call_operation) self.metric_id = self.get_arg(0) if not self._vmstate.custom_metrics.exists(self.metric_id): raise Exception(f"Metric #{self.metric_id} not found") self.val = int(self.get_arg(1)) if len(self.args) > 1 else 1 name = self._vmstate.custom_metrics.get_name(self.metric_id) self._str_params = [name, self.val] def run(self, update_program_counter=True): super().run(update_program_counter) self._vmstate.custom_metrics.increment(self.metric_id, self.val)