mirror of
https://github.com/vale981/ray
synced 2025-03-09 12:56:46 -04:00

* Remove all __future__ imports from RLlib. * Remove (object) again from tf_run_builder.py::TFRunBuilder. * Fix 2xLINT warnings. * Fix broken appo_policy import (must be appo_tf_policy) * Remove future imports from all other ray files (not just RLlib). * Remove future imports from all other ray files (not just RLlib). * Remove future import blocks that contain `unicode_literals` as well. Revert appo_tf_policy.py to appo_policy.py (belongs to another PR). * Add two empty lines before Schedule class. * Put back __future__ imports into determine_tests_to_run.py. Fails otherwise on a py2/print related error.
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
import ray
|
|
|
|
|
|
class _NullLogSpan:
|
|
"""A log span context manager that does nothing"""
|
|
|
|
def __enter__(self):
|
|
pass
|
|
|
|
def __exit__(self, type, value, tb):
|
|
pass
|
|
|
|
|
|
NULL_LOG_SPAN = _NullLogSpan()
|
|
|
|
|
|
def profile(event_type, extra_data=None):
|
|
"""Profile a span of time so that it appears in the timeline visualization.
|
|
|
|
Note that this only works in the raylet code path.
|
|
|
|
This function can be used as follows (both on the driver or within a task).
|
|
|
|
.. code-block:: python
|
|
|
|
with ray.profile("custom event", extra_data={'key': 'value'}):
|
|
# Do some computation here.
|
|
|
|
Optionally, a dictionary can be passed as the "extra_data" argument, and
|
|
it can have keys "name" and "cname" if you want to override the default
|
|
timeline display text and box color. Other values will appear at the bottom
|
|
of the chrome tracing GUI when you click on the box corresponding to this
|
|
profile span.
|
|
|
|
Args:
|
|
event_type: A string describing the type of the event.
|
|
extra_data: This must be a dictionary mapping strings to strings. This
|
|
data will be added to the json objects that are used to populate
|
|
the timeline, so if you want to set a particular color, you can
|
|
simply set the "cname" attribute to an appropriate color.
|
|
Similarly, if you set the "name" attribute, then that will set the
|
|
text displayed on the box in the timeline.
|
|
|
|
Returns:
|
|
An object that can profile a span of time via a "with" statement.
|
|
"""
|
|
worker = ray.worker.global_worker
|
|
if worker.mode == ray.worker.LOCAL_MODE:
|
|
return NULL_LOG_SPAN
|
|
return worker.core_worker.profile_event(
|
|
event_type.encode("ascii"), extra_data)
|