33from numbers import Number
44from functools import wraps
55from typing import Any , Callable , List , Type , Union , TypeVar
6- from hwcomponents ._logging import ListLoggable
6+ from hwcomponents ._logging import ListLoggable , pop_all_messages
77from hwcomponents ._util import parse_float
88
99T = TypeVar ("T" , bound = "ComponentModel" )
@@ -52,10 +52,15 @@ def action(
5252
5353 @wraps (func )
5454 def wrapper (self : "ComponentModel" , * args , ** kwargs ):
55+ self .logger .info ("" )
56+ self .logger .info (
57+ f"Calling action { self .__class__ .__name__ } .{ func .__name__ } with arguments { args } and { kwargs } "
58+ )
5559 for subcomponent in self .subcomponents :
5660 subcomponent ._energy_used = 0
5761 subcomponent ._latency_used = 0
5862 scale = 1
63+ scalestr = None
5964 if bits_per_action is not None and "bits_per_action" in kwargs :
6065 nominal_bits = None
6166 try :
@@ -69,6 +74,7 @@ def wrapper(self: "ComponentModel", *args, **kwargs):
6974 f"are defined in the class."
7075 )
7176 scale = kwargs ["bits_per_action" ] / nominal_bits
77+ scalestr = f"Scaling by { kwargs ['bits_per_action' ]= } / { nominal_bits = } "
7278 kwargs = {k : v for k , v in kwargs .items () if k not in additional_kwargs }
7379 returned_value = func (self , * args , ** kwargs )
7480 # Normalize return to (energy, latency)
@@ -89,21 +95,48 @@ def wrapper(self: "ComponentModel", *args, **kwargs):
8995 f"Expected a tuple of (energy, latency), got { returned_value } ."
9096 )
9197
98+ self .logger .info (
99+ f"Function { func .__name__ } returned energy { energy_val } and latency { latency_val } "
100+ )
101+ if scalestr is not None :
102+ self .logger .info (scalestr )
103+
92104 energy_val *= self .energy_scale
105+ if self .energy_scale != 1 :
106+ self .logger .info (f"Scaling energy by { self .energy_scale = } " )
93107 for subcomponent in self .subcomponents :
108+ self .logger .info (
109+ f"Adding subcomponent { subcomponent .__class__ .__name__ } energy { subcomponent ._energy_used } "
110+ )
94111 energy_val += subcomponent ._energy_used
95112 subcomponent ._energy_used = 0
96113 energy_val *= scale
97114 self ._energy_used += energy_val
98115
99116 latency_val *= self .latency_scale
117+ if self .latency_scale != 1 :
118+ self .logger .info (f"Scaling latency by { self .latency_scale = } " )
100119 target_func = max if pipelined_subcomponents else sum
120+ x = "Max" if pipelined_subcomponents else "Summ"
101121 for subcomponent in self .subcomponents :
122+ self .logger .info (
123+ f"{ x } ing subcomponent { subcomponent .__class__ .__name__ } latency { subcomponent ._latency_used } "
124+ )
102125 latency_val = target_func ((latency_val , subcomponent ._latency_used ))
103126 subcomponent ._latency_used = 0
104127 latency_val *= scale
105128 self ._latency_used += latency_val
106129
130+ for subcomponent in self .subcomponents :
131+ self .logger .info (f"Log for subcomponent { subcomponent .__class__ .__name__ } :" )
132+ for message in pop_all_messages (subcomponent .logger ):
133+ if message :
134+ self .logger .info (f"\t { message } " )
135+
136+ self .logger .info (
137+ f"** Final return value for { self .__class__ .__name__ } .{ func .__name__ } : energy { energy_val } and latency { latency_val } "
138+ )
139+
107140 return energy_val , latency_val
108141
109142 wrapper ._is_component_action = True
@@ -544,4 +577,4 @@ def resolve_multiple_ways_to_calculate_value(
544577 + "\n \t " .join (f"{ fname } : { value } " for fname , value in success_values )
545578 )
546579
547- return next (iter (values ))
580+ return next (iter (values ))
0 commit comments