Skip to content

Commit 43c26b5

Browse files
committed
feat: integrate pyinstrument for performance profiling in WebRTC example
1 parent 69ac841 commit 43c26b5

File tree

3 files changed

+1934
-3932
lines changed

3 files changed

+1934
-3932
lines changed

examples/other_examples/openai_realtime_webrtc/openai_realtime_example.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from uuid import uuid4
1212

1313
from dotenv import load_dotenv
14+
import pyinstrument
1415

1516
from vision_agents.plugins import openai, getstream
1617
from vision_agents.core.agents import Agent
@@ -23,6 +24,8 @@
2324

2425

2526
async def start_agent() -> None:
27+
profiler = pyinstrument.Profiler()
28+
profiler.start()
2629
# Set the call ID here to be used in the logging
2730
call_id = str(uuid4())
2831

@@ -72,6 +75,10 @@ async def start_agent() -> None:
7275

7376
await agent.finish() # run till the call ends
7477

78+
profiler.stop()
79+
with open('profiled.html', 'w') as f:
80+
f.write(profiler.output_html())
81+
7582

7683
if __name__ == "__main__":
7784
asyncio.run(start_agent())

examples/other_examples/openai_realtime_webrtc/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies = [
1010
"asyncio",
1111
"aiortc",
1212
"openai",
13+
"pyinstrument>=5.1.1",
1314
]
1415

1516
[tool.uv.sources]

0 commit comments

Comments
 (0)