File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
agents-core/vision_agents/core/profiling Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 88
99
1010class Profiler :
11+ """Profiles agent execution using pyinstrument and generates an HTML report.
12+
13+ The profiler automatically starts when instantiated and stops when the agent
14+ finishes (on AgentFinishEvent), saving an HTML performance report to disk.
15+
16+ Example:
17+ agent = Agent(
18+ edge=getstream.Edge(),
19+ agent_user=User(name="Agent", id="agent"),
20+ llm=gemini.LLM("gemini-2.0-flash"),
21+ profiler=Profiler(output_path='./profile.html'),
22+ )
23+ """
24+
1125 def __init__ (self , output_path = './profile.html' ):
26+ """Initialize the profiler.
27+
28+ Args:
29+ output_path: Path where the HTML profile report will be saved.
30+ Defaults to './profile.html'.
31+ """
1232 self .output_path = output_path
1333 self .events = EventManager ()
1434 self .events .register_events_from_module (events )
@@ -17,6 +37,11 @@ def __init__(self, output_path='./profile.html'):
1737 self .events .subscribe (self .on_finish )
1838
1939 async def on_finish (self , event : events .AgentFinishEvent ):
40+ """Handle agent finish event by stopping profiler and saving report.
41+
42+ Args:
43+ event: The AgentFinishEvent emitted when the agent finishes.
44+ """
2045 self .profiler .stop ()
2146 logger .info (f"Profiler stopped. Time file saved at: { self .output_path } " )
2247 with open (self .output_path , 'w' ) as f :
You can’t perform that action at this time.
0 commit comments