From 9e42f4fc0ff64e3b3eb070465e8a93b994eded20 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Mon, 21 Jun 2021 02:02:05 +0900 Subject: [PATCH] m1n1.trace: Add a `state` stash to Tracer that persists This allows Tracers to keep internal state around even across complete re-instantiations. Signed-off-by: Hector Martin --- proxyclient/m1n1/trace/__init__.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/proxyclient/m1n1/trace/__init__.py b/proxyclient/m1n1/trace/__init__.py index 2d346ca1..99d59cbf 100644 --- a/proxyclient/m1n1/trace/__init__.py +++ b/proxyclient/m1n1/trace/__init__.py @@ -44,6 +44,9 @@ class RegCache(Reloadable): else: raise Exception("Cannot write register in asynchronous context") +class TracerState: + pass + class Tracer(Reloadable): DEFAULT_MODE = TraceMode.ASYNC @@ -53,10 +56,20 @@ class Tracer(Reloadable): self.ident = type(self).__name__ self.regmaps = {} self.verbose = verbose + self.state = TracerState() + self.init_state() self._cache = RegCache(hv) - if self.ident in hv.tracer_caches: - self._cache.cache = dict(hv.tracer_caches[self.ident]) - hv.tracer_caches[self.ident] = self._cache.cache + cache = hv.tracer_caches.get(self.ident, None) + if cache is not None: + self._cache.cache.update(cache.get("regcache", {})) + self.state.__dict__.update(cache.get("state", {})) + hv.tracer_caches[self.ident] = { + "regcache": self._cache.cache, + "state": self.state.__dict__ + } + + def init_state(self): + pass def evt_rw(self, evt, regmap=None, prefix=None): self._cache.update(evt.addr, evt.data)