Skip to content

Commit

Permalink
[xray] Add flag to start raylet in valgrind (ray-project#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmoritz authored and robertnishihara committed Aug 7, 2018
1 parent 25f0094 commit a3202f5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion python/ray/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@ def start_raylet(redis_address,
worker_path,
resources=None,
num_workers=0,
use_valgrind=False,
use_profiler=False,
stdout_file=None,
stderr_file=None,
cleanup=True):
Expand All @@ -941,6 +943,10 @@ def start_raylet(redis_address,
to.
worker_path (str): The path of the script to use when the local
scheduler starts up new workers.
use_valgrind (bool): True if the raylet should be started inside
of valgrind. If this is True, use_profiler must be False.
use_profiler (bool): True if the raylet should be started inside
a profiler. If this is True, use_valgrind must be False.
stdout_file: A file handle opened for writing to redirect stdout to. If
no redirection should happen, then this should be None.
stderr_file: A file handle opened for writing to redirect stderr to. If
Expand All @@ -952,6 +958,9 @@ def start_raylet(redis_address,
Returns:
The raylet socket name.
"""
if use_valgrind and use_profiler:
raise Exception("Cannot use valgrind and profiler at the same time.")

static_resources = check_and_update_resources(resources, True)

# Format the resource argument in a form like 'CPU,1.0,GPU,0,Custom,3'.
Expand Down Expand Up @@ -984,7 +993,23 @@ def start_raylet(redis_address,
start_worker_command,
resource_argument,
]
pid = subprocess.Popen(command, stdout=stdout_file, stderr=stderr_file)

if use_valgrind:
pid = subprocess.Popen(
[
"valgrind", "--track-origins=yes", "--leak-check=full",
"--show-leak-kinds=all", "--leak-check-heuristics=stdstring",
"--error-exitcode=1"
] + command,
stdout=stdout_file,
stderr=stderr_file)
elif use_profiler:
pid = subprocess.Popen(
["valgrind", "--tool=callgrind"] + command,
stdout=stdout_file,
stderr=stderr_file)
else:
pid = subprocess.Popen(command, stdout=stdout_file, stderr=stderr_file)

if cleanup:
all_processes[PROCESS_TYPE_RAYLET].append(pid)
Expand Down

0 comments on commit a3202f5

Please sign in to comment.