From: Sebastien Bourdeauducq Date: Fri, 6 Jul 2012 21:36:23 +0000 (+0200) Subject: flow/perftools: refactor to use hooks X-Git-Tag: 24jan2021_ls180~2099^2~873 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=518501c493d850f3bcfaa3d2b911cfb00eb3ffc4;p=litex.git flow/perftools: refactor to use hooks --- diff --git a/migen/flow/perftools.py b/migen/flow/perftools.py index f5199bad..0deca307 100644 --- a/migen/flow/perftools.py +++ b/migen/flow/perftools.py @@ -1,10 +1,8 @@ -from migen.fhdl.structure import * -from migen.flow.actor import * -from migen.sim.generic import PureSimulable +from migen.flow.hooks import * -class EndpointReporter(PureSimulable): +class EndpointReporter(EndpointHook): def __init__(self, endpoint): - self.endpoint = endpoint + super().__init__(endpoint) self.reset() def reset(self): @@ -30,35 +28,19 @@ class EndpointReporter(PureSimulable): else: return "N/A" - def do_simulation(self, s): - if s.rd(self.endpoint.stb): - if s.rd(self.endpoint.ack): - self.ack += 1 - else: - self.nack += 1 - else: - self.inactive += 1 + def on_ack(self): + self.ack += 1 + + def on_nack(self): + self.nack += 1 + + def on_inactive(self): + self.inactive += 1 -class DFGReporter: +class DFGReporter(DFGHook): def __init__(self, dfg): - assert(not dfg.is_abstract()) - self.nodepair_to_ep = dict() - for u, v, data in dfg.edges_iter(data=True): - if (u, v) in self.nodepair_to_ep: - ep_to_reporter = self.nodepair_to_ep[(u, v)] - else: - ep_to_reporter = dict() - self.nodepair_to_ep[(u, v)] = ep_to_reporter - ep = data["source"] - ep_to_reporter[ep] = EndpointReporter(u.actor.endpoints[ep]) - - def get_fragment(self): - frag = Fragment() - for v1 in self.nodepair_to_ep.values(): - for v2 in v1.values(): - frag += v2.get_fragment() - return frag - + super().__init__(dfg, lambda u, ep, v: EndpointReporter(u.actor.endpoints[ep])) + def get_edge_labels(self): d = dict() for (u, v), eps in self.nodepair_to_ep.items():