mirror of
https://github.com/wassname/ray.git
synced 2026-07-07 21:50:14 +08:00
Move profiling to c++ (#5771)
* Move profiling to c++ * comments * Fix tests * Start after constructor * fix comment * always init logging * Fix logging * fix logging issue * shared_ptr for profiler * DEBUG -> WARNING * fix killed_ init * Fix flaky checkpointing tests * Fix checkpoint test logic * Fix exception matching * timeout exception * Fix import * fix build * use boost::asio * fix double const * Properly reset async_wait * remove SIGINT * Change error message * increase timeout * small nits * Don't trap on SIGINT * -v for tune * Fix test
This commit is contained in:
@@ -16,6 +16,25 @@ from ray.includes.unique_ids cimport (
|
||||
)
|
||||
|
||||
|
||||
cdef extern from * namespace "polyfill":
|
||||
"""
|
||||
namespace polyfill {
|
||||
|
||||
template <typename T>
|
||||
inline typename std::remove_reference<T>::type&& move(T& t) {
|
||||
return std::move(t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename std::remove_reference<T>::type&& move(T&& t) {
|
||||
return std::move(t);
|
||||
}
|
||||
|
||||
} // namespace polyfill
|
||||
"""
|
||||
cdef T move[T](T)
|
||||
|
||||
|
||||
cdef extern from "ray/common/status.h" namespace "ray" nogil:
|
||||
cdef cppclass StatusCode:
|
||||
pass
|
||||
|
||||
@@ -25,6 +25,10 @@ from ray.includes.common cimport (
|
||||
from ray.includes.libraylet cimport CRayletClient
|
||||
|
||||
|
||||
cdef extern from "ray/core_worker/profiling.h" nogil:
|
||||
cdef cppclass CProfileEvent "ray::worker::ProfileEvent":
|
||||
void SetExtraData(const c_string &extra_data)
|
||||
|
||||
cdef extern from "ray/core_worker/task_interface.h" namespace "ray" nogil:
|
||||
cdef cppclass CTaskSubmissionInterface "CoreWorkerTaskInterface":
|
||||
CRayStatus SubmitTask(
|
||||
@@ -63,7 +67,8 @@ cdef extern from "ray/core_worker/core_worker.h" nogil:
|
||||
const c_string &store_socket,
|
||||
const c_string &raylet_socket, const CJobID &job_id,
|
||||
const CGcsClientOptions &gcs_options,
|
||||
const c_string log_dir, void* execution_callback,
|
||||
const c_string &log_dir, const c_string &node_ip_address,
|
||||
void* execution_callback,
|
||||
c_bool use_memory_store_)
|
||||
void Disconnect()
|
||||
CWorkerType &GetWorkerType()
|
||||
@@ -71,6 +76,8 @@ cdef extern from "ray/core_worker/core_worker.h" nogil:
|
||||
CObjectInterface &Objects()
|
||||
CTaskSubmissionInterface &Tasks()
|
||||
# CTaskExecutionInterface &Execution()
|
||||
unique_ptr[CProfileEvent] CreateProfileEvent(
|
||||
const c_string &event_type)
|
||||
|
||||
# TODO(edoakes): remove this once the raylet client is no longer used
|
||||
# directly.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
from libcpp.string cimport string as c_string
|
||||
|
||||
from ray.includes.libcoreworker cimport CProfileEvent
|
||||
|
||||
import json
|
||||
import traceback
|
||||
|
||||
cdef class ProfileEvent:
|
||||
"""Cython wrapper class of C++ `ray::worker::ProfileEvent`."""
|
||||
cdef:
|
||||
unique_ptr[CProfileEvent] inner
|
||||
dict extra_data
|
||||
|
||||
@staticmethod
|
||||
cdef make(unique_ptr[CProfileEvent] event, dict extra_data):
|
||||
cdef ProfileEvent self = ProfileEvent.__new__(ProfileEvent)
|
||||
self.inner = move(event)
|
||||
self.extra_data = extra_data
|
||||
return self
|
||||
|
||||
def set_extra_data(self, c_string extra_data):
|
||||
self.inner.get().SetExtraData(extra_data)
|
||||
|
||||
def __enter__(self):
|
||||
pass
|
||||
|
||||
def __exit__(self, type, value, tb):
|
||||
extra_data = {}
|
||||
if type is not None:
|
||||
extra_data = {
|
||||
"type": str(type),
|
||||
"value": str(value),
|
||||
"traceback": str(traceback.format_exc()),
|
||||
}
|
||||
elif self.extra_data is not None:
|
||||
extra_data = self.extra_data
|
||||
|
||||
self.inner.get().SetExtraData(json.dumps(extra_data).encode("ascii"))
|
||||
|
||||
# Deleting the CProfileEvent will add it to a queue to be pushed to
|
||||
# the driver.
|
||||
self.inner.reset()
|
||||
Reference in New Issue
Block a user