@@ -15,11 +15,15 @@ def __init__(self, proxy: "Proxy", stale: bool):
1515 self .stale = stale
1616
1717
18- class ProxyRegistry :
19- """A helper class managing all proxy variables being tracked and allow for controlled dumps of
18+ class VarRegistry :
19+ """A helper class managing all variables being tracked and allow for controlled dumps of
2020 the variable states.
2121
2222 A variable is uniquely identified by its "name"
23+ When a variable is added to the registry, it is marked as "not stale".
24+ When a variable is dumped through `dump_sample` or `dump_modified`, it is marked as "stale".
25+ A variable is only dumped through `dump_modified` if it is not stale.
26+
2327 """
2428
2529 def __init__ (self ):
@@ -29,20 +33,24 @@ def __init__(self):
2933 def add_var (self , var : "Proxy" , var_name : str ):
3034 """Add a new proxy variable to the registry"""
3135 with self .registry_lock :
32- self .registry [var_name ] = RegistryEntry (proxy = var , stale = False )
36+ if var_name in self .registry :
37+ self .registry [var_name ].proxy = var
38+ self .registry [var_name ].stale = False
39+ else :
40+ self .registry [var_name ] = RegistryEntry (proxy = var , stale = False )
3341
3442 def dump_sample (self , dump_loc = None ):
3543 """A complete dump of all present proxy objects
3644
3745 Calling this API mark all proxy objects as stale which
38- will affect the `dump_only_modified ` API.
46+ will affect the `dump_modified ` API.
3947 """
4048 with self .registry_lock :
41- for var_name , entry in self .registry .items ():
49+ for _ , entry in self .registry .items ():
4250 entry .stale = True
4351 entry .proxy .dump_trace (phase = "sample" , dump_loc = dump_loc )
4452
45- def dump_only_modified (self , dump_loc = None , dump_config = None ):
53+ def dump_modified (self , dump_loc = None , dump_config = None ):
4654 """Dump only the proxy variables that might be modified since last dump
4755
4856 args:
@@ -81,7 +89,7 @@ def dump_only_modified(self, dump_loc=None, dump_config=None):
8189
8290
8391# Global dictionary to store registered objects
84- global_registry = ProxyRegistry ()
92+ global_registry = VarRegistry ()
8593
8694
8795def get_global_registry ():
0 commit comments