# On-demand runtime profiler to monitor Ray function call duration

**URL:** <https://discuss.ray.io/t/on-demand-runtime-profiler-to-monitor-ray-function-call-duration/23466>\
**Category:** RLlib\
**Created:** [February 5, 2026, 1:02am UTC](https://discuss.ray.io/t/on-demand-runtime-profiler-to-monitor-ray-function-call-duration/23466 "2026-02-05T01:02:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cloudy](https://avatars.discourse-cdn.com/v4/letter/c/ea5d25/32.png) [@cloudy](https://discuss.ray.io/u/cloudy)\
**Post date:** [February 5, 2026, 1:02am UTC](https://discuss.ray.io/t/on-demand-runtime-profiler-to-monitor-ray-function-call-duration/23466/1 "2026-02-05T01:02:04Z")

</div>

Hi, I would like to know ray offers a way to create an on-demand profiler to monitor function call durations in Ray. It can be toggled on and off during runtime.

---

<div class="post-metadata">

**Author:** ![RunLLM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/runllm/32/8249_2.png) [@RunLLM](https://discuss.ray.io/u/RunLLM)\
**Post date:** [February 5, 2026, 1:02am UTC](https://discuss.ray.io/t/on-demand-runtime-profiler-to-monitor-ray-function-call-duration/23466/2 "2026-02-05T01:02:28Z")

</div>

Ray does not provide a built-in, public API for an on-demand profiler that can be toggled at runtime to monitor function call durations. However, you can use the Ray Dashboard to profile worker processes on demand (e.g., via “Stack Trace” or “CPU Flame Graph” actions), but this is done through the web UI, not programmatically within your code. For code-level profiling, you can use Python’s cProfile or Ray’s private profiling API, but toggling profiling on/off at runtime is not natively supported as a public feature. The private API (`ray._private.profiling.profile`) can be used as a context manager, but it is not guaranteed to be stable and may be deprecated without warning in future releases. See [Ray Dashboard profiling guide](https://github.com/ray-project/ray/blob/releases/2.50.1/doc/source/ray-observability/user-guides/debug-apps/optimize-performance.rst) and [discussion on custom events](https://discuss.ray.io/t/ray-timeline-custom-events/7399).

Would you like more detail or code examples for using cProfile or the private profiling API?

Sources:

- [Ray Dashboard profiling guide](https://github.com/ray-project/ray/blob/releases/2.50.1/doc/source/ray-observability/user-guides/debug-apps/optimize-performance.rst)
- [Ray Timeline custom events discussion](https://discuss.ray.io/t/ray-timeline-custom-events/7399)
- [ray.\_private.profiling.py (private API)](https://github.com/ray-project/ray/blob/master/python/ray/_private/profiling.py)

Hint: Mention @RunLLM in the post for followups.
