1212
1313import abc
1414import logging
15+ import uuid
16+ from typing import Dict , List
17+
18+ from deep .api .tracepoint import TracePointConfig
1519
1620
1721class TracepointConfigService :
1822 """This service deals with new responses from the LongPoll"""
1923
2024 def __init__ (self ) -> None :
25+ self ._custom = []
2126 self ._tracepoint_config = []
2227 self ._current_hash = None
2328 self ._last_update = 0
@@ -43,6 +48,10 @@ def update_new_config(self, ts, new_hash, new_config):
4348 self ._last_update = ts
4449 self ._current_hash = new_hash
4550 self ._tracepoint_config = new_config
51+ self .trigger_update (old_hash , old_config )
52+
53+ def trigger_update (self , old_hash , old_config ):
54+ ts = self ._last_update
4655 if self ._task_handler is not None :
4756 future = self ._task_handler .submit_task (self .update_listeners , self ._last_update , old_hash ,
4857 self ._current_hash , old_config , self ._tracepoint_config )
@@ -57,7 +66,7 @@ def update_listeners(self, ts, old_hash, current_hash, old_config, new_config):
5766 listeners_copy = self ._listeners .copy ()
5867 for listeners in listeners_copy :
5968 try :
60- listeners .config_change (ts , old_hash , current_hash , old_config , new_config )
69+ listeners .config_change (ts , old_hash , current_hash , old_config , new_config + self . _custom )
6170 except Exception :
6271 logging .exception ("Error updating listener %s" , listeners )
6372
@@ -73,6 +82,18 @@ def current_config(self):
7382 def current_hash (self ):
7483 return self ._current_hash
7584
85+ def add_custom (self , path : str , line : int , args : Dict [str , str ], watches : List [str ]) -> TracePointConfig :
86+ config = TracePointConfig (str (uuid .uuid4 ()), path , line , args , watches )
87+ self ._custom .append (config )
88+ self .trigger_update (None , None )
89+ return config
90+
91+ def remove_custom (self , config : TracePointConfig ):
92+ for idx , cfg in enumerate (self ._custom ):
93+ if cfg .id == config .id :
94+ del self ._custom [idx ]
95+ return
96+
7697
7798class ConfigUpdateListener (abc .ABC ):
7899 """
0 commit comments