Skip to content

Commit 592faf4

Browse files
committed
docs: enhance Profiler class with detailed docstrings for initialization and event handling
1 parent 903d016 commit 592faf4

File tree

1 file changed

+25
-0
lines changed
  • agents-core/vision_agents/core/profiling

1 file changed

+25
-0
lines changed

agents-core/vision_agents/core/profiling/base.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,27 @@
88

99

1010
class 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:

0 commit comments

Comments
 (0)