diff --git a/python/ray/_raylet.pyx b/python/ray/_raylet.pyx index 695fe0b93..654a7a538 100644 --- a/python/ray/_raylet.pyx +++ b/python/ray/_raylet.pyx @@ -697,6 +697,14 @@ cdef void terminate_asyncio_thread() nogil: core_worker.destroy_event_loop_if_exists() +# An empty profile event context to be used when the timeline is disabled. +cdef class EmptyProfileEvent: + def __enter__(self): + pass + + def __exit__(self, *args): + pass + cdef class CoreWorker: def __cinit__(self, worker_type, store_socket, raylet_socket, @@ -1172,9 +1180,12 @@ cdef class CoreWorker: return resources_dict def profile_event(self, c_string event_type, object extra_data=None): - return ProfileEvent.make( - CCoreWorkerProcess.GetCoreWorker().CreateProfileEvent(event_type), - extra_data) + if RayConfig.instance().enable_timeline(): + return ProfileEvent.make( + CCoreWorkerProcess.GetCoreWorker().CreateProfileEvent( + event_type), extra_data) + else: + return EmptyProfileEvent() def remove_actor_handle_reference(self, ActorID actor_id): cdef: diff --git a/python/ray/includes/ray_config.pxd b/python/ray/includes/ray_config.pxd index 13eb9c6f7..8748449b9 100644 --- a/python/ray/includes/ray_config.pxd +++ b/python/ray/includes/ray_config.pxd @@ -64,3 +64,5 @@ cdef extern from "ray/common/ray_config.h" nogil: uint32_t max_tasks_in_flight_per_worker() const uint64_t metrics_report_interval_ms() const + + c_bool enable_timeline() const diff --git a/python/ray/includes/ray_config.pxi b/python/ray/includes/ray_config.pxi index 25bd1a240..5aac8994a 100644 --- a/python/ray/includes/ray_config.pxi +++ b/python/ray/includes/ray_config.pxi @@ -111,3 +111,7 @@ cdef class Config: @staticmethod def metrics_report_interval_ms(): return RayConfig.instance().metrics_report_interval_ms() + + @staticmethod + def enable_timeline(): + return RayConfig.instance().enable_timeline() diff --git a/src/ray/common/ray_config_def.h b/src/ray/common/ray_config_def.h index e643daef9..08280b9b6 100644 --- a/src/ray/common/ray_config_def.h +++ b/src/ray/common/ray_config_def.h @@ -294,3 +294,7 @@ RAY_CONFIG(uint64_t, metrics_report_interval_ms, 10000) /// The maximum number of I/O worker that raylet starts. RAY_CONFIG(int, max_io_workers, 1) + +/// Enable the task timeline. If this is enabled, certain events such as task +/// execution are profiled and sent to the GCS. +RAY_CONFIG(bool, enable_timeline, true)