Skip to content

Commit

Permalink
[core] Add more infos to each breakpoint (ray-project#48202)
Browse files Browse the repository at this point in the history
Ray debugger CLI (`ray debug`) is useful but when you have multiple
tasks in the breakpoint, and they are of the same task function, one can
have difficulties understanding which is which.

Add "Node ID", "Worker ID", "Actor ID", "Task ID" to the breakpoint info
so in `ray debug` these IDs show up in the breakpoint selection menu.
This helps users disambiguate between active breakpoints.

The new fields are gated by `-v` or `--verbose`.

Signed-off-by: Ruiyang Wang <[email protected]>
  • Loading branch information
rynewang authored and JP-sDEV committed Nov 14, 2024
1 parent 0b7f61b commit bc61fa9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
68 changes: 56 additions & 12 deletions python/ray/scripts/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ def continue_debug_session(live_jobs: Set[str]):
time.sleep(1.0)


def none_to_empty(s):
if s is None:
return ""
return s


def format_table(table):
"""Format a table as a list of lines with aligned columns."""
result = []
Expand All @@ -213,7 +219,14 @@ def format_table(table):
@click.option(
"--address", required=False, type=str, help="Override the address to connect to."
)
def debug(address):
@click.option(
"-v",
"--verbose",
required=False,
is_flag=True,
help="Shows additional fields in breakpoint selection page.",
)
def debug(address: str, verbose: bool):
"""Show all active breakpoints and exceptions in the Ray debugger."""
address = services.canonicalize_bootstrap_address_or_die(address)
logger.info(f"Connecting to Ray instance at {address}.")
Expand Down Expand Up @@ -246,19 +259,50 @@ def debug(address):
sessions_data = sorted(
sessions_data, key=lambda data: data["timestamp"], reverse=True
)
table = [["index", "timestamp", "Ray task", "filename:lineno"]]
for i, data in enumerate(sessions_data):
date = datetime.utcfromtimestamp(data["timestamp"]).strftime(
"%Y-%m-%d %H:%M:%S"
)
table.append(
if verbose:
table = [
[
str(i),
date,
data["proctitle"],
data["filename"] + ":" + str(data["lineno"]),
"index",
"timestamp",
"Ray task",
"filename:lineno",
"Task ID",
"Worker ID",
"Actor ID",
"Node ID",
]
)
]
for i, data in enumerate(sessions_data):
date = datetime.utcfromtimestamp(data["timestamp"]).strftime(
"%Y-%m-%d %H:%M:%S"
)
table.append(
[
str(i),
date,
data["proctitle"],
data["filename"] + ":" + str(data["lineno"]),
data["task_id"],
data["worker_id"],
none_to_empty(data["actor_id"]),
data["node_id"],
]
)
else:
# Non verbose mode: no IDs.
table = [["index", "timestamp", "Ray task", "filename:lineno"]]
for i, data in enumerate(sessions_data):
date = datetime.utcfromtimestamp(data["timestamp"]).strftime(
"%Y-%m-%d %H:%M:%S"
)
table.append(
[
str(i),
date,
data["proctitle"],
data["filename"] + ":" + str(data["lineno"]),
]
)
for i, line in enumerate(format_table(table)):
print(line)
if i >= 1 and not sessions_data[i - 1]["traceback"].startswith(
Expand Down
4 changes: 4 additions & 0 deletions python/ray/util/rpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ def _connect_ray_pdb(
"traceback": "\n".join(traceback.format_exception(*sys.exc_info())),
"timestamp": time.time(),
"job_id": ray.get_runtime_context().get_job_id(),
"node_id": ray.get_runtime_context().get_node_id(),
"worker_id": ray.get_runtime_context().get_worker_id(),
"actor_id": ray.get_runtime_context().get_actor_id(),
"task_id": ray.get_runtime_context().get_task_id(),
}
_internal_kv_put(
"RAY_PDB_{}".format(breakpoint_uuid),
Expand Down

0 comments on commit bc61fa9

Please sign in to comment.